Skip to content

Commit 7ab9f51

Browse files
committed
upgrade to sprockets 3
1 parent deb3058 commit 7ab9f51

File tree

7 files changed

+60
-16
lines changed

7 files changed

+60
-16
lines changed

README.md

+33
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,36 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
3737
3. Commit your changes (`git commit -am 'Add some feature'`)
3838
4. Push to the branch (`git push origin my-new-feature`)
3939
5. Create a new Pull Request
40+
41+
## Critical changes v1.0.0
42+
43+
Install sprockets-rails to version 3.0.0 and newer
44+
45+
If you have previously installed a old version of gem, then you must uninstall this version with e.g.
46+
47+
$ gem uninstall sprockets-rails
48+
49+
and install needed version
50+
51+
$ gem install sprockets-rails -v 3.0.0
52+
53+
Check sprockets v3 [critical changes](https://github.com/rails/sprockets-rails#changes-from-rails-3x)
54+
55+
Replace old gem angular-rails-templates by newer
56+
57+
$ gem 'angular-rails4-templates', '~> 0.4.1'
58+
59+
And read [install instructions](https://github.com/gaslight/angular-rails4-templates)
60+
61+
Change all templates extensions
62+
For example `.html.slim` to `.ngslim`
63+
64+
```
65+
$ cd project/directory
66+
$ find -L . -type f -name "*.html.slim" -print0 | while IFS= read -r -d '' FNAME; do mv -- "$FNAME" "${FNAME%.html.slim}.ngslim"; done
67+
```
68+
69+
Exclude `.ngslim` from precompile. Add to `application.rb` config
70+
```
71+
config.spa_rails.manifest_extensions << '.ngslim'
72+
```

lib/generators/spa_rails_generator.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ def add_routes
2525
end
2626

2727
def add_configs
28+
configs = [
29+
"config.angular_templates.inside_paths << Rails.root.join('frontend')",
30+
"config.spa_rails.manifest_extensions << '.ngslim'"
31+
]
32+
2833
environment do
29-
"config.angular_templates.inside_paths << Rails.root.join('frontend')"
34+
configs.join("\n ")
3035
end
3136
end
3237

@@ -60,7 +65,7 @@ def add_prod_config
6065
end
6166

6267
def add_dependencies
63-
gem 'angular-rails-templates', github: 'sars/angular-rails-templates'
68+
gem 'angular-rails4-templates', '~> 0.4.1'
6469

6570
log :gemfile, "rails-assets gems"
6671

lib/spa_rails/engine.rb

+13-8
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@
22

33
module SpaRails
44
class Engine < ::Rails::Engine
5-
initializer 'spa-rails', group: :all do |app|
6-
Slim::Engine.set_options(attr_list_delims: {'(' => ')', '[' => ']'})
7-
app.assets.register_engine('.slimpage', Slim::Template)
8-
end
5+
config.spa_rails = ActiveSupport::OrderedOptions.new
6+
config.spa_rails.manifest_extensions = %w(.js .css .htm .html)
97

108
config.assets.paths << find_root('.').join("frontend")
119

12-
config.assets.precompile << lambda do |filename, path|
13-
path =~ /frontend/ && !%w(.js .css .htm).include?(File.extname(filename))
14-
end
15-
1610
config.assets.precompile.push(/(?:\/|\\|\A)manifests(?:\/|\\)[^\/]+\.(css|js)$/)
1711

1812
config.before_configuration do |app|
1913
config.ng_annotate.paths = [app.root.to_s]
2014
end
15+
16+
config.after_initialize do |app|
17+
Slim::Engine.set_options(attr_list_delims: {'(' => ')', '[' => ']'})
18+
app.assets.register_engine('.slimpage', Slim::Template)
19+
20+
if config.spa_rails.manifest_extensions.present?
21+
config.assets.precompile << lambda do |filename, path|
22+
path =~ /frontend/ && !config.spa_rails.manifest_extensions.include?(File.extname(filename))
23+
end
24+
end
25+
end
2126
end
2227
end

lib/spa_rails/routes.rb

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ def frontend_page(page_name)
44
Rails.application.assets.dup.instance_eval do
55
@context_class.instance_eval do
66
config = Rails.application.config.assets
7-
self.debug_assets = config.debug
87
self.digest_assets = config.digest
98
end
109

lib/spa_rails/task.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ def define
55
desc "Precompile all pages with .slimpage ext"
66
task :precompile_pages => :environment do
77
with_logger do
8-
paths = index.each_logical_path(/\.htm/).to_a
8+
filter = lambda do |filename, path|
9+
File.extname(path) == '.slimpage'
10+
end
911

10-
paths.each do |path|
11-
if asset = index.find_asset(path)
12+
manifest.find(filter) do |asset|
13+
if filter.call(asset.logical_path, asset.filename)
1214
target = File.join(File.expand_path(output), asset.logical_path)
1315

1416
logger.info "Writing #{target}"

lib/spa_rails/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module SpaRails
2-
VERSION = "0.1.1"
2+
VERSION = "1.0.0"
33
end

spa_rails.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
2929
spec.add_dependency "execjs", "~> 2.5.2"
3030
spec.add_dependency "uglifier", "~> 2.7.1"
3131
spec.add_dependency "ngannotate-rails", "~> 1.0.0"
32-
spec.add_dependency "sprockets-rails", "~> 2.3.1"
32+
spec.add_dependency "sprockets-rails", "~> 3.0.0"
3333
end

0 commit comments

Comments
 (0)