Skip to content

Commit 49668d1

Browse files
authored
Merge pull request #180 from derSascha/add-rails-6-support
Add rails 6.0+6.1 and sprockets 4 support
2 parents 10a8755 + 604f01e commit 49668d1

20 files changed

+156
-90
lines changed

.travis.yml

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,60 @@
11
language: ruby
22
rvm:
3-
- 2.2.9
4-
- 2.3.8
5-
- 2.4.9
6-
- 2.5.8
7-
- 2.6.6
8-
- 2.7.2
3+
- 2.5.9
4+
- 2.6.7
5+
- 2.7.3
6+
- 3.0.1
97
- ruby-head
10-
- jruby-9.1.17.0
11-
- jruby-9.2.14.0
8+
- jruby-9.2.17.0
129
- jruby-head
1310
gemfile:
14-
- gemfiles/Gemfile-4-2-stable
15-
- gemfiles/Gemfile-5-0-stable
16-
- gemfiles/Gemfile-5-1-stable
17-
- gemfiles/Gemfile-5-2-stable
11+
- gemfiles/Gemfile-5-1-sprockets-3
12+
- gemfiles/Gemfile-5-1-sprockets-4
13+
- gemfiles/Gemfile-5-2-sprockets-3
14+
- gemfiles/Gemfile-5-2-sprockets-4
15+
- gemfiles/Gemfile-6-0-sprockets-3
16+
- gemfiles/Gemfile-6-0-sprockets-4
17+
- gemfiles/Gemfile-6-1-sprockets-3
18+
- gemfiles/Gemfile-6-1-sprockets-4
1819
matrix:
1920
exclude:
20-
- rvm: 2.2.9
21-
gemfile: gemfiles/Gemfile-5-2-stable
22-
- rvm: jruby-9.1.17.0
23-
gemfile: gemfiles/Gemfile-4-2-stable
24-
- rvm: jruby-9.2.14.0
25-
gemfile: gemfiles/Gemfile-4-2-stable
21+
- rvm: 3.0.1
22+
gemfile: gemfiles/Gemfile-5-1-sprockets-4
23+
- rvm: 3.0.1
24+
gemfile: gemfiles/Gemfile-5-1-sprockets-3
25+
- rvm: 3.0.1
26+
gemfile: gemfiles/Gemfile-5-2-sprockets-4
27+
- rvm: 3.0.1
28+
gemfile: gemfiles/Gemfile-5-2-sprockets-3
29+
30+
- rvm: ruby-head
31+
gemfile: gemfiles/Gemfile-5-1-sprockets-4
32+
- rvm: ruby-head
33+
gemfile: gemfiles/Gemfile-5-1-sprockets-3
34+
- rvm: ruby-head
35+
gemfile: gemfiles/Gemfile-5-2-sprockets-4
36+
- rvm: ruby-head
37+
gemfile: gemfiles/Gemfile-5-2-sprockets-3
38+
- rvm: ruby-head
39+
gemfile: gemfiles/Gemfile-6-0-sprockets-4
40+
- rvm: ruby-head
41+
gemfile: gemfiles/Gemfile-6-0-sprockets-3
42+
43+
- rvm: jruby-head
44+
gemfile: gemfiles/Gemfile-5-1-sprockets-4
45+
- rvm: jruby-head
46+
gemfile: gemfiles/Gemfile-5-1-sprockets-3
47+
- rvm: jruby-head
48+
gemfile: gemfiles/Gemfile-5-2-sprockets-4
49+
- rvm: jruby-head
50+
gemfile: gemfiles/Gemfile-5-2-sprockets-3
51+
- rvm: jruby-head
52+
gemfile: gemfiles/Gemfile-6-0-sprockets-4
53+
- rvm: jruby-head
54+
gemfile: gemfiles/Gemfile-6-0-sprockets-3
55+
2656
allow_failures:
27-
- rvm: 2.5.8
28-
- rvm: 2.6.6
29-
- rvm: 2.7.2
30-
- rvm: 3.0.0
3157
- rvm: ruby-head
32-
- rvm: jruby-9.2.14.0
3358
- rvm: jruby-head
3459
notifications:
3560
email: false

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace(:spec) do
2727
config.eager_load = false
2828
config.logger = Logger.new('/dev/null')
2929
config.assets.enabled = true
30+
config.root = File.expand_path("../spec/fixtures", __FILE__)
3031
end.initialize!
3132

3233
Rake::Task['jasmine:ci'].invoke

config.ru

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class HamlCoffeeAssetsJasmineTest < Rails::Application
1414
config.assets.enabled = true
1515
config.assets.version = '1.0'
1616
config.secret_token = '9696be98e32a5f213730cb7ed6161c79'
17+
config.root = File.expand_path("../spec/fixtures", __FILE__)
1718
end
1819

1920
HamlCoffeeAssetsJasmineTest.initialize!

