]> gitweb.factorcode.org Git - factor.git/commitdiff
html.templates: adding t:script and t:write-script.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 1 Mar 2020 20:05:59 +0000 (12:05 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 1 Mar 2020 20:05:59 +0000 (12:05 -0800)
basis/html/templates/chloe/chloe-docs.factor
basis/html/templates/chloe/chloe.factor
basis/html/templates/templates.factor

index af03e8e1b96f03894d64fa17b01d09ec79f97ffe..c38cf0ac4c9c435c004c2fc87b004b9258129dd9 100644 (file)
@@ -88,6 +88,8 @@ $nl
     { { $snippet "t:write-title" } "Renders the child's title. Intended for use in a child template." }
     { { $snippet "t:style" } { "Adds CSS markup from the file named by the " { $snippet "t:include" } " attribute. Intended for use in a child template." } }
     { { $snippet "t:write-style" } "Renders the children's CSS markup. Intended for use in a master template." }
+    { { $snippet "t:script" } { "Adds JS from the file named by the " { $snippet "t:include" } " attribute. Intended for use in a child template." } }
+    { { $snippet "t:write-script" } "Renders the children's JS. Intended for use in a master template." }
     { { $snippet "t:atom" } { "Adds an Atom feed link. The attributes are the same as the " { $snippet "t:link" } " tag. Intended for use in a child template. (*)" } }
     { { $snippet "t:write-atom" } "Renders the children's list of Atom feed links. Intended for use in a master template. (*)" }
     { { $snippet "t:call-next-template" } "Calls the next child template from a master template." }
index 0cd639d80506dd344e3b4d2d97e8034610f9f1a9..89feebecd0e53d8646d61e0d072364082e01cc99 100644 (file)
@@ -36,6 +36,19 @@ CHLOE: write-style
         [XML <style type="text/css"> <-> </style> XML]
     ] [xml-code] ;
 
+CHLOE: script
+    dup "include" optional-attr [
+        utf8 file-contents [ add-script ] [code-with]
+    ] [
+        compile-children>string [ add-script ] [code]
+    ] ?if ;
+
+CHLOE: write-script
+    drop [
+        get-script
+        [XML <script type="text/javascript"> <-> </script> XML]
+    ] [xml-code] ;
+
 CHLOE: even
     [ "index" value even? swap when ] process-children ;
 
index 41872054954eaa14362234123685395ba64a9b82..9fe3b1bb7db1a26bfbcdd491c9ee3fefbdd01b78 100644 (file)
@@ -59,6 +59,18 @@ SYMBOL: style
 : write-style ( -- )
     get-style write ;
 
+SYMBOL: script
+
+: add-script ( string -- )
+    "\n" script get push-all
+         script get push-all ;
+
+: get-script ( -- string )
+    script get >string ;
+
+: write-script ( -- )
+    get-script write ;
+
 SYMBOL: atom-feeds
 
 : add-atom-feed ( title url -- )
@@ -91,6 +103,7 @@ M: f call-template* drop call-next-template ;
     [
         title [ [ <box> ] unless* ] change
         style [ [ SBUF" " clone ] unless* ] change
+        script [ [ SBUF" " clone ] unless* ] change
         atom-feeds [ V{ } like ] change
 
         [