Skip to content

Commit

Permalink
Support coffee filter via tilt
Browse files Browse the repository at this point in the history
  • Loading branch information
eagletmt committed Mar 18, 2015
1 parent aa67f07 commit 00341d2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions fast_haml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "appraisal"
spec.add_development_dependency "benchmark-ips"
spec.add_development_dependency "bundler"
spec.add_development_dependency "coffee-script"
spec.add_development_dependency "coveralls"
spec.add_development_dependency "haml"
spec.add_development_dependency "rake"
Expand Down
1 change: 1 addition & 0 deletions lib/fast_haml/filter_compilers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def self.find(name)
end

require 'fast_haml/filter_compilers/cdata'
require 'fast_haml/filter_compilers/coffee'
require 'fast_haml/filter_compilers/css'
require 'fast_haml/filter_compilers/escaped'
require 'fast_haml/filter_compilers/javascript'
Expand Down
14 changes: 14 additions & 0 deletions lib/fast_haml/filter_compilers/coffee.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'fast_haml/filter_compilers/tilt_base'

module FastHaml
module FilterCompilers
class Coffee < TiltBase
def compile(texts)
temple = compile_with_tilt('coffee', texts)
[:haml, :tag, 'script', false, [:html, :attrs], [:html, :js, temple]]
end
end

register(:coffee, Coffee)
end
end
25 changes: 25 additions & 0 deletions spec/render/filters/coffee_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'spec_helper'

RSpec.describe 'CoffeeScript filter renderiong', type: :render do
it 'renders CoffeeScript filter' do
html = render_string(<<HAML)
:coffee
square = (x) -> x * x
square(3)
HAML
expect(html).to include('<script>')
expect(html).to include('square = function(x)')
expect(html).to include('square(3)')
end

it 'parses string interpolation' do
html = render_string(<<'HAML')
:coffee
square = (x) -> x * x
square(#{1 + 2})
HAML
expect(html).to include('<script>')
expect(html).to include('square = function(x)')
expect(html).to include('square(3)')
end
end

0 comments on commit 00341d2

Please sign in to comment.