packages feed

snm 0.0.3 → 0.0.4

raw patch · 9 files changed

+158/−194 lines, 9 files

Files

− Manual.hs
@@ -1,60 +0,0 @@-{---This file is part of The Simple Nice Manual Generator.--    The Simple Nice Manual Generator is free software: you can -    redistribute it and/or modify it under the terms of the GNU -    General Public License as published by the Free Software Foundation, -    either version 3 of the License, or any later version.--    The Simple Nice Manual Generator is distributed in the hope that it -    will be useful, but WITHOUT ANY WARRANTY; without even the implied -    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  -    See the GNU General Public License for more details.--    You should have received a copy of the GNU General Public License-    along with The Simple Nice Manual Generator.  -    If not, see <http://www.gnu.org/licenses/>---}---- | Read and output manuals-module Manual-   (OutputType (..)-   ,load_manual-   ,write_manual-   ,formats-   ,text_format-   ,xhtml_format) where--import Manual.Reader-import Manual.Emit-import Manual.Structure--import System.FilePath--import Data.Map (Map)-import qualified Data.Map as M---- | The output types-data OutputType =-     XHtml-   | Text-   deriving (Eq, Ord)----- | Write in a number of formats-formats :: Map OutputType (Manual -> String, String)-formats = M.fromList [(XHtml, xhtml_format)-                     ,(Text, text_format)]--xhtml_format :: (Manual -> String, String)-xhtml_format = (emit_xhtml, "html")--text_format :: (Manual -> String, String)-text_format = (emit_text, "txt")---- | Write out a manual-write_manual :: (Manual -> String) -> String -> Manual -> FilePath -> IO ()-write_manual format ext man fil =-   writeFile (fil `addExtension` ext) $ format man
+ Manual/Easy.hs view
@@ -0,0 +1,60 @@+{-++This file is part of The Simple Nice Manual Generator.++    The Simple Nice Manual Generator is free software: you can +    redistribute it and/or modify it under the terms of the GNU +    General Public License as published by the Free Software Foundation, +    either version 3 of the License, or any later version.++    The Simple Nice Manual Generator is distributed in the hope that it +    will be useful, but WITHOUT ANY WARRANTY; without even the implied +    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  +    See the GNU General Public License for more details.++    You should have received a copy of the GNU General Public License+    along with The Simple Nice Manual Generator.  +    If not, see <http://www.gnu.org/licenses/>++-}++-- | Read and output manuals+module Manual.Easy+   (OutputType (..)+   ,load_manual+   ,write_manual+   ,formats+   ,text_format+   ,xhtml_format) where++import Manual.Reader+import Manual.Emit+import Manual.Structure++import System.FilePath++import Data.Map (Map)+import qualified Data.Map as M++-- | The output types+data OutputType =+     XHtml+   | Text+   deriving (Eq, Ord)+++-- | Write in a number of formats+formats :: Map OutputType (Manual -> String, String)+formats = M.fromList [(XHtml, xhtml_format)+                     ,(Text, text_format)]++xhtml_format :: (Manual -> String, String)+xhtml_format = (emit_xhtml, "html")++text_format :: (Manual -> String, String)+text_format = (emit_text, "txt")++-- | Write out a manual+write_manual :: (Manual -> String) -> String -> Manual -> FilePath -> IO ()+write_manual format ext man fil =+   writeFile (fil `addExtension` ext) $ format man
Manual/Emit.hs view
@@ -26,7 +26,6 @@ module Manual.Emit where  import Manual.Emit.XHTML-import Manual.Emit.Text import Manual.Structure  import Text.Pretty
− Manual/Emit/Text.hs
@@ -1,114 +0,0 @@-{---Copyright 2010 John Morrice--This source file is part of The Simple Nice Manual Generator and is distributed under the terms of the GNU General Public License--This file is part of The Simple Nice Manual Generator.--    The Simple Nice Manual Generator is free software: you can -    redistribute it and/or modify it under the terms of the GNU -    General Public License as published by the Free Software Foundation, -    either version 3 of the License, or any later version.--    The Simple Nice Manual Generator is distributed in the hope that it -    will be useful, but WITHOUT ANY WARRANTY; without even the implied -    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  -    See the GNU General Public License for more details.--    You should have received a copy of the GNU General Public License-    along with The Simple Nice Manual enerator.  -    If not, see <http://www.gnu.org/licenses/>---}---- | Pretty print manuals as text-module Manual.Emit.Text where--import Manual.Structure--import Text.Pretty--import Data.List--contents :: [Section] -> Contents-contents =-   Contents . gather_sections--gather_sections :: [Section] -> [Contents]-gather_sections ss = -   concatMap subsection_contents $ -      sortBy (\s1 s2 -> number s1 `compare` number s2) ss--subsection_contents :: Section -> [Contents]-subsection_contents s =-   if null $ subsections s-      then [me]-      else [me , Contents $ gather_sections (subsections s)]-   where-   me = Entry (number s) (pretty $ title s) (unique s)---instance Pretty Contents where-   pretty' c sp =-      case c of-         Entry nums name _ -> pspace sp . pretty_nums nums . ((' ' : name) ++)-         Contents cs -> pretty_list' cs $ sp + 1---- Pretty print manuals-instance Pretty Manual where-   pretty' man _ =-      pretty' (header man) 0 . nl . nl . -         pretty' (mcontents man) (-1) . nl . nl . nl .-            pretty_list' (sections man) 0--instance Pretty Section where-   pretty' sec _ =-      pretty_nums (number sec) . (' ' :) . pretty' (title sec) 0 . nl . nl . -         pretty_list_nl' (stext sec) 0 . nl . nl . nl .-            (if null $ subsections sec-               then id-               else pretty_list' (subsections sec) 0)--mock_shows :: String -> ShowS-mock_shows s = (s ++) ---- Prettify the section's number.-pretty_nums :: [Int] -> ShowS-pretty_nums nums = (intercalate "." (map show nums) ++) . ('.' :)--instance Pretty Paragraph where-   pretty' par _ =-      pretty_list' (ptext par) 0---- | Copyright notice-copy_notice :: String -> String-copy_notice cp = "Copyright " ++ cp---- | License notice-license_notice :: String -> String-license_notice lic = "Distributed under terms of the " ++ lic ++ "."---- | License file notice-license_file_notice :: String -> String-license_file_notice fi = "See the file " ++ fi ++  " for details."--instance Pretty Header where-   pretty' head _ =-      pretty' (mtitle head) 0 . nl . nl . nl .-           pretty_list_nl' (banners head) 0 . nl . nl . nl .-           pretty_list_nl' (preamble head) 0--instance Pretty Banner where-   pretty' ban _ =-      pretty_list' (btext ban) 0--instance Pretty Inline where-   pretty' inline _ =-      case inline of-         IText str -> mock_shows str-         ISectionLink text dest -> mock_shows text-         IExternLink text dest -> mock_shows text . mock_shows " (see " . mock_shows dest . mock_shows ")"-         -- IIndent -> mock_shows "   "-         -- ILine -> nl-         ILiteral t -> mock_shows t
Manual/Emit/XHTML.hs view
@@ -22,11 +22,11 @@  -} -module Manual.Emit.XHTML where+module Manual.Emit.XHTML+   (render_manual_xhtml)+   where  import Manual.Structure-import Manual.Emit.Text- import Text.Pretty  import Text.XHtml.Strict hiding (header,title,style)
Manual/Reader.hs view
@@ -23,11 +23,11 @@ -}  -- | Read a manual from its source files-module Manual.Reader where+module Manual.Reader+   (load_manual+   ,load_section) where  import Manual.Structure--- You'd think it's pretty weird that the Reader would import the Emitter, but it's to manufacture the contents-import Manual.Emit.Text  import Data.Yaml.Simple 
Manual/Structure.hs view
@@ -23,13 +23,25 @@ -}  -- | The structure of a manual-module Manual.Structure where+module Manual.Structure+   (Manual (..)+   ,Header (..)+   ,Contents (..)+   ,Section (..)+   ,Banner (..)+   ,Paragraph (..)+   ,Inline (..)+   ,pretty_nums+   ,contents)+   where  import System.FilePath import System.Directory  import Data.List +import Text.Pretty+ -- | We just see a CSS file as a string type CSS = String @@ -116,3 +128,73 @@    Contents [Contents]    | Entry [Int] String String    deriving Show++-- | Create the manual's contents+contents :: [Section] -> Contents+contents =+   Contents . gather_sections++gather_sections :: [Section] -> [Contents]+gather_sections ss = +   concatMap subsection_contents $ +      sortBy (\s1 s2 -> number s1 `compare` number s2) ss++subsection_contents :: Section -> [Contents]+subsection_contents s =+   if null $ subsections s+      then [me]+      else [me , Contents $ gather_sections (subsections s)]+   where+   me = Entry (number s) (pretty $ title s) (unique s)++instance Pretty Banner where+   pretty' ban _ =+      pretty_list' (btext ban) 0++instance Pretty Inline where+   pretty' inline _ =+      case inline of+         IText str -> mock_shows str+         ISectionLink text dest -> mock_shows text+         IExternLink text dest -> mock_shows text . mock_shows " (see " . mock_shows dest . mock_shows ")"+         -- IIndent -> mock_shows "   "+         -- ILine -> nl+         ILiteral t -> mock_shows t++mock_shows :: String -> ShowS+mock_shows s = (s ++) ++instance Pretty Contents where+   pretty' c sp =+      case c of+         Entry nums name _ -> pspace sp . pretty_nums nums . ((' ' : name) ++)+         Contents cs -> pretty_list' cs $ sp + 1++-- Pretty print manuals+instance Pretty Manual where+   pretty' man _ =+      pretty' (header man) 0 . nl . nl . +         pretty' (mcontents man) (-1) . nl . nl . nl .+            pretty_list' (sections man) 0++instance Pretty Section where+   pretty' sec _ =+      pretty_nums (number sec) . (' ' :) . pretty' (title sec) 0 . nl . nl . +         pretty_list_nl' (stext sec) 0 . nl . nl . nl .+            (if null $ subsections sec+               then id+               else pretty_list' (subsections sec) 0)++-- Prettify the section's number.+pretty_nums :: [Int] -> ShowS+pretty_nums nums = (intercalate "." (map show nums) ++) . ('.' :)++instance Pretty Paragraph where+   pretty' par _ =+      pretty_list' (ptext par) 0++instance Pretty Header where+   pretty' head _ =+      pretty' (mtitle head) 0 . nl . nl . nl .+           pretty_list_nl' (banners head) 0 . nl . nl . nl .+           pretty_list_nl' (preamble head) 0
bin/snm.hs view
@@ -1,24 +1,22 @@ -- Generate simple and nice looking manuals -import Manual+import Manual.Easy  import System.Environment import System.Console.GetOpt--import Data.Maybe--import Data.List+import System.IO  import System.FilePath  import Control.Monad +import Data.Maybe import Data.Map (Map) import qualified Data.Map as M+import Data.List -import Data.Maybe -import System.IO+  -- Flags determine how we should behave data ManFlag =
snm.cabal view
@@ -1,5 +1,5 @@ Name:           snm -Version:	0.0.3+Version:	0.0.4 License:	GPL-3 License-File:   COPYING	 Author:		John Morrice <spoon@killersmurf.com>@@ -31,9 +31,8 @@       Manual.Structure       Manual.Reader       Manual.Emit-      Manual.Emit.Text       Manual.Emit.XHTML-      Manual+      Manual.Easy  Executable snm    Main-is: bin/snm.hs@@ -42,5 +41,5 @@       Data.Yaml.Simple       Manual.Structure       Manual.Reader-      Manual.Emit-      Manual+      Manual.Emit.XHTML+      Manual.Easy