1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Split out doctype compiler

This commit is contained in:
Takashi Kokubun 2015-03-23 01:43:47 +09:00
parent 7156d23fc3
commit 7f3188e38c
3 changed files with 22 additions and 7 deletions

View file

@ -0,0 +1,17 @@
require 'hamlit/concerns/format_normalizable'
require 'hamlit/filter'
module Hamlit
class DoctypeCompiler < Hamlit::Filter
include Concerns::FormatNormalizable
def on_haml_doctype(format, type)
case type
when 'XML'
return [:static, "<?xml version='1.0' encoding='utf-8' ?>"]
end
[:html, :doctype, normalize_format(format).to_s]
end
end
end

View file

@ -1,6 +1,7 @@
require 'temple'
require 'hamlit/attribute_compiler'
require 'hamlit/dynamic_formatter'
require 'hamlit/doctype_compiler'
require 'hamlit/filter_compiler'
require 'hamlit/filter_formatter'
require 'hamlit/html'
@ -16,6 +17,7 @@ module Hamlit
use MultilinePreprocessor
use Parser
use DoctypeCompiler
use AttributeCompiler
use NewAttributeCompier
use FilterFormatter

View file

@ -2,7 +2,6 @@ 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'
@ -10,7 +9,6 @@ module Hamlit
class Parser < Temple::Parser
include Concerns::Balanceable
include Concerns::Escapable
include Concerns::FormatNormalizable
include Concerns::Indentable
include Concerns::LineReader
@ -77,14 +75,12 @@ module Hamlit
def parse_doctype(scanner)
raise SyntaxError unless scanner.scan(/!!!/)
type = nil
if scanner.scan(/ +/) && scanner.rest?
case scanner.rest.strip
when 'XML'
return [:static, "<?xml version='1.0' encoding='utf-8' ?>"]
end
type = scanner.rest.strip
end
[:html, :doctype, normalize_format(options[:format]).to_s]
[:haml, :doctype, options[:format], type]
end
def parse_tag(scanner)