gemfiles/Gemfile-5-1-sprockets-3

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec path: '..'
4+
5+
gem 'rails', '~> 5.1.4'
6+
gem 'sprockets', '~> 3.7.2'
7+
8+
platform :ruby do
9+
gem 'therubyracer'
10+
gem 'redcarpet'
11+
end
12+
13+
platform :jruby do
14+
gem 'therubyrhino'
15+
gem 'kramdown'
16+
end

gemfiles/Gemfile-5-1-stable renamed to gemfiles/Gemfile-5-1-sprockets-4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
33
gemspec path: '..'
44

55
gem 'rails', '~> 5.1.4'
6+
gem 'sprockets', '~> 4.0'
67

78
platform :ruby do
89
gem 'therubyracer'

gemfiles/Gemfile-5-2-sprockets-3

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec path: '..'
4+
5+
gem 'rails', '~> 5.2.4'
6+
gem 'sprockets', '~> 3.7.2'
7+
8+
platform :ruby do
9+
gem 'therubyracer'
10+
gem 'redcarpet'
11+
end
12+
13+
platform :jruby do
14+
gem 'therubyrhino'
15+
gem 'kramdown'
16+
end

gemfiles/Gemfile-5-2-stable renamed to gemfiles/Gemfile-5-2-sprockets-4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
33
gemspec path: '..'
44

55
gem 'rails', '~> 5.2.4'
6+
gem 'sprockets', '~> 4.0'
67

78
platform :ruby do
89
gem 'therubyracer'

gemfiles/Gemfile-6-0-sprockets-3

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec path: '..'
4+
5+
gem 'rails', '~> 6.0.0'
6+
gem 'sprockets', '~> 3.7.2'
7+
8+
platform :ruby do
9+
gem 'therubyracer'
10+
gem 'redcarpet'
11+
end
12+
13+
platform :jruby do
14+
gem 'therubyrhino'
15+
gem 'kramdown'
16+
end

gemfiles/Gemfile-4-2-stable renamed to gemfiles/Gemfile-6-0-sprockets-4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ source 'https://rubygems.org'
22

33
gemspec path: '..'
44

5-
gem 'rails', '~> 4.2.2'
5+
gem 'rails', '~> 6.0.0'
6+
gem 'sprockets', '~> 4.0'
67

78
platform :ruby do
89
gem 'therubyracer'

gemfiles/Gemfile-6-1-sprockets-3

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec path: '..'
4+
5+
gem 'rails', '~> 6.1.0'
6+
gem 'sprockets', '~> 3.7.2'
7+
8+
platform :ruby do
9+
gem 'therubyracer'
10+
gem 'redcarpet'
11+
end
12+
13+
platform :jruby do
14+
gem 'therubyrhino'
15+
gem 'kramdown'
16+
end

gemfiles/Gemfile-5-0-stable renamed to gemfiles/Gemfile-6-1-sprockets-4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ source 'https://rubygems.org'
22

33
gemspec path: '..'
44

5-
gem 'rails', '~> 5.0.7'
5+
gem 'rails', '~> 6.1.0'
6+
gem 'sprockets', '~> 4.0'
67

78
platform :ruby do
89
gem 'therubyracer'

haml_coffee_assets.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Gem::Specification.new do |s|
1313

1414
s.required_ruby_version = '>= 2.2.4'
1515
s.required_rubygems_version = '>= 1.3.6'
16-
s.rubyforge_project = 'haml_coffee_assets'
1716

1817
s.files = Dir.glob('{app,lib,vendor}/**/*') + %w[LICENSE README.md]
1918

@@ -33,4 +32,5 @@ Gem::Specification.new do |s|
3332
s.add_development_dependency 'yard'
3433
s.add_development_dependency 'pry'
3534
s.add_development_dependency 'rb-readline'
35+
s.add_development_dependency 'puma'
3636
end

