13
13
14
14
module Dhall.Docs.Html
15
15
( dhallFileToHtml
16
+ , markdownFileToHtml
16
17
, textFileToHtml
17
18
, indexToHtml
18
19
, DocParams (.. )
@@ -47,57 +48,75 @@ data DocParams = DocParams
47
48
, baseImportUrl :: Maybe Text -- ^ Base import URL
48
49
}
49
50
50
- -- | Generates an @`Html` ()@ with all the information about a dhall file
51
- dhallFileToHtml
52
- :: Path Rel File -- ^ Source file name, used to extract the title
53
- -> Text -- ^ Contents of the file
54
- -> Expr Src Import -- ^ AST of the file
55
- -> [Expr Void Import ] -- ^ Examples extracted from the assertions of the file
56
- -> Html () -- ^ Header document as HTML
51
+ -- | Generates an @`Html` ()@ containing standard elements like title,
52
+ -- navbar, breadcrumbs, and the provided content.
53
+ htmlTemplate
54
+ :: Path Rel a -- ^ Source file name or index directory, used to extract the title
57
55
-> DocParams -- ^ Parameters for the documentation
56
+ -> HtmlFileType -- ^ Are we rendering an index page?
57
+ -> Html () -- ^ Content to be included
58
58
-> Html ()
59
- dhallFileToHtml filePath contents expr examples header params@ DocParams {.. } =
59
+ htmlTemplate filePath params@ DocParams {.. } isIndex html =
60
60
doctypehtml_ $ do
61
61
headContents htmlTitle params
62
62
body_ $ do
63
63
navBar params
64
64
mainContainer $ do
65
- setPageTitle params NotIndex breadcrumb
65
+ setPageTitle params isIndex breadcrumb
66
66
copyToClipboardButton clipboardText
67
67
br_ []
68
- div_ [class_ " doc-contents" ] header
69
- Control.Monad. unless (null examples) $ do
70
- h3_ " Examples"
71
- div_ [class_ " source-code code-examples" ] $
72
- mapM_ (renderCodeSnippet characterSet AssertionExample ) examples
73
- h3_ " Source"
74
- div_ [class_ " source-code" ] $ renderCodeWithHyperLinks contents expr
68
+ html
75
69
where
76
70
breadcrumb = relPathToBreadcrumb filePath
77
71
htmlTitle = breadCrumbsToText breadcrumb
78
72
clipboardText = fold baseImportUrl <> htmlTitle
79
73
80
- -- | Generates an @`Html` ()@ with all the information about a non-dhall text file
74
+ -- | Generates an @`Html` ()@ with all the information about a dhall file
75
+ dhallFileToHtml
76
+ :: Path Rel File -- ^ Source file name, used to extract the title
77
+ -> Text -- ^ Contents of the file
78
+ -> Expr Src Import -- ^ AST of the file
79
+ -> [Expr Void Import ] -- ^ Examples extracted from the assertions of the file
80
+ -> Html () -- ^ Header document as HTML
81
+ -> DocParams -- ^ Parameters for the documentation
82
+ -> Html ()
83
+ dhallFileToHtml filePath contents expr examples header params@ DocParams {.. } =
84
+ htmlTemplate filePath params NotIndex $ do
85
+ div_ [class_ " doc-contents" ] header
86
+ Control.Monad. unless (null examples) $ do
87
+ h3_ " Examples"
88
+ div_ [class_ " source-code code-examples" ] $
89
+ mapM_ (renderCodeSnippet characterSet AssertionExample ) examples
90
+ h3_ " Source"
91
+ div_ [class_ " source-code" ] $ renderCodeWithHyperLinks contents expr
92
+
93
+ -- | Generates an @`Html` ()@ with all the information about a Markdown file
94
+ markdownFileToHtml
95
+ :: Path Rel File -- ^ Source file name, used to extract the title
96
+ -> Text -- ^ Original text contents of the file
97
+ -> Html () -- ^ Contents converted to HTML
98
+ -> DocParams -- ^ Parameters for the documentation
99
+ -> Html ()
100
+ markdownFileToHtml filePath contents html params =
101
+ htmlTemplate filePath params NotIndex $ do
102
+ details_ [open_ " " ] $ do
103
+ summary_ [class_ " part-summary" ] " Rendered content"
104
+ div_ [class_ " doc-contents" ] html
105
+ details_ $ do
106
+ summary_ [class_ " part-summary" ] " Source"
107
+ div_ [class_ " source-code" ] $ pre_ (toHtml contents)
108
+
109
+
110
+ -- | Generates an @`Html` ()@ with all the information about a text file
81
111
textFileToHtml
82
112
:: Path Rel File -- ^ Source file name, used to extract the title
83
113
-> Text -- ^ Contents of the file
84
114
-> DocParams -- ^ Parameters for the documentation
85
115
-> Html ()
86
- textFileToHtml filePath contents params@ DocParams {.. } =
87
- doctypehtml_ $ do
88
- headContents htmlTitle params
89
- body_ $ do
90
- navBar params
91
- mainContainer $ do
92
- setPageTitle params NotIndex breadcrumb
93
- copyToClipboardButton clipboardText
94
- br_ []
95
- h3_ " Source"
96
- div_ [class_ " source-code" ] $ pre_ (toHtml contents)
97
- where
98
- breadcrumb = relPathToBreadcrumb filePath
99
- htmlTitle = breadCrumbsToText breadcrumb
100
- clipboardText = fold baseImportUrl <> htmlTitle
116
+ textFileToHtml filePath contents params =
117
+ htmlTemplate filePath params NotIndex $ do
118
+ h3_ " Source"
119
+ div_ [class_ " source-code" ] $ pre_ (toHtml contents)
101
120
102
121
-- | Generates an index @`Html` ()@ that list all the dhall files in that folder
103
122
indexToHtml
@@ -106,21 +125,15 @@ indexToHtml
106
125
-> [Path Rel Dir ] -- ^ Generated directories in that directory
107
126
-> DocParams -- ^ Parameters for the documentation
108
127
-> Html ()
109
- indexToHtml indexDir files dirs params@ DocParams {.. } = doctypehtml_ $ do
110
- headContents htmlTitle params
111
- body_ $ do
112
- navBar params
113
- mainContainer $ do
114
- setPageTitle params Index breadcrumbs
115
- copyToClipboardButton clipboardText
116
- br_ []
117
- Control.Monad. unless (null files) $ do
118
- h3_ " Exported files: "
119
- ul_ $ mconcat $ map listFile files
120
-
121
- Control.Monad. unless (null dirs) $ do
122
- h3_ " Exported packages: "
123
- ul_ $ mconcat $ map listDir dirs
128
+ indexToHtml indexDir files dirs params@ DocParams {.. } =
129
+ htmlTemplate indexDir params Index $ do
130
+ Control.Monad. unless (null files) $ do
131
+ h3_ " Exported files: "
132
+ ul_ $ mconcat $ map listFile files
133
+
134
+ Control.Monad. unless (null dirs) $ do
135
+ h3_ " Exported packages: "
136
+ ul_ $ mconcat $ map listDir dirs
124
137
125
138
where
126
139
listFile :: (Path Rel File , Maybe (Expr Void Import )) -> Html ()
@@ -145,10 +158,6 @@ indexToHtml indexDir files dirs params@DocParams{..} = doctypehtml_ $ do
145
158
Nothing -> file
146
159
Just (f, _) -> f
147
160
148
- breadcrumbs = relPathToBreadcrumb indexDir
149
- htmlTitle = breadCrumbsToText breadcrumbs
150
- clipboardText = fold baseImportUrl <> htmlTitle
151
-
152
161
copyToClipboardButton :: Text -> Html ()
153
162
copyToClipboardButton filePath =
154
163
a_ [class_ " copy-to-clipboard" , data_ " path" filePath]
0 commit comments