Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haml compatibility issues #25

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
haml_assets
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.4.0
1 change: 0 additions & 1 deletion .rvmrc

This file was deleted.

11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
## On master

## v0.3.1 (unreleased)

* Loosen requirement of tilt gem
* Upgrade json gem to latest current version patch
* Add method `haml_options` to engine to pass options to template engine or default to `Haml::Template.options`
* Update rails to latest patch level

## v0.3.0 (2016-12-09)

* Supports Rails 4

## v0.2.2 (2013-06-02)

* Allow partials to be read from app/views
Expand Down
131 changes: 65 additions & 66 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,102 +1,100 @@
PATH
remote: .
specs:
haml_assets (0.3.0)
haml_assets (0.3.1)
haml
tilt (~> 1.4.1)
tilt (>= 1.4, < 3)

GEM
remote: http://rubygems.org/
specs:
actionmailer (4.2.7.1)
actionpack (= 4.2.7.1)
actionview (= 4.2.7.1)
activejob (= 4.2.7.1)
actionmailer (4.2.10)
actionpack (= 4.2.10)
actionview (= 4.2.10)
activejob (= 4.2.10)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.7.1)
actionview (= 4.2.7.1)
activesupport (= 4.2.7.1)
actionpack (4.2.10)
actionview (= 4.2.10)
activesupport (= 4.2.10)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.7.1)
activesupport (= 4.2.7.1)
actionview (4.2.10)
activesupport (= 4.2.10)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
activejob (4.2.7.1)
activesupport (= 4.2.7.1)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (4.2.10)
activesupport (= 4.2.10)
globalid (>= 0.3.0)
activemodel (4.2.7.1)
activesupport (= 4.2.7.1)
activemodel (4.2.10)
activesupport (= 4.2.10)
builder (~> 3.1)
activerecord (4.2.7.1)
activemodel (= 4.2.7.1)
activesupport (= 4.2.7.1)
activerecord (4.2.10)
activemodel (= 4.2.10)
activesupport (= 4.2.10)
arel (~> 6.0)
activesupport (4.2.7.1)
activesupport (4.2.10)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
builder (3.2.2)
concurrent-ruby (1.0.2)
arel (6.0.4)
builder (3.2.3)
concurrent-ruby (1.0.5)
crass (1.0.4)
diff-lcs (1.2.5)
ejs (1.0.0)
erubis (2.7.0)
globalid (0.3.7)
activesupport (>= 4.1.0)
haml (4.0.7)
globalid (0.4.1)
activesupport (>= 4.2.0)
haml (5.0.2)
temple (>= 0.8.0)
tilt
i18n (0.7.0)
json (1.8.3)
loofah (2.0.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.6.4)
mime-types (>= 1.16, < 4)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.9.0)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
pkg-config (1.1.7)
mail (2.7.0)
mini_mime (>= 0.1.1)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.11.3)
nokogiri (1.8.2)
mini_portile2 (~> 2.3.0)
power_assert (0.2.6)
rack (1.6.4)
rack (1.6.9)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.7.1)
actionmailer (= 4.2.7.1)
actionpack (= 4.2.7.1)
actionview (= 4.2.7.1)
activejob (= 4.2.7.1)
activemodel (= 4.2.7.1)
activerecord (= 4.2.7.1)
activesupport (= 4.2.7.1)
rails (4.2.10)
actionmailer (= 4.2.10)
actionpack (= 4.2.10)
actionview (= 4.2.10)
activejob (= 4.2.10)
activemodel (= 4.2.10)
activerecord (= 4.2.10)
activesupport (= 4.2.10)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.7.1)
railties (= 4.2.10)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.7)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-dom-testing (1.0.9)
activesupport (>= 4.2.0, < 5.0)
nokogiri (~> 1.6)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (4.2.7.1)
actionpack (= 4.2.7.1)
activesupport (= 4.2.7.1)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (4.2.10)
actionpack (= 4.2.10)
activesupport (= 4.2.10)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (11.2.2)
rake (12.3.1)
rspec (2.13.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
Expand All @@ -112,19 +110,20 @@ GEM
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
rspec-mocks (~> 2.13.0)
sprockets (3.7.0)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.0)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
temple (0.8.0)
test-unit (3.1.5)
power_assert
thor (0.19.1)
thread_safe (0.3.5)
thor (0.20.0)
thread_safe (0.3.6)
tilt (1.4.1)
tzinfo (1.2.2)
tzinfo (1.2.5)
thread_safe (~> 0.1)

