packages feed

moe (empty) → 2009.8.23

raw patch · 12 files changed

+488/−0 lines, 12 filesdep +basedep +data-defaultdep +mpssetup-changed

Dependencies added: base, data-default, mps, mtl

Files

+ LICENSE view
@@ -0,0 +1,9 @@+Copyright (c) 2009, Jinjing Wang+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 the <ORGANIZATION> nor the names of its 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 HOLDER 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.
+ Nemesis view
@@ -0,0 +1,32 @@+nemesis = do+  +  clean+    [ "**/*.hi"+    , "**/*.o"+    , "manifest"+    ]+    +  desc "prepare cabal dist"+  task "dist" - do+    sh "cabal clean"+    sh "cabal configure"+    sh "cabal sdist"++  desc "start console"+  task "i" (sh "ghci -Wall -isrc src/Text/HTML/Moe.hs")++  desc "put all .hs files in manifest"+  task "manifest" - do+    sh "find . | grep 'hs$' > manifest"++  desc "show sloc"+  task "stat" - do+    sh "cloc -match-f=hs$ --quiet src --no3"+  +  desc "test"+  task "test" - do +    sh "ghci -Wall -isrc src/test.hs"+  +  desc "run-test"+  task "run-test" - do+    sh "runghc -isrc src/test.hs"
+ Setup.lhs view
@@ -0,0 +1,4 @@+#! /usr/bin/env runhaskell++> import Distribution.Simple+> main = defaultMain
+ changelog.md view
@@ -0,0 +1,4 @@+2009.8.24+---------++Init
+ known-issues.md view
+ moe.cabal view
@@ -0,0 +1,27 @@+Name:                 moe+Version:              2009.8.23+Build-type:           Simple+Synopsis:             html combinator with style+Description:++    a purely functional html combinator with a clean syntax++License:              BSD3+License-file:         LICENSE+Author:               Wang, Jinjing+Maintainer:           Wang, Jinjing <nfjinjing@gmail.com>+Build-Depends:        base+Cabal-version:        >= 1.2+category:             Web+homepage:             http://github.com/nfjinjing/moe+data-files:           readme.md, changelog.md, known-issues.md, Nemesis, src/test.hs++library+  ghc-options: -Wall+  build-depends: base >= 4 && < 5, mtl, mps >= 2009.8.18.1, data-default+  hs-source-dirs: src/+  exposed-modules:  +                      Text.HTML.Moe   +                      Text.HTML.Moe.Attribute+                      Text.HTML.Moe.Element+                      Text.HTML.Moe.Type
+ readme.md view
@@ -0,0 +1,58 @@+# Moe++html combinator with style++# Example++first page++    -- test.hs++    import Prelude hiding ((/), (-), head, (>), (.))+    import MPS.Light ((-))+    import Text.HTML.Moe++    test_page :: String+    test_page = render -+      html - do+        head - do+          meta'+            [http_equiv "Content-Type", content "text/html; charset-utf-8"] (/)+          title - str "my title"+          link' [rel "icon", _type "image/png", href "panda_icon.png"] (/)++        body - do+          div' [_class "container"] - do+            str "hello world"+    +    main :: IO ()+    main = putStrLn test_page++install and run++    cabal update+    cabal install moe+    +    runghc test.hs++    output:++    <html>+      <head>+        <meta http-equiv="Content-Type" content="text/html; charset-utf-8">+        </meta>+        <title>+          my title+        </title>+        <link rel="icon" type="image/png" href="panda_icon.png">+        </link>+      </head>+      <body>+        <div class="container">+          hello world+        </div>+      </body>+    </html>+++
+ src/Text/HTML/Moe.hs view
@@ -0,0 +1,60 @@+{-# LANGUAGE NoMonomorphismRestriction #-}++module Text.HTML.Moe+(+    module Text.HTML.Moe.Element+  , module Text.HTML.Moe.Attribute+  , (/)+  , render+)+where++import Control.Monad.Writer (tell, execWriter)+import Prelude hiding ((/), (-), head, (>), (.))+import MPS.Light ((-), (>), (.), join, times)+import MPS.Heavy+import Text.HTML.Moe.Type hiding (name, value)+import qualified Text.HTML.Moe.Type as T+import Text.HTML.Moe.Element+import Text.HTML.Moe.Attribute++(/) :: MoeUnit+(/) = return ()++render :: MoeUnit -> String+render = execWriter > map render_element > join "\n"++indent_space :: Int+indent_space = 2++render_element' :: Int -> Element -> String+render_element' _ (Raw x)   = x++render_element' n (Data x)  = execWriter - do+  tell - (n * indent_space).times ' '+  tell - escape_xml x+  tell - "\n"+  +render_element' n x = execWriter - do+  tell - indent+  tell - "<" ++ x.T.name ++ ""+  tell - x.attributes.map render_attribute. join_attribute+  tell - ">"+  tell - "\n"+  +  tell - x.elements.map (render_element' (n+1)) .concat+  +  tell - indent+  tell - "</" ++ x.T.name ++ ">"+  tell - "\n"+  +  where+    join_attribute xs = xs.map (" " ++) .concat+    indent = (n * indent_space).times ' '+++render_element :: Element -> String+render_element = render_element' 0++render_attribute :: Attribute -> String+render_attribute x = x.key ++ "=" ++ "\"" ++ x.T.value ++ "\""
+ src/Text/HTML/Moe/Attribute.hs view
@@ -0,0 +1,73 @@+module Text.HTML.Moe.Attribute where++import Text.HTML.Moe.Type+import Prelude hiding (id)++attr        :: String -> String -> Attribute+attr        = Attribute++_class      :: String -> Attribute+_data       :: String -> Attribute+_span       :: String -> Attribute+_style      :: String -> Attribute+_title      :: String -> Attribute+_type       :: String -> Attribute+align       :: String -> Attribute+alt         :: String -> Attribute+bgcolor     :: String -> Attribute+border      :: String -> Attribute+classid     :: String -> Attribute+colspan     :: String -> Attribute+content     :: String -> Attribute+height      :: String -> Attribute      +href        :: String -> Attribute+http_equiv  :: String -> Attribute+id          :: String -> Attribute+lang        :: String -> Attribute+language    :: String -> Attribute+media       :: String -> Attribute+name        :: String -> Attribute+quality     :: String -> Attribute+rel         :: String -> Attribute+rowspan     :: String -> Attribute+src         :: String -> Attribute+target      :: String -> Attribute+valign      :: String -> Attribute+value       :: String -> Attribute+width       :: String -> Attribute+xml_lang    :: String -> Attribute+xmlns       :: String -> Attribute++_class      = attr "class"+_data       = attr "data"+_span       = attr "span"+_style      = attr "style"+_title      = attr "title"+_type       = attr "type"+align       = attr "align"+alt         = attr "alt"+bgcolor     = attr "bgcolor"+border      = attr "border"+classid     = attr "classid"+colspan     = attr "colspan"+content     = attr "content"+height      = attr "height"+href        = attr "href"+http_equiv  = attr "http-equiv"+id          = attr "id"+lang        = attr "lang"+language    = attr "language"+media       = attr "media"+name        = attr "name"+quality     = attr "quality"+rel         = attr "rel"    +rowspan     = attr "rowspan"+src         = attr "src"+target      = attr "target"+valign      = attr "valign"+value       = attr "value"+width       = attr "width"+xml_lang    = attr "xml_lang"+xmlns       = attr "xmlns"++
+ src/Text/HTML/Moe/Element.hs view
@@ -0,0 +1,168 @@+module Text.HTML.Moe.Element where++import Text.HTML.Moe.Type+import Data.Default+import Control.Monad.Writer+import Prelude hiding (id, span, div)++element' :: String -> MoeCombinator'+element' x xs u = tell [+  def+    {+      name = x+    , attributes = xs+    , elements =  execWriter u+    }+  ]++element :: (String -> MoeCombinator') -> (String -> MoeCombinator)+element x = flip x []++e :: String -> MoeCombinator'+e = element'++a'          ::  MoeCombinator'+body'       ::  MoeCombinator'+br'         ::  MoeCombinator'+colgroup'   ::  MoeCombinator'+col'        ::  MoeCombinator'+div'        ::  MoeCombinator'+embed'      ::  MoeCombinator'+h1'         ::  MoeCombinator'+h2'         ::  MoeCombinator'+h3'         ::  MoeCombinator'+head'       ::  MoeCombinator'+html'       ::  MoeCombinator'+img'        ::  MoeCombinator'+li'         ::  MoeCombinator'+link'       ::  MoeCombinator'+meta'       ::  MoeCombinator'+object'     ::  MoeCombinator'+ol'         ::  MoeCombinator'+param'      ::  MoeCombinator'+ul'         ::  MoeCombinator'+dl'         ::  MoeCombinator'+dt'         ::  MoeCombinator'+dd'         ::  MoeCombinator'+p'          ::  MoeCombinator'+pre'        ::  MoeCombinator'+script'     ::  MoeCombinator'+span'       ::  MoeCombinator'+style'      ::  MoeCombinator'+table'      ::  MoeCombinator'+td'         ::  MoeCombinator'+th'         ::  MoeCombinator'+title'      ::  MoeCombinator'+tr'         ::  MoeCombinator'+++a'          = e "a"+body'       = e "body"+br'         = e "br"+colgroup'   = e "colgroup"+col'        = e "col"+div'        = e "div"+embed'      = e "embed"+h1'         = e "h1"+h2'         = e "h2"+h3'         = e "h3"+head'       = e "head"+html'       = e "html"+img'        = e "img"+li'         = e "li"+link'       = e "link"+meta'       = e "meta"+object'     = e "object"+ol'         = e "ol"+param'      = e "param"+ul'         = e "ul"+dl'         = e "dl"+dt'         = e "dt"+dd'         = e "dd"+p'          = e "p"+pre'        = e "pre"+script'     = e "script"+span'       = e "span"+style'      = e "style"+table'      = e "table"+td'         = e "td"+th'         = e "th"+title'      = e "title"+tr'         = e "tr"+++++a         :: MoeCombinator+body      :: MoeCombinator+br        :: MoeCombinator+colgroup  :: MoeCombinator+col       :: MoeCombinator+div       :: MoeCombinator+embed     :: MoeCombinator+h1        :: MoeCombinator+h2        :: MoeCombinator+h3        :: MoeCombinator+head      :: MoeCombinator+html      :: MoeCombinator+img       :: MoeCombinator+li        :: MoeCombinator+link      :: MoeCombinator+meta      :: MoeCombinator+object    :: MoeCombinator+ol        :: MoeCombinator+param     :: MoeCombinator+ul        :: MoeCombinator+dl        :: MoeCombinator+dt        :: MoeCombinator+dd        :: MoeCombinator+p         :: MoeCombinator+pre       :: MoeCombinator+script    :: MoeCombinator+span      :: MoeCombinator+style     :: MoeCombinator+table     :: MoeCombinator+td        :: MoeCombinator+th        :: MoeCombinator+title     :: MoeCombinator+tr        :: MoeCombinator++a         = a'          []+body      = body'       []+br        = br'         []+colgroup  = colgroup'   []+col       = col'        []+div       = div'        []+embed     = embed'      []+h1        = h1'         []+h2        = h2'         []+h3        = h3'         []+head      = head'       []+html      = html'       []+img       = img'        []+li        = li'         []+link      = link'       []+meta      = meta'       []+object    = object'     []+ol        = ol'         []+param     = param'      []+ul        = ul'         []+dl        = dl'         []+dt        = dt'         []+dd        = dd'         []+p         = p'          []+pre       = pre'        []+script    = script'     []+span      = span'       []+style     = style'      []+table     = table'      []+td        = td'         []+th        = th'         []+title     = title'      []+tr        = tr'         []++str :: String -> MoeUnit+raw :: String -> MoeUnit++str x   = tell [Data x]+raw x   = tell [Raw  x]
+ src/Text/HTML/Moe/Type.hs view
@@ -0,0 +1,34 @@+module Text.HTML.Moe.Type where++import Data.Default+import Control.Monad.Writer++data Element = +    Element+      {+        name :: String+      , attributes :: [Attribute]+      , elements :: [Element]+      }+  | Raw String+  | Data String+  deriving (Show)++instance Default Element where+  def = Element def def def++data Attribute = Attribute+  {+    key :: String+  , value :: String+  }+  deriving (Show)++instance Default Attribute where+  def = Attribute def def++type MoeUnitT a = Writer [Element] a+type MoeUnit = MoeUnitT ()++type MoeCombinator' = [Attribute] -> MoeUnit -> MoeUnit+type MoeCombinator = MoeUnit -> MoeUnit
+ src/test.hs view
@@ -0,0 +1,19 @@+import Prelude hiding ((/), (-), head, (>), (.))+import MPS.Light ((-))+import Text.HTML.Moe++test_page :: String+test_page = render -+  html - do+    head - do+      meta'+        [http_equiv "Content-Type", content "text/html; charset-utf-8"] (/)+      title - str "my title"+      link' [rel "icon", _type "image/png", href "panda_icon.png"] (/)+  +    body - do+      div' [_class "container"] - do+        str "hello world"++main :: IO ()+main = putStrLn test_page