mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Convert Haml::Parser to temple filter
This commit is contained in:
parent
dd8ed93545
commit
743ba540c0
4 changed files with 10 additions and 18 deletions
|
@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|||
|
||||
spec.required_ruby_version = '>= 2.0.0'
|
||||
|
||||
spec.add_dependency 'temple'
|
||||
spec.add_dependency 'temple', '>= 0.7.6'
|
||||
spec.add_dependency 'tilt'
|
||||
|
||||
spec.add_development_dependency 'rails', '>= 4.0.0'
|
||||
|
|
|
@ -88,14 +88,18 @@ module Haml
|
|||
ID_KEY = 'id'.freeze
|
||||
CLASS_KEY = 'class'.freeze
|
||||
|
||||
def initialize(template, options)
|
||||
@options = options
|
||||
def initialize(options)
|
||||
@options = options
|
||||
@options = Options.new(options) unless options.is_a?(Options)
|
||||
|
||||
# Record the indent levels of "if" statements to validate the subsequent
|
||||
# elsif and else statements are indented at the appropriate level.
|
||||
@script_level_stack = []
|
||||
@template_index = 0
|
||||
@template_tabs = 0
|
||||
end
|
||||
|
||||
def call(template)
|
||||
match = template.rstrip.scan(/(([ \t]+)?(.*?))(?:\Z|\r\n|\r|\n)/m)
|
||||
# discard the last match which is always blank
|
||||
match.pop
|
||||
|
@ -104,9 +108,7 @@ module Haml
|
|||
end
|
||||
# Append special end-of-document marker
|
||||
@template << Line.new(nil, '-#', '-#', @template.size, self, true)
|
||||
end
|
||||
|
||||
def parse
|
||||
@root = @parent = ParseNode.new(:root)
|
||||
@flat = false
|
||||
@filter_buffer = nil
|
||||
|
|
|
@ -1,16 +1,6 @@
|
|||
require 'temple'
|
||||
|
||||
module Haml
|
||||
class ParserFilter
|
||||
def initialize(options = {})
|
||||
@options = Options.new(options)
|
||||
end
|
||||
|
||||
def call(template)
|
||||
@options.parser_class.new(template, @options).parse
|
||||
end
|
||||
end
|
||||
|
||||
class CompilerFilter
|
||||
def initialize(options = {})
|
||||
@options = Options.new(options)
|
||||
|
@ -47,7 +37,7 @@ module Haml
|
|||
:trace => false
|
||||
)
|
||||
|
||||
use ParserFilter
|
||||
use :Parser, -> { options[:parser_class] }
|
||||
use CompilerFilter
|
||||
|
||||
def compile(template)
|
||||
|
|
|
@ -165,8 +165,8 @@ module Haml
|
|||
|
||||
def parse(haml, options = nil)
|
||||
options ||= Options.new
|
||||
parser = Parser.new(haml, options)
|
||||
parser.parse
|
||||
parser = Parser.new(options)
|
||||
parser.call(haml)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue