From 426441eecf7f06f3bb75a44fd76d5f5937f0a89f Mon Sep 17 00:00:00 2001 From: "G. Allais" Date: Wed, 15 Sep 2021 15:21:56 +0100 Subject: [PATCH] [ new ] persistent css switch and alternative style files (#1923) --- Makefile | 2 +- src/Idris/Doc/HTML.idr | 78 +++++++- src/Idris/Package.idr | 12 +- src/Idris/Package/Types.idr | 17 ++ support/docs/alternative.css | 242 +++++++++++++++++++++++ support/docs/blackandwhite.css | 242 +++++++++++++++++++++++ support/docs/{styles.css => default.css} | 0 support/docs/index.html | 2 +- 8 files changed, 583 insertions(+), 12 deletions(-) create mode 100644 support/docs/alternative.css create mode 100644 support/docs/blackandwhite.css rename support/docs/{styles.css => default.css} (100%) diff --git a/Makefile b/Makefile index 4dbb15d3f..3f1133230 100644 --- a/Makefile +++ b/Makefile @@ -186,7 +186,7 @@ install-support: mkdir -p ${PREFIX}/${NAME_VERSION}/support/racket mkdir -p ${PREFIX}/${NAME_VERSION}/support/gambit mkdir -p ${PREFIX}/${NAME_VERSION}/support/js - install -m 644 support/docs/styles.css ${PREFIX}/${NAME_VERSION}/support/docs + install -m 644 support/docs/*.css ${PREFIX}/${NAME_VERSION}/support/docs install -m 644 support/racket/* ${PREFIX}/${NAME_VERSION}/support/racket install -m 644 support/gambit/* ${PREFIX}/${NAME_VERSION}/support/gambit install -m 644 support/js/* ${PREFIX}/${NAME_VERSION}/support/js diff --git a/src/Idris/Doc/HTML.idr b/src/Idris/Doc/HTML.idr index b9847c629..959e59e0d 100644 --- a/src/Idris/Doc/HTML.idr +++ b/src/Idris/Doc/HTML.idr @@ -115,13 +115,77 @@ docDocToHtml doc = renderHtml $ removeNewlinesFromDeclarations dt htmlPreamble : String -> String -> String -> String -htmlPreamble title root class = "" - ++ "" ++ htmlEscape title ++ "" - ++ "" - ++ "" - ++ "
Idris2Doc : " ++ htmlEscape title - ++ "
" - ++ "
" +htmlPreamble title root class = + let title = htmlEscape title in + let cssID = "preferredStyle" in + let cssSelectID = "selectPreferredStyle" in + let cssDefault = "default" in + let cssLocalKey = "stylefile" in + """ + + + + + \{title} + + + + + +
+ Idris2Doc : \{title} + + + + +
+
+ """ htmlFooter : String htmlFooter = "
Produced by Idris 2 version " ++ (showVersion True version) ++ "
" diff --git a/src/Idris/Package.idr b/src/Idris/Package.idr index dbc850408..806086f65 100644 --- a/src/Idris/Package.idr +++ b/src/Idris/Package.idr @@ -528,9 +528,15 @@ makeDoc pkg opts = Right () <- coreLift $ writeFile (docBase "index.html") $ renderDocIndex pkg | Left err => fileError (docBase "index.html") err - css <- readDataFile "docs/styles.css" - Right () <- coreLift $ writeFile (docBase "styles.css") css - | Left err => fileError (docBase "styles.css") err + errs <- for cssFiles $ \ cssFile => do + let fn = cssFile.filename ++ ".css" + css <- readDataFile ("docs/" ++ fn) + Right () <- coreLift $ writeFile (docBase fn) css + | Left err => fileError (docBase fn) err + pure (the (List Error) []) + + let [] = concat errs + | err => pure err runScript (postbuild pkg) pure [] diff --git a/src/Idris/Package/Types.idr b/src/Idris/Package/Types.idr index a537343d7..0cc897c9d 100644 --- a/src/Idris/Package/Types.idr +++ b/src/Idris/Package/Types.idr @@ -243,3 +243,20 @@ Pretty PkgDesc where seqField nm xs = pretty nm <++> equals <++> align (sep (punctuate comma (map pretty xs))) + + +------------------------------------------------------------------------------ +-- CSS files (used in --mkdoc) + +public export +record CSS where + constructor MkCSS + stylename : String + filename : String + +export +cssFiles : List CSS +cssFiles = [ MkCSS "Default" "default" + , MkCSS "Alternative" "alternative" + , MkCSS "Black & White" "blackandwhite" + ] diff --git a/support/docs/alternative.css b/support/docs/alternative.css new file mode 100644 index 000000000..0d5903fa2 --- /dev/null +++ b/support/docs/alternative.css @@ -0,0 +1,242 @@ +html, +body { + margin: 0; + padding: 0; + border: 0; + height: 100%; + font-family: "Trebuchet MS", Helvetica, sans-serif; + font-size: 11pt; + background-color: #fff; +} + +a, +a:active, +a:visited { + text-decoration: none; + color: inherit; +} + +a:hover { + text-decoration: underline; +} + +header { + padding: 5px 11px; + border-bottom: 3px solid #659fdb; + box-shadow: 0 -8px 22px 0; + background-color: #252525; + color: white; + font-size: 9pt; +} + +.wrapper { + min-height: 100%; +} + +header nav, +header strong { + font-size: 11pt; +} + +header nav { + float: right; +} + +footer { + height: 30px; + width: 100%; + border-top: 1px solid #aaa; + margin-top: -31px; + text-align: center; + color: #666; + line-height: 30px; + font-size: 9pt; + background: none repeat scroll 0 0 #ddd; +} + +.container { + padding: 10px 10px 41px 20px; +} + +h1 { + margin: 0; + margin-bottom: 5px; + font-size: 14pt; + font-family: "Trebuchet MS", Helvetica, sans-serif; +} + +#moduleHeader { + border-bottom: 1px solid #bbb; + padding-bottom: 2px; +} + +ul { + list-style-type: none; + margin: 0; + padding: 0; +} + +hr { + margin: 0; + padding: 0; + border: 0; + border-bottom: 1px solid #bbb; +} + +p { + margin: 0; + padding: 0; +} + +.code { + font-family: "Lucida Console", Monaco, monospace; + font-size: 10pt; +} + +.decls { + margin-top: 5px; +} + +.decls > dt { + font-family: "Lucida Console", Monaco, monospace; + font-size: 10pt; + line-height: 20px; + padding: 2px 6px; + border: 1px solid #ccc; + background-color: #f0f0f0; + display: table; + width: 100%; + box-sizing: border-box; + white-space: pre-wrap; +} + +.decls > dd { + margin: 10px 0 20px 20px; + font-family: Arial, sans-serif; + font-size: 10pt; +} + +.decls > dd > p { + margin-bottom: 8px; +} + +.decls > dd > dl:not(.decls):not(:first-child) { + padding-top: 5px; + border-top: 1px solid #eee; +} + +.decls > dd > dl:not(.decls) > dt { + display: block; + min-width: 70px; + float: left; + font-weight: bold; +} + +.decls > dd > dl:not(.decls) > dd { + margin-bottom: 2px; +} + +.fixity { + font-style: italic; + font-weight: normal !important; +} + +dd.fixity { + cursor: default; +} + +.word { + display: table-cell; + white-space: nowrap; + width: 0; +} + +.signature { + display: table-cell; + width: 100%; +} + +.name { + white-space: nowrap; + width: 0; +} + +.documented, +.name { + cursor: default; +} + +.documented { + font-weight: bold; +} + +/* The following colours are taken from the conservative 8 color palette given + in http://mkweb.bcgsc.ca/colorblind/palettes.mhtml +*/ + +a.function { + color: rgb(53, 155, 115); +} + +.function { + color: rgb(53, 155, 115); +} + +a.constructor { + color: rgb(213, 94, 0); +} + +.constructor { + color: rgb(213, 94, 0); +} + +a.type { + color: rgb(61, 183, 233); +} + +.type { + color: rgb(61, 183, 233); +} + +.keyword { + color: inherit; +} + +.boundvar { + color: rgb(247, 72, 165); /* Too much colour makes it hard to differ the rest of the colours */ + color: inherit; +} + +.boundvar.implicit { + text-decoration: underline; +} + +ul.names { + border: 1px solid #666; +} + +ul.names li { + padding-left: 5px; +} + +ul.names li a { + display: inline-block; + width: 100%; + padding: 2px 0; +} + +ul.names li:nth-child(odd) { + background-color: #eeeeef; +} + +ul.names li:nth-child(even) { + background-color: white; +} + +body.index .container a:visited { + color: #666; +} + +body.index .container a:hover { + color: #04819e; +} diff --git a/support/docs/blackandwhite.css b/support/docs/blackandwhite.css new file mode 100644 index 000000000..e1567f116 --- /dev/null +++ b/support/docs/blackandwhite.css @@ -0,0 +1,242 @@ +html, +body { + margin: 0; + padding: 0; + border: 0; + height: 100%; + font-family: "Trebuchet MS", Helvetica, sans-serif; + font-size: 11pt; + background-color: #fff; +} + +a, +a:active, +a:visited { + text-decoration: none; + color: inherit; +} + +a:hover { + text-decoration: underline; +} + +header { + padding: 5px 11px; + border-bottom: 3px solid #659fdb; + box-shadow: 0 -8px 22px 0; + background-color: #252525; + color: white; + font-size: 9pt; +} + +.wrapper { + min-height: 100%; +} + +header nav, +header strong { + font-size: 11pt; +} + +header nav { + float: right; +} + +footer { + height: 30px; + width: 100%; + border-top: 1px solid #aaa; + margin-top: -31px; + text-align: center; + color: #666; + line-height: 30px; + font-size: 9pt; + background: none repeat scroll 0 0 #ddd; +} + +.container { + padding: 10px 10px 41px 20px; +} + +h1 { + margin: 0; + margin-bottom: 5px; + font-size: 14pt; + font-family: "Trebuchet MS", Helvetica, sans-serif; +} + +#moduleHeader { + border-bottom: 1px solid #bbb; + padding-bottom: 2px; +} + +ul { + list-style-type: none; + margin: 0; + padding: 0; +} + +hr { + margin: 0; + padding: 0; + border: 0; + border-bottom: 1px solid #bbb; +} + +p { + margin: 0; + padding: 0; +} + +.code { + font-family: "Lucida Console", Monaco, monospace; + font-size: 10pt; +} + +.decls { + margin-top: 5px; +} + +.decls > dt { + font-family: "Lucida Console", Monaco, monospace; + font-size: 10pt; + line-height: 20px; + padding: 2px 6px; + border: 1px solid #ccc; + background-color: #f0f0f0; + display: table; + width: 100%; + box-sizing: border-box; + white-space: pre-wrap; +} + +.decls > dd { + margin: 10px 0 20px 20px; + font-family: Arial, sans-serif; + font-size: 10pt; +} + +.decls > dd > p { + margin-bottom: 8px; +} + +.decls > dd > dl:not(.decls):not(:first-child) { + padding-top: 5px; + border-top: 1px solid #eee; +} + +.decls > dd > dl:not(.decls) > dt { + display: block; + min-width: 70px; + float: left; + font-weight: bold; +} + +.decls > dd > dl:not(.decls) > dd { + margin-bottom: 2px; +} + +.fixity { + font-style: italic; + font-weight: normal !important; +} + +dd.fixity { + cursor: default; +} + +.word { + display: table-cell; + white-space: nowrap; + width: 0; +} + +.signature { + display: table-cell; + width: 100%; +} + +.name { + white-space: nowrap; + width: 0; +} + +.documented, +.name { + cursor: default; + font-weight: normal; + font-style: normal; + font-variant: normal; +} + +.documented { + font-weight: bold; +} + +a.function { + font-style: italic; +} + +.function { + font-style: italic; +} + +a.constructor { + font-weight: bold; +} + +.constructor { + font-weight: bold; +} + +a.type { + font-variant: small-caps !important; +} + +.type { + font-variant: small-caps !important; +} + +.keyword { + text-decoration: underline; + color: inherit; +} + +.boundvar { + color: #bf30bf; /* Too much colour makes it hard to differ the rest of the colours */ + color: inherit; +} + +.boundvar.implicit { + text-decoration: underline; +} + +ul.names { + border: 1px solid #666; +} + +ul.names li { + padding-left: 5px; +} + +ul.names li a { + display: inline-block; + width: 100%; + padding: 2px 0; +} + +ul.names li:nth-child(odd) { + background-color: #eeeeef; +} + +ul.names li:nth-child(even) { + background-color: white; +} + +body.index .container a:visited { + color: #666; +} + +body.index .container a:hover { + color: #04819e; +} diff --git a/support/docs/styles.css b/support/docs/default.css similarity index 100% rename from support/docs/styles.css rename to support/docs/default.css diff --git a/support/docs/index.html b/support/docs/index.html index 4a2fa334e..c51f565c5 100644 --- a/support/docs/index.html +++ b/support/docs/index.html @@ -3,7 +3,7 @@ Idris Packages - +