Add coffee filter
This commit is contained in:
parent
42e085b1c4
commit
2ff1a8bc3b
|
@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|||
spec.add_dependency "tilt"
|
||||
spec.add_development_dependency "benchmark-ips"
|
||||
spec.add_development_dependency "bundler"
|
||||
spec.add_development_dependency "coffee-script"
|
||||
spec.add_development_dependency "erubis"
|
||||
spec.add_development_dependency "faml"
|
||||
spec.add_development_dependency "haml"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'hamlit/concerns/included'
|
||||
require 'hamlit/concerns/registerable'
|
||||
require 'hamlit/filters/coffee'
|
||||
require 'hamlit/filters/css'
|
||||
require 'hamlit/filters/erb'
|
||||
require 'hamlit/filters/escaped'
|
||||
|
@ -22,6 +23,8 @@ module Hamlit
|
|||
|
||||
define_options :format
|
||||
|
||||
register :coffee, Filters::Coffee
|
||||
register :coffeescript, Filters::Coffee
|
||||
register :css, Filters::Css
|
||||
register :erb, Filters::Erb
|
||||
register :escaped, Filters::Escaped
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
require 'hamlit/filters/tilt'
|
||||
|
||||
module Hamlit
|
||||
module Filters
|
||||
class Coffee < Filters::Tilt
|
||||
def compile(lines)
|
||||
ast = [:html, :tag, 'script', [:html, :attrs]]
|
||||
compile_with_tilt('coffee', lines.join("\n"), ast)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,41 @@
|
|||
describe Hamlit::Filters::Coffee do
|
||||
describe '#compile' do
|
||||
it 'renders coffee filter' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
:coffee
|
||||
foo = ->
|
||||
alert('hello')
|
||||
HAML
|
||||
<script>
|
||||
(function() {
|
||||
var foo;
|
||||
|
||||
foo = function() {
|
||||
return alert('hello');
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
</script>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'renders coffeescript filter' do
|
||||
assert_render(<<-HAML, <<-HTML)
|
||||
:coffee
|
||||
foo = ->
|
||||
alert('hello')
|
||||
HAML
|
||||
<script>
|
||||
(function() {
|
||||
var foo;
|
||||
|
||||
foo = function() {
|
||||
return alert('hello');
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
</script>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue