mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Merge DoctypeCompiler into Compiler
This commit is contained in:
parent
894fd5a21d
commit
2f7857c03b
4 changed files with 41 additions and 41 deletions
|
@ -1,8 +1,10 @@
|
|||
require 'hamlit/compilers/doctype'
|
||||
require 'hamlit/compilers/preserve'
|
||||
require 'hamlit/filter'
|
||||
|
||||
module Hamlit
|
||||
class Compiler < Hamlit::Filter
|
||||
include Compilers::Doctype
|
||||
include Compilers::Preserve
|
||||
end
|
||||
end
|
||||
|
|
39
lib/hamlit/compilers/doctype.rb
Normal file
39
lib/hamlit/compilers/doctype.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
module Hamlit
|
||||
module Compilers
|
||||
module Doctype
|
||||
def on_haml_doctype(format, type)
|
||||
if type == 'XML'
|
||||
return xml_doctype_tag(format)
|
||||
elsif type
|
||||
return doctype_tag(type)
|
||||
end
|
||||
|
||||
case format
|
||||
when :html4
|
||||
doctype_tag(:transitional)
|
||||
when :html5
|
||||
doctype_tag(:html)
|
||||
when :xhtml
|
||||
doctype_tag(:transitional)
|
||||
else
|
||||
doctype_tag(format)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def xml_doctype_tag(format)
|
||||
case format
|
||||
when :html4, :html5
|
||||
[:newline]
|
||||
else
|
||||
[:multi, [:static, "<?xml version='1.0' encoding='utf-8' ?>"], [:static, "\n"]]
|
||||
end
|
||||
end
|
||||
|
||||
def doctype_tag(type)
|
||||
[:multi, [:html, :doctype, type.to_s], [:static, "\n"]]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,39 +0,0 @@
|
|||
require 'hamlit/filter'
|
||||
|
||||
module Hamlit
|
||||
class DoctypeCompiler < Hamlit::Filter
|
||||
def on_haml_doctype(format, type)
|
||||
if type == 'XML'
|
||||
return xml_doctype_tag(format)
|
||||
elsif type
|
||||
return doctype_tag(type)
|
||||
end
|
||||
|
||||
case format
|
||||
when :html4
|
||||
doctype_tag(:transitional)
|
||||
when :html5
|
||||
doctype_tag(:html)
|
||||
when :xhtml
|
||||
doctype_tag(:transitional)
|
||||
else
|
||||
doctype_tag(format)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def xml_doctype_tag(format)
|
||||
case format
|
||||
when :html4, :html5
|
||||
[:newline]
|
||||
else
|
||||
[:multi, [:static, "<?xml version='1.0' encoding='utf-8' ?>"], [:static, "\n"]]
|
||||
end
|
||||
end
|
||||
|
||||
def doctype_tag(type)
|
||||
[:multi, [:html, :doctype, type.to_s], [:static, "\n"]]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,7 +3,6 @@ require 'hamlit/attribute_compiler'
|
|||
require 'hamlit/attribute_sorter'
|
||||
require 'hamlit/compiler'
|
||||
require 'hamlit/dynamic_formatter'
|
||||
require 'hamlit/doctype_compiler'
|
||||
require 'hamlit/filter_compiler'
|
||||
require 'hamlit/filter_formatter'
|
||||
require 'hamlit/html/pretty'
|
||||
|
@ -26,7 +25,6 @@ module Hamlit
|
|||
use Multiline
|
||||
use Parser
|
||||
use Compiler
|
||||
use DoctypeCompiler
|
||||
use AttributeCompiler
|
||||
use NewAttributeCompier
|
||||
use AttributeSorter
|
||||
|
|
Loading…
Add table
Reference in a new issue