Create autoclose option

This commit is contained in:
Takashi Kokubun 2015-10-11 21:50:46 +09:00
parent c8e73a385b
commit c67d79e14d
3 changed files with 19 additions and 6 deletions

View File

@ -11,6 +11,9 @@ module Hamlit
attr_quote: "'",
escape_html: true,
pretty: false,
autoclose: %w(area base basefont br col command embed frame
hr img input isindex keygen link menuitem meta
param source track wbr),
)
use Parser

View File

@ -2,12 +2,19 @@ require 'haml'
module Hamlit
class Parser
OPTION_MAPS = {
autoclose: :autoclose,
}.freeze
def initialize(options = {})
@options = options
@options = Haml::Options.defaults.dup
OPTION_MAPS.each do |temple, haml|
@options[haml] = options[temple]
end
end
def call(template)
Haml::Parser.new(template, Haml::Options.defaults).parse
Haml::Parser.new(template, @options).parse
end
end
end

View File

@ -1,7 +1,8 @@
module Hamlit
class TagCompiler
def initialize(options = {})
@quote = options[:attr_quote].inspect.freeze
@quote = options[:attr_quote].inspect.freeze
@format = options[:format]
end
def compile(node, &block)
@ -24,10 +25,12 @@ module Hamlit
end
def compile_contents(node, &block)
unless node.children.empty?
return yield(node)
case
when !node.children.empty?
yield(node)
else
[:dynamic, node.value[:value]]
end
[:dynamic, node.value[:value]]
end
end
end