rails2_asset_pipeline 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails2_asset_pipeline (0.1.1)
4
+ rails2_asset_pipeline (0.1.2)
5
5
  sprockets
6
6
 
7
7
  GEM
data/Readme.md CHANGED
@@ -6,12 +6,15 @@ Familiar asset handling for those stuck on Rails 2.
6
6
  - application.js?time for development
7
7
  - application-MD5.js for production
8
8
  - old asset versions can stay around during deploys
9
+ - no monkey-patching, everything is opt-in
9
10
 
10
11
  # Usage
11
12
 
12
13
  ```
13
14
  rake assets:precompile
14
15
  rake assets:clean
16
+ rake assets:remove_old
17
+ rake assets:convert_jammit
15
18
  ```
16
19
 
17
20
  ```Erb
@@ -78,6 +81,7 @@ end
78
81
  rake assets:precompile
79
82
  rake assets:clean
80
83
  rake assets:remove_old # Keeps current + 2 older versions in public/assets
84
+ rake assets:convert_jammit # reads config/assets.yml and converts packs into `app/assets/<type>/<pack>.js` with `//= require <dependency>`
81
85
 
82
86
  ## Todo
83
87
  - read config from Rails 3 style config.assets
@@ -29,4 +29,33 @@ namespace :assets do
29
29
  load_tasks.call
30
30
  Rake::Task["r2ap:clean"].invoke
31
31
  end
32
+
33
+ desc "converts project from jammit based assets.yml"
34
+ task :convert_jammit do
35
+ require 'yaml'
36
+
37
+ sh "mkdir app/assets" unless File.exist?("app/assets")
38
+ sh "mv public/javascripts app/assets/javascripts"
39
+ sh "mv public/stylesheets app/assets/stylesheets"
40
+
41
+ jammit = YAML.load_file("config/assets.yml")
42
+
43
+ jammit["javascripts"].each do |pack, assets|
44
+ File.open("app/assets/javascripts/#{pack}.js", "w") do |f|
45
+ assets.each do |file|
46
+ f.puts "//= require #{file.sub("public/javascripts", "").sub(".js","")}"
47
+ end
48
+ end
49
+ end
50
+
51
+ jammit["stylesheets"].each do |pack, assets|
52
+ File.open("app/assets/stylesheets/#{pack}.css", "w") do |f|
53
+ f.puts "/*"
54
+ assets.each do |file|
55
+ f.puts "//= require #{file.sub("public/stylesheets", "").sub(".css","")}"
56
+ end
57
+ f.puts " */"
58
+ end
59
+ end
60
+ end
32
61
  end
@@ -1,3 +1,3 @@
1
1
  module Rails2AssetPipeline
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -0,0 +1,9 @@
1
+ javascripts:
2
+ pack:
3
+ - public/javascripts/a.js
4
+ - public/javascripts/b.js
5
+
6
+ stylesheets:
7
+ pack:
8
+ - public/stylesheets/a.css
9
+ - public/stylesheets/b.css
@@ -8,11 +8,16 @@ describe "Rails2AssetPipeline Tasks" do
8
8
  end
9
9
 
10
10
  def write(file, content)
11
+ folder = File.dirname(file)
12
+ run "mkdir -p #{folder}" unless File.exist?(folder)
11
13
  File.open(file, 'w'){|f| f.write content }
12
14
  end
13
15
 
14
16
  def cleanup
15
17
  run "rm -rf public/assets"
18
+ run "rm -rf public/javascripts"
19
+ run "rm -rf public/stylesheets"
20
+ run "rm -rf app/assets"
16
21
  write "app/assets/javascripts/application.js", "alert(1)"
17
22
  end
18
23
 
@@ -30,7 +35,7 @@ describe "Rails2AssetPipeline Tasks" do
30
35
  describe "assets:precompile" do
31
36
  it "compiles" do
32
37
  run "rake assets:precompile"
33
- run("ls public/assets").should == "application-84582092b2aab64d132618a3d4ac2288.js\nmanifest.json\n"
38
+ run("ls public/assets").should == "application-ceff92e831a69f6e164737670664e886.js\nmanifest.json\n"
34
39
  end
35
40
  end
36
41
 
@@ -52,4 +57,28 @@ describe "Rails2AssetPipeline Tasks" do
52
57
  run("ls public/assets").scan(/application-/).size.should == 3
53
58
  end
54
59
  end
60
+
61
+ describe "assets:convert_jammit" do
62
+ before do
63
+ run "rm -rf app/assets"
64
+ write "public/javascripts/a.js", "A"
65
+ write "public/javascripts/b.js", "B"
66
+ write "public/stylesheets/a.css", "A"
67
+ write "public/stylesheets/b.css", "A"
68
+ end
69
+
70
+ it "moves and combines javascripts" do
71
+ run "rake assets:convert_jammit"
72
+ run("ls app/assets").should == "javascripts\nstylesheets\n"
73
+ run("ls app/assets/javascripts").should == "a.js\nb.js\npack.js\n"
74
+ run("cat app/assets/javascripts/pack.js").should == "//= require /a\n//= require /b\n"
75
+ end
76
+
77
+ it "moves and combines stylesheets" do
78
+ run "rake assets:convert_jammit"
79
+ run("ls app/assets").should == "javascripts\nstylesheets\n"
80
+ run("ls app/assets/stylesheets").should == "a.css\nb.css\npack.css\n"
81
+ run("cat app/assets/stylesheets/pack.css").should == "/*\n//= require /a\n//= require /b\n */\n"
82
+ end
83
+ end
55
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails2_asset_pipeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -46,6 +46,7 @@ files:
46
46
  - rails2_asset_pipeline.gemspec
47
47
  - spec/fake_rails/Rakefile
48
48
  - spec/fake_rails/app/assets/javascripts/application.js
49
+ - spec/fake_rails/config/assets.yml
49
50
  - spec/rails2_asset_pipeline/tasks_spec.rb
50
51
  - spec/rails2_asset_pipeline/view_helpers_spec.rb
51
52
  - spec/rails2_asset_pipeline_spec.rb
@@ -65,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
66
  version: '0'
66
67
  segments:
67
68
  - 0
68
- hash: -2252524658053579579
69
+ hash: 2199684529747267224
69
70
  required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  none: false
71
72
  requirements:
@@ -74,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  version: '0'
75
76
  segments:
76
77
  - 0
77
- hash: -2252524658053579579
78
+ hash: 2199684529747267224
78
79
  requirements: []
79
80
  rubyforge_project:
80
81
  rubygems_version: 1.8.24