Allow parser and compiler classes to be set in options
This makes it easier to extend and modify Haml. The change was originally motivated by issue #570.
This commit is contained in:
parent
0468dcbd36
commit
7f8c794fa8
|
@ -13,7 +13,8 @@
|
|||
|
||||
* Haml's internals have been refactored to move the parser, compiler and options
|
||||
handling into independent classes, rather than including them all in the
|
||||
Engine module.
|
||||
Engine module. You can also specify your own custom Haml parser or compiler
|
||||
class in Haml::Options in order to extend or modify Haml reasonably easily.
|
||||
|
||||
* The :sass filter now wraps its output in a script tag, as do the new :less and
|
||||
:scss filters. The :coffee filter wraps its output in a script tag.
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'forwardable'
|
||||
|
||||
require 'haml/parser'
|
||||
require 'haml/compiler'
|
||||
require 'haml/options'
|
||||
require 'haml/helpers'
|
||||
require 'haml/buffer'
|
||||
require 'haml/parser'
|
||||
require 'haml/compiler'
|
||||
require 'haml/filters'
|
||||
require 'haml/error'
|
||||
|
||||
|
@ -60,8 +60,8 @@ module Haml
|
|||
|
||||
initialize_encoding options[:encoding]
|
||||
|
||||
@parser = Parser.new(@template, @options)
|
||||
@compiler = Compiler.new(@options)
|
||||
@parser = @options.parser_class.new(@template, @options)
|
||||
@compiler = @options.compiler_class.new(@options)
|
||||
|
||||
@compiler.compile(@parser.parse)
|
||||
end
|
||||
|
|
|
@ -19,7 +19,9 @@ module Haml
|
|||
:remove_whitespace => false,
|
||||
:suppress_eval => false,
|
||||
:ugly => false,
|
||||
:cdata => false
|
||||
:cdata => false,
|
||||
:parser_class => ::Haml::Parser,
|
||||
:compiler_class => ::Haml::Compiler
|
||||
}
|
||||
|
||||
@valid_formats = [:html4, :html5, :xhtml]
|
||||
|
@ -160,6 +162,12 @@ module Haml
|
|||
# xhtml.
|
||||
attr_accessor :cdata
|
||||
|
||||
# The parser class to use. Defaults to Haml::Parser.
|
||||
attr_accessor :parser_class
|
||||
|
||||
# The compiler class to use. Defaults to Haml::Compiler.
|
||||
attr_accessor :compiler_class
|
||||
|
||||
def initialize(values = {}, &block)
|
||||
defaults.each {|k, v| instance_variable_set :"@#{k}", v}
|
||||
values.reject {|k, v| !defaults.has_key?(k) || v.nil?}.each {|k, v| send("#{k}=", v)}
|
||||
|
|
Loading…
Reference in New Issue