PLATFORMS
Expand All @@ -139,4 +138,4 @@ DEPENDENCIES
test-unit (~> 3.1.5)

BUNDLED WITH
1.13.6
1.16.1
2 changes: 1 addition & 1 deletion haml_assets.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]

s.add_runtime_dependency "haml"
s.add_runtime_dependency "tilt", "~> 1.4.1"
s.add_runtime_dependency "tilt", "< 3", ">= 1.4"

s.add_development_dependency 'rails', '~> 4.0'
s.add_development_dependency 'rspec', '~> 2.13.0'
Expand Down
14 changes: 14 additions & 0 deletions lib/haml_assets/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,19 @@ def look_in_app_views
def look_in_app_views=(look)
@look_in_app_views = look
end

def haml_options
return @haml_options if @haml_options

if defined?(Haml::Template)
@haml_options = Haml::Template.options
end

@haml_options
end

def haml_options=(opts)
@haml_options = opts
end
end
end
7 changes: 7 additions & 0 deletions lib/haml_assets/haml_sprockets_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ def protect_against_forgery?
end
end

def prepare
if HamlAssets::Config.haml_options
@options = @options.merge(HamlAssets::Config.haml_options)
end
super
end

def evaluate(scope, locals, &block)
scope = view_context(scope)
super
Expand Down
2 changes: 1 addition & 1 deletion lib/haml_assets/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module HamlAssets
VERSION = "0.3.0"
VERSION = "0.3.1"
end
4 changes: 3 additions & 1 deletion spec/rails_app/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
config.cache_classes = true

# Configure static asset server for tests with Cache-Control for performance
config.serve_static_assets = true
config.serve_static_files = true
config.static_cache_control = "public, max-age=3600"

# Log error messages when you accidentally call methods on nil
Expand All @@ -34,4 +34,6 @@

# Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
config.assets.allow_debugging = true

config.eager_load = false
end
89 changes: 76 additions & 13 deletions spec/render_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,88 @@
context "quoted attributes" do
after { Haml::Template.options[:attr_wrapper] = "'" }

it "handles data attributes" do
template = HamlAssets::HamlSprocketsEngine.new(path) { %Q(%div{data:{bind:'attr: { "data-something": someValue }'}}) }
template.send(:evaluate, Object.new, {}).strip.should eq(%Q(<div data-bind='attr: { "data-something": someValue }'></div>))
context 'with Haml::Template.options escape_attrs and escape_html being false' do
before do
Haml::Template.options[:escape_attrs] = false
Haml::Template.options[:escape_html] = false
end

it "handles data attributes" do
template = HamlAssets::HamlSprocketsEngine.new(path) { %Q(%div{data:{bind:'attr: { "data-something": someValue }'}}) }
template.send(:evaluate, Object.new, {}).strip.should eq(%Q(<div data-bind='attr: { "data-something": someValue }'></div>))
end

it "allows nested quotes with ()" do
template = HamlAssets::HamlSprocketsEngine.new(path) { %Q|%div(ng-model-options='{updateOn: "blur"}')| }
template.send(:evaluate, Object.new, {}).strip.should eq(%Q(<div ng-model-options='{updateOn: "blur"}'></div>))
end

it "allows nested quotes with {}" do
Haml::Template.options[:attr_wrapper] = '"'
template = HamlAssets::HamlSprocketsEngine.new(path) { %Q|%div{"ng-model-options" => "{updateOn: 'blur'}"}| }
template.send(:evaluate, Object.new, {}).strip.should eq(%Q(<div ng-model-options="{updateOn: 'blur'}"></div>))
end

