mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Normalize format
This commit is contained in:
parent
604616fad5
commit
a12d814cc8
4 changed files with 26 additions and 11 deletions
16
lib/hamlit/concerns/format_normalizable.rb
Normal file
16
lib/hamlit/concerns/format_normalizable.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
module Hamlit
|
||||
module Concerns
|
||||
module FormatNormalizable
|
||||
def normalize_format(format)
|
||||
return :html unless format
|
||||
|
||||
case format
|
||||
when :html4, :html5
|
||||
:html
|
||||
else
|
||||
format
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -23,7 +23,7 @@ module Hamlit
|
|||
use ScriptCompiler
|
||||
use TextCompiler
|
||||
use DynamicFormatter
|
||||
use HTML
|
||||
html :Fast
|
||||
filter :Escapable
|
||||
filter :ControlFlow
|
||||
filter :MultiFlattener
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
require 'temple/html/fast'
|
||||
require 'hamlit/filter'
|
||||
require 'hamlit/concerns/format_normalizable'
|
||||
|
||||
module Hamlit
|
||||
class HTML < Temple::HTML::Fast
|
||||
include Concerns::FormatNormalizable
|
||||
|
||||
def initialize(opts = {})
|
||||
super rewrite_format(opts)
|
||||
end
|
||||
|
@ -11,14 +13,9 @@ module Hamlit
|
|||
|
||||
# Temple's warning is noisy.
|
||||
def rewrite_format(options)
|
||||
options = options.dup
|
||||
|
||||
case options[:format]
|
||||
when :html4, :html5
|
||||
options[:format] = :html
|
||||
end
|
||||
|
||||
options
|
||||
options.merge(
|
||||
format: normalize_format(options[:format]),
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,6 +2,7 @@ require 'strscan'
|
|||
require 'temple'
|
||||
require 'hamlit/concerns/balanceable'
|
||||
require 'hamlit/concerns/escapable'
|
||||
require 'hamlit/concerns/format_normalizable'
|
||||
require 'hamlit/concerns/indentable'
|
||||
require 'hamlit/concerns/line_reader'
|
||||
|
||||
|
@ -9,6 +10,7 @@ module Hamlit
|
|||
class Parser < Temple::Parser
|
||||
include Concerns::Balanceable
|
||||
include Concerns::Escapable
|
||||
include Concerns::FormatNormalizable
|
||||
include Concerns::Indentable
|
||||
include Concerns::LineReader
|
||||
|
||||
|
@ -75,7 +77,7 @@ module Hamlit
|
|||
def parse_doctype(scanner)
|
||||
raise SyntaxError unless scanner.scan(/!!!/)
|
||||
|
||||
[:html, :doctype, 'html']
|
||||
[:html, :doctype, normalize_format(options[:format]).to_s]
|
||||
end
|
||||
|
||||
def parse_tag(scanner)
|
||||
|
|
Loading…
Add table
Reference in a new issue