lib/haml_coffee_assets/action_view/template_handler.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module ActionView
33
class TemplateHandler
44
DEPENDENCY_PATTERN = /(?:window\.)?JST(?:\[["']([\w\/]+)["']\]|\.(\w+))/
55

6-
def self.call(template)
6+
def self.call(template, _body = nil)
77
new(template).render
88
end
99

@@ -80,7 +80,8 @@ def include_dependencies(compiled)
8080
partial_source(path),
8181
path,
8282
self.class,
83-
virtual_path: partial_path(path)
83+
virtual_path: partial_path(path),
84+
locals: []
8485
)
8586

8687
compiled << self.class.new(

lib/haml_coffee_assets/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def initialize
3838
self.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base'
3939
self.context = 'window.HAML.context'
4040
self.templates_path = 'app/assets/javascripts/templates'
41-
self.global_context_asset = 'templates/context'
41+
self.global_context_asset = 'templates/context.js'
4242
self.name_filter = lambda { |n|
4343
parts = n.sub(/^templates\//, '').split('/')
4444
parts.last.sub!(/^_/, '')

lib/haml_coffee_assets/rails/engine.rb

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,50 +33,6 @@ class Engine < ::Rails::Engine
3333
end
3434
end
3535

36-
if ::Rails.env == "development"
37-
# Monkey patch rails so it busts the server cache for templates
38-
# depending on the global_context_asset.
39-
#
40-
# Currently, the only way to force rails to recompile a server template is to
41-
# touch it. This is problematic because when the global_context_asset
42-
# changes we need to manually touch every template that uses the congtext
43-
# in some way.
44-
#
45-
# To ease development, make rails 'touch' and recompile hamlc templates
46-
# when the global context has changed.
47-
#
48-
# Do this ONLY in development.
49-
#
50-
# TODO: Don't monkey patch rails.
51-
module ::ActionView
52-
class Template
53-
def stale?
54-
return false unless ::Rails.env == "development"
55-
return false unless handler.respond_to?(:stale?)
56-
handler.stale?(updated_at)
57-
end
58-
59-
alias_method :old_render, :render
60-
61-
# by default, rails will only compile a template once
62-
# path render so it recompiles the template if 'stale'
63-
def render(view, locals, buffer=nil, &block)
64-
if @compiled and stale?
65-
now = Time.now
66-
File.utime(now, now, identifier) # touch file
67-
::Rails.logger.info "Busted cache for #{identifier} by touching it"
68-
69-
view = refresh(view)
70-
@source = view.source
71-
@compiled = false
72-
end
73-
old_render(view, locals, buffer, &block)
74-
end
75-
76-
end
77-
end
78-
end
79-
8036
config.assets.configure do |env|
8137
if env.respond_to?(:register_transformer)
8238
env.register_mime_type 'text/hamlc', extensions: ['.hamlc']
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//
2+
// Manifest file required by sprockets 4
3+
//
4+
//= link_tree ../images
5+
//= link_directory ../javascripts .js
6+
//= link_directory ../stylesheets .css

spec/haml_coffee_assets/action_view/template_handler_spec.rb

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ def new_template(body)
88
body,
99
"template",
1010
described_class,
11-
virtual_path: "path/to/_template"
11+
virtual_path: "path/to/_template",
12+
locals: []
1213
)
1314
end
1415

15-
let(:context) { Object.new }
16-
let(:locals) { Hash.new }
16+
let(:context) do
17+
if ActionView.gem_version >= Gem::Version.new('6')
18+
lookup_context = ActionView::LookupContext.new([])
19+
assigns = {}
20+
controller = nil
21+
ActionView::Base.with_empty_template_cache.new(lookup_context, assigns, controller)
22+
else
23+
Object.new
24+
end
25+
end
1726

1827
let(:global_context) do
1928
path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'support', 'hamlcoffee_baseline.js'))
@@ -25,17 +34,17 @@ def new_template(body)
2534
end
2635

2736
it "renders basic templates" do
28-
output = new_template("Foo").render(context, locals)
37+
output = new_template("Foo").render(context, {})
2938
expect(output).to eq "Foo"
3039
end
3140

3241
it "renders Haml" do
33-
output = new_template("%h1 Foo").render(context, locals)
42+
output = new_template("%h1 Foo").render(context, {})
3443
expect(output).to eq "<h1>Foo</h1>"
3544
end
3645

3746
it "renders CoffeeScript" do
38-
output = new_template("= @foo").render(context, foo: "Foo")
47+
output = new_template("= @foo").render(context, { foo: "Foo" })
3948
expect(output).to eq "Foo"
4049
end
4150

@@ -55,25 +64,25 @@ def stub_partial_source
5564

5665
it "renders partials with bracket notation" do
5766
template = new_template("!= window.JST['basic/partial'](foo: 'Foo')")
58-
output = template.render(context, foo: "Foo")
67+
output = template.render(context, { foo: "Foo" })
5968
expect(output).to eq "Foo"
6069
end
6170

6271
it "renders partials with dot notation" do
6372
template = new_template("!= window.JST.basic_partial_01(foo: 'Foo')")
64-
output = template.render(context, foo: "Foo")
73+
output = template.render(context, { foo: "Foo" })
6574
expect(output).to eq "Foo"
6675
end
6776

6877
it "doesn't require JST to be called on window" do
6978
template = new_template("!= JST['basic/partial'](foo: 'Foo')")
70-
output = template.render(context, foo: "Foo")
79+
output = template.render(context, { foo: "Foo" })
7180
expect(output).to eq "Foo"
7281
end
7382

7483
it "renders nested templates" do
7584
template = new_template("!= JST['nested/partial'](foo: 'Foo')")
76-
output = template.render(context, foo: "Foo")
85+
output = template.render(context, { foo: "Foo" })
7786
expect(output).to eq "Foo"
7887
end
7988

@@ -85,7 +94,7 @@ def stub_partial_source
8594
compiled = described_class.new(template).send(:compilation_string)
8695
expect(compiled.scan(/JST\['basic\/partial'\] =/).size).to eq 1
8796

88-
output = template.render(context, foo: "Foo")
97+
output = template.render(context, { foo: "Foo" })
8998
expect(output).to eq "Foo\nFoo"
9099
end
91100
end

0 commit comments

Comments
 (0)