it "allows nested quote with {} ('\"\"')" do
template = HamlAssets::HamlSprocketsEngine.new(path) { %Q|%div{"ng-model-options" => '{updateOn: "blur"}'}| }
template.send(:evaluate, Object.new, {}).strip.should eq(%Q(<div ng-model-options='{updateOn: "blur"}'></div>))
end
end

it "allows nested quotes with ()" do
template = HamlAssets::HamlSprocketsEngine.new(path) { %Q|%div(ng-model-options='{updateOn: "blur"}')| }
template.send(:evaluate, Object.new, {}).strip.should eq(%Q(<div ng-model-options='{updateOn: "blur"}'></div>))
context 'with Ham::Template.options escape_attrs and escape_html being true' do
before do
Haml::Template.options[:escape_attrs] = true
Haml::Template.options[:escape_html] = true
end

it "handles data attributes" do
template = HamlAssets::HamlSprocketsEngine.new(path) { %Q(%div{data:{bind:'attr: { "data-something": someValue }'}}) }
template.send(:evaluate, Object.new, {}).strip.should eq(%Q(<div data-bind='attr: { &quot;data-something&quot;: someValue }'></div>))
end

it "allows nested quotes with ()" do
template = HamlAssets::HamlSprocketsEngine.new(path) { %Q|%div(ng-model-options='{updateOn: "blur"}')| }
template.send(:evaluate, Object.new, {}).strip.should eq(%Q(<div ng-model-options='{updateOn: &quot;blur&quot;}'></div>))
end

it "allows nested quotes with {}" do
Haml::Template.options[:attr_wrapper] = '"'
template = HamlAssets::HamlSprocketsEngine.new(path) { %Q|%div{"ng-model-options" => "{updateOn: 'blur'}"}| }
template.send(:evaluate, Object.new, {}).strip.should eq(%Q(<div ng-model-options=\"{updateOn: &#39;blur&#39;}\"></div>))
end

it "allows nested quote with {} ('\"\"')" do
template = HamlAssets::HamlSprocketsEngine.new(path) { %Q|%div{"ng-model-options" => '{updateOn: "blur"}'}| }
template.send(:evaluate, Object.new, {}).strip.should eq(%Q(<div ng-model-options='{updateOn: &quot;blur&quot;}'></div>))
end
end

it "allows nested quotes with {}" do
Haml::Template.options[:attr_wrapper] = '"'
template = HamlAssets::HamlSprocketsEngine.new(path) { %Q|%div{"ng-model-options" => "{updateOn: 'blur'}"}| }
template.send(:evaluate, Object.new, {}).strip.should eq(%Q(<div ng-model-options="{updateOn: 'blur'}"></div>))
context 'with HamlAssets::Config.haml_options escape_attrs and escape_html being true' do
before do
HamlAssets::Config.haml_options = {
escape_attrs: true,
escape_html: true
}
end

it "escapes interpolated code" do
template = HamlAssets::HamlSprocketsEngine.new(path) { %Q(%div{data:{bind:'attr: { "data-something": someValue }'}}) }
template.send(:evaluate, Object.new, {}).strip.should eq(%Q(<div data-bind='attr: { &quot;data-something&quot;: someValue }'></div>))
end
end

it "allows nested quote with {} ('\"\"')" do
template = HamlAssets::HamlSprocketsEngine.new(path) { %Q|%div{"ng-model-options" => '{updateOn: "blur"}'}| }
template.send(:evaluate, Object.new, {}).strip.should eq(%Q(<div ng-model-options='{updateOn: "blur"}'></div>))
context 'with HamlAssets::Config.haml_options escape_attrs and escape_html being false' do
before do
HamlAssets::Config.haml_options = {
escape_attrs: false,
escape_html: false
}
end

it "does not escapes interpolated code" do
template = HamlAssets::HamlSprocketsEngine.new(path) { %Q(%div{data:{bind:'attr: { "data-something": someValue }'}}) }
template.send(:evaluate, Object.new, {}).strip.should eq(%Q(<div data-bind='attr: { "data-something": someValue }'></div>))
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
require 'rails_app/config/environment'
require 'haml_assets'
require 'ejs'
require 'rspec/rails'
require 'rspec/rails'