rails2_asset_pipeline 0.1.2 → 0.1.3

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.2)
4
+ rails2_asset_pipeline (0.1.3)
5
5
  sprockets
6
6
 
7
7
  GEM
data/Readme.md CHANGED
@@ -6,15 +6,18 @@ 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
+ - converter for jammit asset.yml
9
10
  - no monkey-patching, everything is opt-in
10
11
 
12
+ [Example application](https://github.com/grosser/rails2_asset_pipeline_exmaple)
13
+
11
14
  # Usage
12
15
 
13
16
  ```
14
17
  rake assets:precompile
15
18
  rake assets:clean
16
- rake assets:remove_old
17
- rake assets:convert_jammit
19
+ rake assets:remove_old # Keeps current + 2 older versions in public/assets
20
+ rake assets:convert_jammit # reads config/assets.yml and converts packs into `app/assets/<type>/<pack>.js` with `//= require <dependency>`
18
21
  ```
19
22
 
20
23
  ```Erb
@@ -30,14 +33,7 @@ rake assets:convert_jammit
30
33
  # config/environment.rb
31
34
  config.gem "rails2_asset_pipeline"
32
35
 
33
- # Rakefile
34
- begin
35
- require "rails2_asset_pipeline/tasks"
36
- rescue LoadError
37
- puts "rails2_asset_pipeline is not installed, you probably should run 'rake gems:install' or 'bundle install'."
38
- end
39
-
40
- ## Initializer
36
+ ### Initializer
41
37
  Here you can do additional configuration of sprockets.
42
38
 
43
39
  ```Ruby
@@ -47,7 +43,16 @@ Rails2AssetPipeline.setup do |sprockets|
47
43
  end
48
44
  ```
49
45
 
50
- ## config.ru
46
+ ### Tasks
47
+
48
+ # Rakefile
49
+ begin
50
+ require "rails2_asset_pipeline/tasks"
51
+ rescue LoadError
52
+ puts "rails2_asset_pipeline is not installed, you probably should run 'rake gems:install' or 'bundle install'."
53
+ end
54
+
55
+ ### Dynamic assets for development
51
56
  Setup a config.ru so development has dynamic assets
52
57
 
53
58
  ```Ruby
@@ -65,7 +70,7 @@ map '/' do
65
70
  end
66
71
  ```
67
72
 
68
- ## View helpers
73
+ ### View helpers
69
74
  ```
70
75
  # app/helpers/application_helper.rb
71
76
  require 'rails2_asset_pipeline/view_helpers'
@@ -76,14 +81,7 @@ end
76
81
  ```
77
82
 
78
83
 
79
- # Tasks
80
-
81
- rake assets:precompile
82
- rake assets:clean
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>`
85
-
86
- ## Todo
84
+ # Todo
87
85
  - read config from Rails 3 style config.assets
88
86
  - asset image helpers for inside css/scss
89
87
 
@@ -0,0 +1,71 @@
1
+ require 'yaml'
2
+
3
+ module Rails2AssetPipeline
4
+ module JammitConverter
5
+ def self.convert
6
+ move_to_app
7
+ cleanup_scss
8
+ convert_javascript_packs
9
+ convert_stylesheet_packs
10
+ end
11
+
12
+ private
13
+
14
+ def self.jammit
15
+ @jammit ||= YAML.load_file("config/assets.yml")
16
+ end
17
+
18
+ def self.cleanup_scss
19
+ stylesheets = Dir["app/assets/stylesheets/**/*"].select{|f| File.file?(f) and f =~ /\.s?css$/ }
20
+
21
+ # cleanup import of .scss
22
+ stylesheets.each do |file|
23
+ content = File.read(file)
24
+ rex = /^(@import ['"].*).scss(['"]);/
25
+ if content =~ rex
26
+ File.open(file, 'w'){|f| f.write content.gsub(rex, "\\1.css\\2;") }
27
+ end
28
+ end
29
+
30
+ # cleanup .scss -> .css.scss
31
+ stylesheets.each do |file|
32
+ sh "mv #{file} #{file.sub(".scss", ".css.scss")}" if file =~ /\.scss$/ and not file =~ /\.css\.scss$/
33
+ end
34
+ end
35
+
36
+ def self.convert_javascript_packs
37
+ # convert javascript packs
38
+ jammit["javascripts"].each do |pack, assets|
39
+ File.open("app/assets/javascripts/#{pack}.js", "w") do |f|
40
+ assets.each do |file|
41
+ fuzzy = /[\/*]+$/
42
+ f.puts "//= #{file =~ fuzzy ? "require_tree" : "require"} #{file.sub("public/javascripts/", "").sub(".js","").sub(fuzzy,"")}"
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ def self.convert_stylesheet_packs
49
+ jammit["stylesheets"].each do |pack, assets|
50
+ File.open("app/assets/stylesheets/#{pack}.css", "w") do |f|
51
+ f.puts "/*"
52
+ assets.each do |file|
53
+ f.puts " *= require #{file.sub("public/stylesheets/", "").sub(/.s?css$/,"")}"
54
+ end
55
+ f.puts " */"
56
+ end
57
+ end
58
+ end
59
+
60
+ # TODO only move .js/.css/.scss, no images
61
+ def self.move_to_app
62
+ sh "mkdir app/assets" unless File.exist?("app/assets")
63
+ folders = ["javascripts", "stylesheets"]
64
+ folders.each do |folder|
65
+ target = "app/assets/#{folder}"
66
+ raise "Remove #{target} before proceeding, I'm not merging!" if File.exist?(target)
67
+ end
68
+ folders.each{|f| sh "mv public/#{f} app/assets/#{f}" }
69
+ end
70
+ end
71
+ end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'rake/sprocketstask'
2
3
 
3
4
  namespace :assets do
@@ -32,30 +33,7 @@ namespace :assets do
32
33
 
33
34
  desc "converts project from jammit based assets.yml"
34
35
  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
36
+ require 'rails2_asset_pipeline/jammit_converter'
37
+ Rails2AssetPipeline::JammitConverter.convert
60
38
  end
61
39
  end
@@ -1,3 +1,3 @@
1
1
  module Rails2AssetPipeline
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -2,6 +2,7 @@ javascripts:
2
2
  pack:
3
3
  - public/javascripts/a.js
4
4
  - public/javascripts/b.js
5
+ - public/javascripts/c/**/*
5
6
 
6
7
  stylesheets:
7
8
  pack:
@@ -67,18 +67,43 @@ describe "Rails2AssetPipeline Tasks" do
67
67
  write "public/stylesheets/b.css", "A"
68
68
  end
69
69
 
70
+ it "fails when folders already exist" do
71
+ run "mkdir -p app/assets/javascripts"
72
+ expect{
73
+ puts run "rake assets:convert_jammit"
74
+ }.to raise_error
75
+ end
76
+
70
77
  it "moves and combines javascripts" do
71
78
  run "rake assets:convert_jammit"
72
79
  run("ls app/assets").should == "javascripts\nstylesheets\n"
73
80
  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"
81
+ run("cat app/assets/javascripts/pack.js").should == "//= require a\n//= require b\n//= require_tree c\n"
75
82
  end
76
83
 
77
84
  it "moves and combines stylesheets" do
78
85
  run "rake assets:convert_jammit"
79
86
  run("ls app/assets").should == "javascripts\nstylesheets\n"
80
87
  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"
88
+ run("cat app/assets/stylesheets/pack.css").should == "/*\n *= require a\n *= require b\n */\n"
89
+ end
90
+
91
+ it "renames .scss to .css.scss" do
92
+ write "public/stylesheets/c.scss", "C"
93
+ run "rake assets:convert_jammit"
94
+ run("ls app/assets/stylesheets").should include("\nc.css.scss\n")
95
+ end
96
+
97
+ it "does not renames .css.scss to .css.css.scss" do
98
+ write "public/stylesheets/c.css.scss", "C"
99
+ run "rake assets:convert_jammit"
100
+ run("ls app/assets/stylesheets").should include("\nc.css.scss\n")
101
+ end
102
+
103
+ it "fixes broken inputs" do
104
+ write "public/stylesheets/c.css.scss", "a{}\n@import \"../global/_tables.scss\";\na{}"
105
+ run "rake assets:convert_jammit"
106
+ run("cat app/assets/stylesheets/c.css.scss").should == "a{}\n@import \"../global/_tables.css\";\na{}"
82
107
  end
83
108
  end
84
109
  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.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-22 00:00:00.000000000 Z
12
+ date: 2012-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets
@@ -39,6 +39,7 @@ files:
39
39
  - Rakefile
40
40
  - Readme.md
41
41
  - lib/rails2_asset_pipeline.rb
42
+ - lib/rails2_asset_pipeline/jammit_converter.rb
42
43
  - lib/rails2_asset_pipeline/tasks.rb
43
44
  - lib/rails2_asset_pipeline/version.rb
44
45
  - lib/rails2_asset_pipeline/view_helpers.rb
@@ -66,7 +67,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
67
  version: '0'
67
68
  segments:
68
69
  - 0
69
- hash: 2199684529747267224
70
+ hash: 2378466707075981159
70
71
  required_rubygems_version: !ruby/object:Gem::Requirement
71
72
  none: false
72
73
  requirements:
@@ -75,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
76
  version: '0'
76
77
  segments:
77
78
  - 0
78
- hash: 2199684529747267224
79
+ hash: 2378466707075981159
79
80
  requirements: []
80
81
  rubyforge_project:
81
82
  rubygems_version: 1.8.24