vendor/plugins/haml/lib/haml/engine.rb in radiant-0.6.7 vs vendor/plugins/haml/lib/haml/engine.rb in radiant-0.6.8
- old
+ new
@@ -43,15 +43,15 @@
@options[:format] == :html5
end
# Creates a new instace of Haml::Engine that will compile the given
# template string when <tt>render</tt> is called.
- # See README.rdoc for available options.
+ # See the Haml module documentation for available options.
#
#--
# When adding options, remember to add information about them
- # to README.rdoc!
+ # to lib/haml.rb!
#++
#
def initialize(template, options = {})
@options = {
:suppress_eval => false,
@@ -59,57 +59,48 @@
# Don't forget to update the docs in lib/haml.rb if you update these
:autoclose => %w[meta img link br hr input area param col base],
:preserve => %w[textarea pre],
- :filters => {
- 'sass' => Haml::Filters::Sass,
- 'plain' => Haml::Filters::Plain,
- 'javascript' => Haml::Filters::Javascript,
- 'preserve' => Haml::Filters::Preserve,
- 'redcloth' => Haml::Filters::RedCloth,
- 'textile' => Haml::Filters::Textile,
- 'markdown' => Haml::Filters::Markdown },
:filename => '(haml)',
:line => 1,
:ugly => false,
:format => :xhtml,
:escape_html => false
}
- @options[:filters].merge! options.delete(:filters) if options[:filters]
@options.merge! options
unless [:xhtml, :html4, :html5].include?(@options[:format])
raise Haml::Error, "Invalid format #{@options[:format].inspect}"
end
- unless @options[:suppress_eval]
- @options[:filters].merge!({
- 'erb' => Haml::Filters::ERB,
- 'ruby' => Haml::Filters::Ruby
- })
- end
-
- if @options[:locals]
- warn <<END
-DEPRECATION WARNING:
-The Haml :locals option is deprecated and will be removed in version 2.0.
-Use the locals option for Haml::Engine#render instead.
-END
- end
-
- @template = template.rstrip #String
+ @template = template.rstrip + "\n-#\n-#"
@to_close_stack = []
@output_tabs = 0
@template_tabs = 0
@index = 0
@flat_spaces = -1
@newlines = 0
+ @precompiled = ''
+ @merged_text = ''
+ @tab_change = 0
+ if @template =~ /\A(\s*\n)*[ \t]+\S/
+ raise SyntaxError.new("Indenting at the beginning of the document is illegal.", ($1 || "").count("\n"))
+ end
+
+ if @options[:filters]
+ warn <<END
+DEPRECATION WARNING:
+The Haml :filters option is deprecated and will be removed in version 2.1.
+Filters are now automatically registered.
+END
+ end
+
precompile
- rescue Haml::Error
- $!.backtrace.unshift "#{@options[:filename]}:#{@index + $!.line_offset + @options[:line] - 1}" if @index
+ rescue Haml::Error => e
+ e.backtrace.unshift "#{@options[:filename]}:#{(e.line ? e.line + 1 : @index) + @options[:line] - 1}" if @index
raise
end
# Processes the template and returns the result as a string.
#
@@ -145,10 +136,9 @@
# In particular, it's equivalent to passing <tt>eval("self", scope)</tt> as scope.
# This won't have an effect in most cases,
# but if you're relying on local variables defined in the context of scope,
# they won't work.
def render(scope = Object.new, locals = {}, &block)
- locals = (@options[:locals] || {}).merge(locals)
buffer = Haml::Buffer.new(scope.instance_variable_get('@haml_buffer'), options_for_buffer)
if scope.is_a?(Binding) || scope.is_a?(Proc)
scope_object = eval("self", scope)
scope = scope_object.instance_eval{binding} if block_given?