lib/faml/compiler.rb in faml-0.2.1 vs lib/faml/compiler.rb in faml-0.2.2
- old
+ new
@@ -1,9 +1,10 @@
require 'parser/current'
require 'temple'
require 'faml/ast'
require 'faml/filter_compilers'
+require 'faml/helpers'
require 'faml/static_hash_parser'
require 'faml/text_compiler'
module Faml
class Compiler < Temple::Parser
@@ -34,19 +35,14 @@
def self.find_and_preserve(input)
# Taken from the original haml code
re = /<(#{options[:preserve].map(&Regexp.method(:escape)).join('|')})([^>]*)>(.*?)(<\/\1>)/im
input.to_s.gsub(re) do |s|
s =~ re # Can't rely on $1, etc. existing since Rails' SafeBuffer#gsub is incompatible
- "<#{$1}#{$2}>#{preserve($3)}</#{$1}>"
+ "<#{$1}#{$2}>#{Helpers.preserve($3)}</#{$1}>"
end
end
- def self.preserve(input)
- # Taken from the original haml code
- input.to_s.chomp("\n").gsub(/\n/, '
').gsub(/\r/, '')
- end
-
private
def compile(ast)
case ast
when Ast::Root
@@ -73,10 +69,10 @@
raise "InternalError: Unknown AST node #{ast.class}: #{ast.inspect}"
end
end
def compile_root(ast)
- [:multi].tap do |temple|
+ [:multi, [:code, 'extend ::Faml::Helpers']].tap do |temple|
compile_children(ast, temple)
end
end
def compile_children(ast, temple)