Add erb filter
This commit is contained in:
parent
1000f20504
commit
42e085b1c4
|
@ -1,6 +1,7 @@
|
|||
require 'hamlit/concerns/included'
|
||||
require 'hamlit/concerns/registerable'
|
||||
require 'hamlit/filters/css'
|
||||
require 'hamlit/filters/erb'
|
||||
require 'hamlit/filters/escaped'
|
||||
require 'hamlit/filters/javascript'
|
||||
require 'hamlit/filters/less'
|
||||
|
@ -22,6 +23,7 @@ module Hamlit
|
|||
define_options :format
|
||||
|
||||
register :css, Filters::Css
|
||||
register :erb, Filters::Erb
|
||||
register :escaped, Filters::Escaped
|
||||
register :javascript, Filters::Javascript
|
||||
register :less, Filters::Less
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
require 'hamlit/filters/tilt'
|
||||
|
||||
module Hamlit
|
||||
module Filters
|
||||
class Erb < Filters::Tilt
|
||||
def compile(lines)
|
||||
compile_with_tilt('erb', lines.join("\n"), [], indent_width: 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -22,7 +22,8 @@ module Hamlit
|
|||
include Parsers::Text
|
||||
include Parsers::Whitespace
|
||||
|
||||
SKIP_NEWLINE_EXPS = %i[newline code multi].freeze
|
||||
SKIP_NEWLINE_EXPS = %i[newline code multi].freeze
|
||||
SKIP_NEWLINE_FILTERS = %w[ruby markdown erb].freeze
|
||||
|
||||
define_options :format
|
||||
|
||||
|
@ -111,9 +112,12 @@ module Hamlit
|
|||
def skip_newline?(ast)
|
||||
SKIP_NEWLINE_EXPS.include?(ast.first) ||
|
||||
(ast[0..1] == [:haml, :doctype]) ||
|
||||
(ast[0..2] == [:haml, :filter, 'ruby']) ||
|
||||
(ast[0..2] == [:haml, :filter, 'markdown']) ||
|
||||
newline_skip_filter?(ast) ||
|
||||
@outer_removal.include?(@current_indent)
|
||||
end
|
||||
|
||||
def newline_skip_filter?(ast)
|
||||
ast[0..1] == [:haml, :filter] && SKIP_NEWLINE_FILTERS.include?(ast[2])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
describe Hamlit::Filters::Erb do
|
||||
describe '#compile' do
|
||||
it 'renders erb filter' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
:erb
|
||||
<% if true %>
|
||||
ok
|
||||
<% else %>
|
||||
ng
|
||||
<% end %>
|
||||
HAML
|
||||
ok
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue