packages feed

moe 2010.9.29.1 → 2010.9.29.2

raw patch · 3 files changed

+215/−3 lines, 3 files

Files

moe.cabal view
@@ -1,5 +1,5 @@ Name:                 moe-Version:              2010.9.29.1+Version:              2010.9.29.2 Build-type:           Simple Synopsis:             html with style Description:@@ -32,13 +32,18 @@                       Text.HTML.Moe.Backend.ByteString                                              Text.HTML.Moe2   +                      +  other-modules:+                      Text.HTML.Moe.Backend.DList+                                             Text.HTML.Moe2.Attribute                       Text.HTML.Moe2.Element                       Text.HTML.Moe2.DSL.Markdown                       Text.HTML.Moe2.DSL.Kawaii                       Text.HTML.Moe2.DSL.HTML5+                      Text.HTML.Moe2.DSL.HTML+                      Text.HTML.Moe2.Renderer+                       Text.HTML.Moe2.Type                       Text.HTML.Moe2.Utils                       -  other-modules:-                      Text.HTML.Moe.Backend.DList
+ src/Text/HTML/Moe2/DSL/HTML.hs view
@@ -0,0 +1,104 @@+module Text.HTML.Moe2.DSL.HTML where++import Text.HTML.Moe2.Element+import Text.HTML.Moe2.Type+import Prelude hiding (head)+++a         :: MoeCombinator+body      :: MoeCombinator+br        :: LightCombinator+blockquote  :: MoeCombinator+code      :: MoeCombinator+colgroup  :: MoeCombinator+col       :: MoeCombinator+div       :: MoeCombinator+form      :: MoeCombinator+embed     :: MoeCombinator+em        :: MoeCombinator+h1        :: MoeCombinator+h2        :: MoeCombinator+h3        :: MoeCombinator+h4        :: MoeCombinator+h5        :: MoeCombinator+h6        :: MoeCombinator+head      :: MoeCombinator+html      :: MoeCombinator+hr        :: LightCombinator+img       :: LightCombinator+input     :: LightCombinator+label     :: MoeCombinator+li        :: MoeCombinator+link      :: LightCombinator+meta      :: LightCombinator+object    :: MoeCombinator+ol        :: MoeCombinator+param     :: MoeCombinator+ul        :: MoeCombinator+dl        :: MoeCombinator+dt        :: MoeCombinator+dd        :: MoeCombinator+option    :: MoeCombinator+p         :: MoeCombinator+pre       :: MoeCombinator+select    :: MoeCombinator+script    :: MoeCombinator+span      :: MoeCombinator+style     :: MoeCombinator+strong    :: MoeCombinator+table     :: MoeCombinator+textarea  :: MoeCombinator+td        :: MoeCombinator+th        :: MoeCombinator+title     :: MoeCombinator+tr        :: MoeCombinator++++a          = e "a"+body       = e "body"+br         = sc "br"+blockquote  = e "blockquote"+code       = e "code"+colgroup   = e "colgroup"+col        = e "col"+div        = e "div"+embed      = e "embed"+em         = e "em"+form       = e "form"+h1         = e "h1"+h2         = e "h2"+h3         = e "h3"+h4         = e "h4"+h5         = e "h5"+h6         = e "h6"+head       = e "head"+html       = e "html"+hr         = sc "hr"+img        = sc "img"+input      = sc "input"+label      = e "label"+li         = e "li"+link       = sc "link"+meta       = sc "meta"+object     = e "object"+ol         = e "ol"+param      = e "param"+ul         = e "ul"+dl         = e "dl"+dt         = e "dt"+dd         = e "dd"+option     = e "option"+p          = e "p"+pre        = e "pre"+select     = e "select"+script     = e "script"+span       = e "span"+style      = e "style"+strong     = e "strong"+table      = e "table"+textarea   = ne "textarea"+td         = e "td"+th         = e "th"+title      = e "title"+tr         = e "tr"
+ src/Text/HTML/Moe2/Renderer.hs view
@@ -0,0 +1,103 @@+{-# LANGUAGE NoMonomorphismRestriction #-}++module Text.HTML.Moe2.Renderer+(+    render+  , render'+)+where++import Text.HTML.Moe2.Element+import Text.HTML.Moe2.Attribute+import Text.HTML.Moe2.Utils+import Text.HTML.Moe2.Type hiding (name, value)+import qualified Text.HTML.Moe2.Type as T++import Prelude hiding ((/), (-), head, (>), (.), concat, concatMap, (+))+import qualified Prelude as P++import MPS.Env ((>), (.), times, belongs_to, reject)++import Control.Monad.Writer (execWriter)++import qualified Data.ByteString.Char8 as B+import Data.DList (toList)+import Data.List (intersperse)+++render :: MoeUnit -> String+render = render' > B.unpack++render' :: MoeUnit -> B.ByteString+render' = execWriter > toList > map render_element > intercalate new_line > to_bs++_indent_space :: Int+_indent_space = 2++new_line :: Internal+new_line = pack "\n"++space :: Internal+space = pack " "++_indent :: Int -> Internal+_indent n = (n * _indent_space).times space.concat++render_element' :: Int -> Element -> Internal+render_element' _ (Raw x)   = x+render_element' _ (Pre x)   = x+render_element' n (Prim x)  = _indent n + x+render_element' n (Data x)  = _indent n + x+render_element' n (Attributes xs e) = +  let xs' = e.attributes.reject (key > belongs_to (xs.map key)) ++ xs+  in+  render_element' n e {attributes = xs'}+  +render_element' n x +  | x.self_close =+    [ _indent n+    , "<".pack+    , x.T.name+    , x.attributes.map render_attribute. join_attribute+    , " />".pack+    ]+    .concat+    +  | otherwise = +    [ self_indent+    , "<".pack+    , x.T.name+    , x.attributes.map render_attribute. join_attribute+    , ">".pack+    , inner_elements+    , "</".pack+    , x.T.name+    , ">".pack+    ]+    .concat+    +  where+    self_indent = if x.indent then _indent n else "".pack+    join_attribute xs = xs.map (pack " " `append`) .concat+    inner_elements = +      if x.elements.null+        then "".pack+        else +          [ new_line+          , x.elements.map (render_element' (n P.+ 1)) .intersperse new_line .concat+          , new_line+          , self_indent+          ]+          .concat++      ++++render_element :: Element -> Internal+render_element = render_element' 0++render_attribute :: Attribute -> Internal+render_attribute x = +  [x.key, pack "=", pack "\"", x.T.value, pack "\""].concat+