]> gitweb.factorcode.org Git - factor.git/commitdiff
html.templates: adding meta tag and some chloe tests.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 2 Mar 2020 23:57:19 +0000 (15:57 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 2 Mar 2020 23:57:19 +0000 (15:57 -0800)
basis/html/templates/chloe/chloe-tests.factor
basis/html/templates/chloe/chloe.factor
basis/html/templates/templates.factor

index 9128eef6b7677d783013d581cb24c2f59f749b3f..2a205f929f5c83c15fcc971ab8d102e847b5ece6 100644 (file)
@@ -194,3 +194,21 @@ TUPLE: person first-name last-name ;
         ] run-template
     ] with-scope
 ] [ error>> tag-not-allowed-here? ] must-fail-with
+
+{ "This is     <style type=\"text/css\"> * { font-family: monospace; } </style>" } [
+    SBUF" " clone style [
+        [ "test16" test-template call-template ] run-template
+    ] with-variable
+] unit-test
+
+{ "<script type=\"text/javascript\"> function testAlerts() {    window.alert(\"Hello, world!\");} </script>" } [
+    SBUF" " clone script [
+        [ "test17" test-template call-template ] run-template
+    ] with-variable
+] unit-test
+
+{ "<meta name=\"author\" content=\"John Doe\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>" } [
+    V{ } clone meta [
+        [ "test18" test-template call-template ] run-template
+    ] with-variable
+] unit-test
index 89feebecd0e53d8646d61e0d072364082e01cc99..483f31c3db05b916e4b8e68b913b6a4571221761 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs html.components html.forms
+USING: accessors arrays assocs fry html.components html.forms
 html.templates html.templates.chloe.compiler
 html.templates.chloe.components html.templates.chloe.syntax
 io.encodings.utf8 io.files io.files.info kernel logging make
@@ -49,6 +49,14 @@ CHLOE: write-script
         [XML <script type="text/javascript"> <-> </script> XML]
     ] [xml-code] ;
 
+CHLOE: meta
+    [ "name" optional-attr ]
+    [ "content" optional-attr ] bi
+    '[ _ _ add-meta ] [code] ;
+
+CHLOE: write-meta
+    drop [ get-meta ] [xml-code] ;
+
 CHLOE: even
     [ "index" value even? swap when ] process-children ;
 
index 9fe3b1bb7db1a26bfbcdd491c9ee3fefbdd01b78..3966b1ac83f37c9c4319cfdf16e34c167c273446 100644 (file)
@@ -1,9 +1,13 @@
 ! Copyright (C) 2008, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel fry io io.encodings.utf8 io.files
-debugger prettyprint continuations namespaces boxes sequences
-arrays strings html io.streams.string assocs
-quotations xml.data xml.writer xml.syntax ;
+USING: accessors arrays assocs boxes continuations debugger io
+io.encodings.utf8 io.files io.streams.string kernel namespaces
+prettyprint quotations sequences strings xml.data xml.syntax
+xml.writer ;
+! USING: accessors kernel fry io io.encodings.utf8 io.files
+! debugger prettyprint continuations namespaces boxes sequences
+! arrays strings html io.streams.string assocs
+! quotations xml.data xml.writer xml.syntax ;
 IN: html.templates
 
 MIXIN: template
@@ -71,6 +75,19 @@ SYMBOL: script
 : write-script ( -- )
     get-script write ;
 
+SYMBOL: meta
+
+: add-meta ( name content -- )
+    2array meta get push ;
+
+: get-meta ( -- xml )
+    meta get [
+        [XML <meta name=<-> content=<->/> XML]
+    ] { } assoc>map ;
+
+: write-meta ( -- )
+    get-meta write-xml ;
+
 SYMBOL: atom-feeds
 
 : add-atom-feed ( title url -- )
@@ -104,6 +121,7 @@ M: f call-template* drop call-next-template ;
         title [ [ <box> ] unless* ] change
         style [ [ SBUF" " clone ] unless* ] change
         script [ [ SBUF" " clone ] unless* ] change
+        meta [ [ V{ } clone ] unless* ] change
         atom-feeds [ V{ } like ] change
 
         [