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_dependency "tilt"
|
||||||
spec.add_development_dependency "benchmark-ips"
|
spec.add_development_dependency "benchmark-ips"
|
||||||
spec.add_development_dependency "bundler"
|
spec.add_development_dependency "bundler"
|
||||||
|
spec.add_development_dependency "coffee-script"
|
||||||
spec.add_development_dependency "erubis"
|
spec.add_development_dependency "erubis"
|
||||||
spec.add_development_dependency "faml"
|
spec.add_development_dependency "faml"
|
||||||
spec.add_development_dependency "haml"
|
spec.add_development_dependency "haml"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
require 'hamlit/concerns/included'
|
require 'hamlit/concerns/included'
|
||||||
require 'hamlit/concerns/registerable'
|
require 'hamlit/concerns/registerable'
|
||||||
|
require 'hamlit/filters/coffee'
|
||||||
require 'hamlit/filters/css'
|
require 'hamlit/filters/css'
|
||||||
require 'hamlit/filters/erb'
|
require 'hamlit/filters/erb'
|
||||||
require 'hamlit/filters/escaped'
|
require 'hamlit/filters/escaped'
|
||||||
|
@ -22,17 +23,19 @@ module Hamlit
|
||||||
|
|
||||||
define_options :format
|
define_options :format
|
||||||
|
|
||||||
register :css, Filters::Css
|
register :coffee, Filters::Coffee
|
||||||
register :erb, Filters::Erb
|
register :coffeescript, Filters::Coffee
|
||||||
register :escaped, Filters::Escaped
|
register :css, Filters::Css
|
||||||
register :javascript, Filters::Javascript
|
register :erb, Filters::Erb
|
||||||
register :less, Filters::Less
|
register :escaped, Filters::Escaped
|
||||||
register :markdown, Filters::Markdown
|
register :javascript, Filters::Javascript
|
||||||
register :plain, Filters::Plain
|
register :less, Filters::Less
|
||||||
register :preserve, Filters::Preserve
|
register :markdown, Filters::Markdown
|
||||||
register :ruby, Filters::Ruby
|
register :plain, Filters::Plain
|
||||||
register :sass, Filters::Sass
|
register :preserve, Filters::Preserve
|
||||||
register :scss, Filters::Scss
|
register :ruby, Filters::Ruby
|
||||||
|
register :sass, Filters::Sass
|
||||||
|
register :scss, Filters::Scss
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_haml_filter(name, lines)
|
def on_haml_filter(name, lines)
|
||||||
|
|
|
@ -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