! Copyright (C) 2005 Alex Chapman
! Copyright (C) 2006, 2010 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors combinators compiler.units html.templates io
-io.encodings.utf8 io.files kernel lexer math namespaces parser
-parser.notes quotations sequences splitting vocabs.parser ;
+USING: accessors compiler.units html.templates io
+io.encodings.utf8 io.files kernel lexer lexer.private math
+namespaces parser parser.notes quotations sequences splitting
+vocabs.parser ;
IN: html.templates.fhtml
! We use a custom lexer so that %> ends a token even if not
M: template-lexer skip-word
[
- {
- { [ 2dup nth CHAR: \" = ] [ drop 1 + ] }
- { [ 2dup swap tail-slice "%>" head? ] [ drop 2 + ] }
- [ f skip ]
- } cond
+ 2dup swap tail-slice "%>" head?
+ [ drop 2 + ] [ (skip-word) ] if
] change-lexer-column ;
DEFER: <% delimiter
: check-<% ( lexer -- col )
- [ line-text>> "<%" ] [ column>> ] bi start ;
+ "<%" swap [ line-text>> ] [ column>> ] bi subseq-start-from ;
: found-<% ( accum lexer col -- accum )
[
[
parser-quiet? on
"html.templates.fhtml" use-vocab
- string-lines parse-template-lines
+ split-lines parse-template-lines
] with-file-vocabs
] with-compilation-unit ;
C: <fhtml> fhtml
-M: fhtml call-template* ( filename -- )
+M: fhtml call-template*
path>> utf8 file-contents eval-template ;
INSTANCE: fhtml template