From 00341d2ac2bb227e21c2d0b419118abc01d239b3 Mon Sep 17 00:00:00 2001 From: Kohei Suzuki Date: Wed, 18 Mar 2015 20:53:57 +0900 Subject: [PATCH] Support coffee filter via tilt --- fast_haml.gemspec | 1 + lib/fast_haml/filter_compilers.rb | 1 + lib/fast_haml/filter_compilers/coffee.rb | 14 +++++++++++++ spec/render/filters/coffee_spec.rb | 25 ++++++++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 lib/fast_haml/filter_compilers/coffee.rb create mode 100644 spec/render/filters/coffee_spec.rb diff --git a/fast_haml.gemspec b/fast_haml.gemspec index 266cae0..0c28c93 100644 --- a/fast_haml.gemspec +++ b/fast_haml.gemspec @@ -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" diff --git a/lib/fast_haml/filter_compilers.rb b/lib/fast_haml/filter_compilers.rb index 5ad5613..64da5f0 100644 --- a/lib/fast_haml/filter_compilers.rb +++ b/lib/fast_haml/filter_compilers.rb @@ -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' diff --git a/lib/fast_haml/filter_compilers/coffee.rb b/lib/fast_haml/filter_compilers/coffee.rb new file mode 100644 index 0000000..d9b271a --- /dev/null +++ b/lib/fast_haml/filter_compilers/coffee.rb @@ -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 diff --git a/spec/render/filters/coffee_spec.rb b/spec/render/filters/coffee_spec.rb new file mode 100644 index 0000000..31670f2 --- /dev/null +++ b/spec/render/filters/coffee_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +RSpec.describe 'CoffeeScript filter renderiong', type: :render do + it 'renders CoffeeScript filter' do + html = render_string(< x * x + square(3) +HAML + expect(html).to include('