lib/cutaneous/lexer.rb in cutaneous-0.1.7 vs lib/cutaneous/lexer.rb in cutaneous-0.2.0
- old
+ new
@@ -22,22 +22,18 @@
template << open.to_s << token[1] << close.to_s
end
template
end
- # def script
- # @script ||= compile
- # end
-
protected
BRACES ||= /\{|\}/
STRIP_WS = "-"
def parse
tokens = []
- scanner = StringScanner.new(@template.to_s)
+ scanner = StringScanner.new(template_string)
tag_start = syntax.tag_start_pattern
tags = syntax.tags
token_map = syntax.token_map
previous = nil
@@ -81,8 +77,20 @@
def place_text_token(expression)
expression.gsub!(syntax.escaped_tag_pattern, '\1')
expression.gsub!(ESCAPE_STRING, '\\\\\&')
[:text, expression]
+ end
+
+ def template_string
+ return read_file_template if @template.respond_to?(:read)
+ return @template.call if @template.respond_to?(:call)
+ @template.to_s
+ end
+
+ def read_file_template
+ source = @template.read
+ @template.close if @template.respond_to?(:close)
+ source
end
end
end