packages feed

Docs (empty) → 1.0.0

raw patch · 4 files changed

+150/−0 lines, 4 filesdep +basedep +htmlsetup-changed

Dependencies added: base, html

Files

+ Docs.cabal view
@@ -0,0 +1,19 @@+Name:           Docs
+Version:        1.0.0
+Author:         Daniel Diaz
+Homepage:       http://ddiaz.asofilak.es/packages/Docs.html
+License:        BSD3
+License-file:   license
+Maintainer:     lazy.ddiaz@gmail.com
+Category:       Documentation
+Synopsis:       Documentation types library.
+Description:    Currently, this package defines classes for types that represents documentation.
+                .
+                The point of this library is to make possible write documentation in a general format,
+                and later, render it in a desired concrete format.
+                .
+                At the moment, only Html format are supported by default, but you can add new instances.
+Build-type:     Simple
+Build-depends:  base == 4.* , html
+Cabal-version:  >= 1.6
+Exposed-modules: Text.Docs.Class
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple
+main = defaultMain
+ Text/Docs/Class.hs view
@@ -0,0 +1,99 @@+
+-- | Classes for 'Documentable' types.
+module Text.Docs.Class (
+    -- * @Documentable@ class
+    Documentable (..)
+  , emptydoc
+  , dunlines
+    -- * Specific @Documentable@ class.
+  , DocTitled (..)
+  , DocLinked (..)
+  , DocList (..)
+  ) where
+
+import Data.Monoid
+--
+import qualified Text.Html as H
+
+-- | Class for types that represents a documentation text. Minimal complete definition: All except 'lnappend'.
+--
+-- Every instance of 'Documentable' class can be an instance of 'Monoid' class.
+class Documentable a where
+ -- | 'String' to a documentation text.
+ text :: String -> a
+ -- | 'String' to a code format text.
+ code :: String -> a
+ -- | 'String' to a code block.
+ codeblock :: String -> a
+ -- | Emphasizing documentation.
+ emphasize :: a -> a
+ -- | Appending documentation.
+ dappend :: a -> a -> a
+ -- | Appending documentation, with line break.
+ lnappend :: a -> a -> a
+ -- | Rendering documentation.
+ renderdoc :: a -> String
+ --
+ lnappend x y = x `dappend` text "\n" `dappend` y
+
+-- | An empty documentation.
+emptydoc :: Documentable a => a
+emptydoc = text []
+
+-- | 'Documentable' version of 'unlines'.
+dunlines :: Documentable a => [a] -> a
+dunlines = foldr lnappend emptydoc
+ 
+-- | 'Documentable' types with titles.
+class Documentable a => DocTitled a where
+ -- | Making a title.
+ title :: a -> a
+ -- | Making a subtitle.
+ subtitle :: a -> a
+ --
+ title = id
+ subtitle = title
+
+-- | 'Documentable' types with links.
+class Documentable a => DocLinked a where
+ -- | An URL to documentation.
+ url :: String -> a
+ -- | A named URL to documentation. First argument is the name of the link, second argument the URL.
+ nameurl :: String -> String -> a
+ -- 
+ url = text
+ nameurl _ y = url y
+
+-- | 'Documentable' types with lists.
+class Documentable a => DocList a where
+ -- | Unordered list.
+ ulist :: [a] -> a
+ -- | Enumerated list.
+ elist :: [a] -> a
+ --
+ ulist = dunlines . map (dappend $ text "* ")
+ elist = dunlines . zipWith (\n x -> (text $ show n) `dappend` text ". " `dappend` x ) [1..]
+
+-- Html instance
+
+instance Documentable H.Html where
+ text = H.stringToHtml
+ code = H.thecode . text
+ codeblock = H.pre . text
+ emphasize = H.emphasize
+ dappend = (H.+++)
+ renderdoc = H.renderHtml
+ 
+instance DocTitled H.Html where
+ title = H.h1
+ subtitle = H.h2
+
+instance DocLinked H.Html where
+ url x = (H.![H.href x]) . H.anchor . text $ x
+ nameurl x y = (H.![H.href y]) . H.anchor . text $ x
+
+instance DocList H.Html where
+ ulist = H.ulist . H.concatHtml . map H.li
+ elist = H.olist . H.concatHtml . map H.li
+
+
+ license view
@@ -0,0 +1,30 @@+Copyright (c)2010, Daniel Díaz
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+
+    * Neither the name of Daniel Díaz nor the names of other
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.