help.html: simplify html by saving styles as classes.

We store the CSS classes in the HTML <style> tag.
db4
John Benediktsson 2015-09-14 13:32:38 -07:00
parent eaa65bc66f
commit 74d8e43312
1 changed files with 43 additions and 14 deletions

View File

@ -1,11 +1,13 @@
! Copyright (C) 2008, 2011 Slava Pestov. ! Copyright (C) 2008, 2011 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs debugger fry help help.home USING: accessors arrays assocs combinators.short-circuit
help.topics help.vocabs html html.streams io.directories debugger fry help help.home help.topics help.vocabs html
io.encodings.binary io.encodings.utf8 io.files io.files.temp html.streams io.directories io.encodings.binary
io.pathnames kernel make math.parser memoize namespaces io.encodings.utf8 io.files io.files.temp io.pathnames kernel
sequences serialize splitting tools.completion vocabs locals make math math.parser memoize namespaces sequences
vocabs.hierarchy words xml.syntax xml.writer ; sequences.deep serialize sorting splitting tools.completion
vocabs vocabs.hierarchy words xml.data xml.syntax xml.traversal
xml.writer ;
FROM: io.encodings.ascii => ascii ; FROM: io.encodings.ascii => ascii ;
FROM: ascii => ascii? ; FROM: ascii => ascii? ;
IN: help.html IN: help.html
@ -65,9 +67,9 @@ M: pathname url-of
prepend prepend
] [ drop f ] if ; ] [ drop f ] if ;
: help-stylesheet ( -- xml ) : help-stylesheet ( stylesheet -- xml )
"vocab:help/html/stylesheet.css" ascii file-contents "vocab:help/html/stylesheet.css" ascii file-contents
[XML <style><-></style> XML] ; swap "\n" glue [XML <style><-></style> XML] ;
: help-navbar ( -- xml ) : help-navbar ( -- xml )
"conventions" >link topic>filename "conventions" >link topic>filename
@ -84,15 +86,42 @@ M: pathname url-of
</div> </div>
XML] ; XML] ;
: bijective-base26 ( n -- name )
[ dup 0 > ] [ 1 - 26 /mod CHAR: a + ] "" produce-as nip reverse! ;
: css-class ( style classes -- name )
dup '[ drop _ assoc-size 1 + bijective-base26 ] cache ;
: css-classes ( classes -- stylesheet )
[
[ " { " " }" surround ] [ "." prepend ] bi* prepend
] { } assoc>map "\n" join ;
:: css-styles-to-classes ( body -- stylesheet body )
H{ } clone :> classes
body [
dup xml-chunk? [
seq>> [ tag? ] filter
"span" "div" [ deep-tags-named ] bi-curry@ bi append
[
dup {
[ "style" attr ]
[ "class" attr not ]
} 1&& [
attrs>> [ V{ } like ] change-alist
"style" over delete-at* drop classes css-class
"class" rot set-at
] [ drop ] if
] each
] [ drop ] if
] each classes sort-values css-classes body ;
: help>html ( topic -- xml ) : help>html ( topic -- xml )
[ article-title " - Factor Documentation" append ] [ article-title " - Factor Documentation" append ]
[ drop help-stylesheet ]
[ [
[ help-navbar ] [ print-topic ] with-html-writer css-styles-to-classes
[ [ print-topic ] with-html-writer ] [ help-stylesheet ] [ help-navbar prepend ] bi*
bi* append ] bi simple-page ;
] tri
simple-page ;
: generate-help-file ( topic -- ) : generate-help-file ( topic -- )
dup topic>filename utf8 [ help>html write-xml ] with-file-writer ; dup topic>filename utf8 [ help>html write-xml ] with-file-writer ;