mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Compile plain filter
This commit is contained in:
parent
4fff10c075
commit
1265fdb98a
4 changed files with 58 additions and 9 deletions
|
@ -1,4 +1,5 @@
|
|||
require 'hamlit/doctype_compiler'
|
||||
require 'hamlit/filter_compiler'
|
||||
require 'hamlit/tag_compiler'
|
||||
require 'hamlit/whitespace_handler'
|
||||
|
||||
|
@ -6,6 +7,7 @@ module Hamlit
|
|||
class Compiler
|
||||
def initialize(options = {})
|
||||
@doctype_compiler = DoctypeCompiler.new(options)
|
||||
@filter_compiler = FilterCompiler.new
|
||||
@tag_compiler = TagCompiler.new(options)
|
||||
@whitespace_handler = WhitespaceHandler.new
|
||||
end
|
||||
|
@ -24,6 +26,8 @@ module Hamlit
|
|||
compile_comment(node)
|
||||
when :doctype
|
||||
compile_doctype(node)
|
||||
when :filter
|
||||
compile_filter(node)
|
||||
when :tag
|
||||
compile_tag(node)
|
||||
when :plain
|
||||
|
@ -41,6 +45,10 @@ module Hamlit
|
|||
@doctype_compiler.compile(node)
|
||||
end
|
||||
|
||||
def compile_filter(node)
|
||||
@filter_compiler.compile(node)
|
||||
end
|
||||
|
||||
def compile_comment(node)
|
||||
if node.children.empty?
|
||||
return [:html, :comment, [:static, " #{node.value[:text]} "]]
|
||||
|
|
32
lib/hamlit/filter_compiler.rb
Normal file
32
lib/hamlit/filter_compiler.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require 'hamlit/filter_compiler/plain'
|
||||
|
||||
module Hamlit
|
||||
class FilterCompiler
|
||||
@registered = {}
|
||||
|
||||
class << self
|
||||
attr_reader :registered
|
||||
|
||||
private
|
||||
|
||||
def register(name, compiler)
|
||||
registered[name] = compiler.new
|
||||
end
|
||||
end
|
||||
|
||||
register :plain, Plain
|
||||
|
||||
def compile(node)
|
||||
find_compiler(node.value[:name]).compile(node)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_compiler(name)
|
||||
compiler = FilterCompiler.registered[name.to_sym]
|
||||
raise "FilterCompiler for '#{name}' was not found" unless compiler
|
||||
|
||||
compiler
|
||||
end
|
||||
end
|
||||
end
|
9
lib/hamlit/filter_compiler/plain.rb
Normal file
9
lib/hamlit/filter_compiler/plain.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
module Hamlit
|
||||
class FilterCompiler
|
||||
class Plain
|
||||
def compile(node)
|
||||
[:static, node.value[:text].rstrip + "\n"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -373,15 +373,15 @@ markup comments:
|
|||
# html: |-
|
||||
# hello

|
||||
# <p></p>
|
||||
# content in a 'plain' filter:
|
||||
# haml: |-
|
||||
# :plain
|
||||
# hello
|
||||
#
|
||||
# %p
|
||||
# html: |-
|
||||
# hello
|
||||
# <p></p>
|
||||
content in a 'plain' filter:
|
||||
haml: |-
|
||||
:plain
|
||||
hello
|
||||
|
||||
%p
|
||||
html: |-
|
||||
hello
|
||||
<p></p>
|
||||
# content in a 'css' filter (XHTML):
|
||||
# haml: |-
|
||||
# :css
|
||||
|
|
Loading…
Add table
Reference in a new issue