rails2_asset_pipeline 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +4 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +36 -0
- data/Rakefile +22 -0
- data/Readme.md +90 -0
- data/lib/rails2_asset_pipeline.rb +30 -0
- data/lib/rails2_asset_pipeline/tasks.rb +33 -0
- data/lib/rails2_asset_pipeline/version.rb +3 -0
- data/lib/rails2_asset_pipeline/view_helpers.rb +15 -0
- data/lib/tasks/rails2_asset_pipeline.rake +1 -0
- data/rails2_asset_pipeline.gemspec +13 -0
- data/spec/rails2_asset_pipeline/view_helpers_spec.rb +35 -0
- data/spec/rails2_asset_pipeline_spec.rb +54 -0
- data/spec/spec_helper.rb +13 -0
- metadata +81 -0
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rails2_asset_pipeline (0.1.0)
|
5
|
+
sprockets
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.3)
|
11
|
+
hike (1.2.1)
|
12
|
+
multi_json (1.3.5)
|
13
|
+
rack (1.4.1)
|
14
|
+
rake (0.9.2)
|
15
|
+
rspec (2.6.0)
|
16
|
+
rspec-core (~> 2.6.0)
|
17
|
+
rspec-expectations (~> 2.6.0)
|
18
|
+
rspec-mocks (~> 2.6.0)
|
19
|
+
rspec-core (2.6.4)
|
20
|
+
rspec-expectations (2.6.0)
|
21
|
+
diff-lcs (~> 1.1.2)
|
22
|
+
rspec-mocks (2.6.0)
|
23
|
+
sprockets (2.3.2)
|
24
|
+
hike (~> 1.2)
|
25
|
+
multi_json (~> 1.0)
|
26
|
+
rack (~> 1.0)
|
27
|
+
tilt (~> 1.1, != 1.3.0)
|
28
|
+
tilt (1.3.3)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
rails2_asset_pipeline!
|
35
|
+
rake
|
36
|
+
rspec (~> 2)
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
task :default do
|
4
|
+
sh "rspec spec/"
|
5
|
+
end
|
6
|
+
|
7
|
+
# extracted from https://github.com/grosser/project_template
|
8
|
+
rule /^version:bump:.*/ do |t|
|
9
|
+
sh "git status | grep 'nothing to commit'" # ensure we are not dirty
|
10
|
+
index = ['major', 'minor','patch'].index(t.name.split(':').last)
|
11
|
+
file = 'lib/rails2_asset_pipeline/version.rb'
|
12
|
+
|
13
|
+
version_file = File.read(file)
|
14
|
+
old_version, *version_parts = version_file.match(/(\d+)\.(\d+)\.(\d+)/).to_a
|
15
|
+
version_parts[index] = version_parts[index].to_i + 1
|
16
|
+
version_parts[2] = 0 if index < 2 # remove patch for minor
|
17
|
+
version_parts[1] = 0 if index < 1 # remove minor for major
|
18
|
+
new_version = version_parts * '.'
|
19
|
+
File.open(file,'w'){|f| f.write(version_file.sub(old_version, new_version)) }
|
20
|
+
|
21
|
+
sh "bundle && git add #{file} Gemfile.lock && git commit -m 'bump version to #{new_version}'"
|
22
|
+
end
|
data/Readme.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Rails 2 Asset pipeline
|
2
|
+
|
3
|
+
Familiar asset handling for those stuck on Rails 2.
|
4
|
+
|
5
|
+
- sprockets/coffee/sass etc goodness
|
6
|
+
- application.js?time for development
|
7
|
+
- application-MD5.js for production
|
8
|
+
- old asset versions can stay around during deploys
|
9
|
+
|
10
|
+
# Usage
|
11
|
+
|
12
|
+
```
|
13
|
+
rake assets:precompile
|
14
|
+
rake assets:clean
|
15
|
+
```
|
16
|
+
|
17
|
+
```Erb
|
18
|
+
<%= stylesheet_link_tag pipeline_path("application.css") %>
|
19
|
+
<%= javascript_include_tag pipeline_path("application.js") %>
|
20
|
+
```
|
21
|
+
|
22
|
+
|
23
|
+
# Install
|
24
|
+
|
25
|
+
gem install rails2_asset_pipeline
|
26
|
+
|
27
|
+
# config/environment.rb
|
28
|
+
config.gem "rails2_asset_pipeline"
|
29
|
+
|
30
|
+
# Rakefile
|
31
|
+
begin
|
32
|
+
require "rails2_asset_pipeline/tasks"
|
33
|
+
rescue LoadError
|
34
|
+
puts "rails2_asset_pipeline is not installed, you probably should run 'rake gems:install' or 'bundle install'."
|
35
|
+
end
|
36
|
+
|
37
|
+
## Initializer
|
38
|
+
Here you can do additional configuration of sprockets.
|
39
|
+
|
40
|
+
```Ruby
|
41
|
+
# config/initializers/rails2_asset_pipeline.rb
|
42
|
+
Rails2AssetPipeline.setup do |sprockets|
|
43
|
+
# ... additional config ...
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
## config.ru
|
48
|
+
Setup a config.ru so development has dynamic assets
|
49
|
+
|
50
|
+
```Ruby
|
51
|
+
# config.ru
|
52
|
+
# we need to protect against multiple includes of the Rails environment (trust me)
|
53
|
+
require './config/environment' if !defined?(Rails) || !Rails.initialized?
|
54
|
+
|
55
|
+
instance_exec(&Rails2AssetPipeline.config_ru)
|
56
|
+
|
57
|
+
map '/' do
|
58
|
+
use Rails::Rack::LogTailer unless Rails.env.test?
|
59
|
+
# use Rails::Rack::Debugger unless Rails.env.test?
|
60
|
+
use Rails::Rack::Static
|
61
|
+
run ActionController::Dispatcher.new
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
## View helpers
|
66
|
+
```
|
67
|
+
# app/helpers/application_helper.rb
|
68
|
+
module ApplicationHelper
|
69
|
+
include Rails2AssetPipeline::ViewHelpers
|
70
|
+
...
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
|
75
|
+
# Tasks
|
76
|
+
|
77
|
+
rake assets:precompile
|
78
|
+
rake assets:clean
|
79
|
+
|
80
|
+
## Todo
|
81
|
+
- read config from Rails 3 style config.assets
|
82
|
+
- `rake assets:clobber` to remove old assets
|
83
|
+
- asset helpers for inside css/scss
|
84
|
+
|
85
|
+
Author
|
86
|
+
======
|
87
|
+
[Michael Grosser](http://grosser.it)<br/>
|
88
|
+
michael@grosser.it<br/>
|
89
|
+
License: MIT<br/>
|
90
|
+
[](http://travis-ci.org/grosser/rails2_asset_pipeline)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rails2_asset_pipeline/version'
|
2
|
+
require 'sprockets'
|
3
|
+
|
4
|
+
module Rails2AssetPipeline
|
5
|
+
STATIC_ENVIRONMENTS = ["production", "staging"]
|
6
|
+
|
7
|
+
def self.env
|
8
|
+
@env || setup
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.setup
|
12
|
+
@env ||= Sprockets::Environment.new
|
13
|
+
@env.append_path 'app/assets/images'
|
14
|
+
@env.append_path 'app/assets/javascripts'
|
15
|
+
@env.append_path 'app/assets/stylesheets'
|
16
|
+
# TODO vendor + lib
|
17
|
+
yield @env if block_given?
|
18
|
+
@env
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.config_ru
|
22
|
+
lambda do
|
23
|
+
unless STATIC_ENVIRONMENTS.include?(Rails.env)
|
24
|
+
map '/assets' do
|
25
|
+
run Rails2AssetPipeline.env
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rake/sprocketstask'
|
2
|
+
|
3
|
+
namespace :assets do
|
4
|
+
load_tasks = lambda do
|
5
|
+
namespace :r2ap do
|
6
|
+
Rake::SprocketsTask.new do |t|
|
7
|
+
t.environment = Rails2AssetPipeline.env
|
8
|
+
t.output = "./public/assets"
|
9
|
+
t.assets = t.environment.paths.map{|p| Dir["#{p.sub(Rails.root.to_s,'')}/**/*"] }.flatten
|
10
|
+
t.keep = 2
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Compile all the assets"
|
16
|
+
task :precompile => :environment do
|
17
|
+
load_tasks.call
|
18
|
+
Rake::Task["r2ap:assets"].invoke
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Remove compiled assets"
|
22
|
+
task :clean => :environment do
|
23
|
+
load_tasks.call
|
24
|
+
Rake::Task["r2ap:clean"].invoke
|
25
|
+
end
|
26
|
+
|
27
|
+
# FIXME always just removes public/assets
|
28
|
+
#desc "Remove old assets"
|
29
|
+
#task :clobber => :environment do
|
30
|
+
# load_tasks.call
|
31
|
+
# Rake::Task["r2ap:clobber"].invoke
|
32
|
+
#end
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Rails2AssetPipeline
|
2
|
+
module ViewHelpers
|
3
|
+
def pipeline_path(asset)
|
4
|
+
data = Rails2AssetPipeline.env[asset]
|
5
|
+
return "/assets/NOT_FOUND" unless data
|
6
|
+
asset = "/assets/#{asset}"
|
7
|
+
|
8
|
+
if Rails2AssetPipeline::STATIC_ENVIRONMENTS.include?(Rails.env)
|
9
|
+
asset.sub(/(\.[\.a-z]+$)/, "-#{data.digest}\\1")
|
10
|
+
else
|
11
|
+
"#{asset}?#{data.mtime.to_i}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../rails2_asset_pipeline/tasks")
|
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
name = "rails2_asset_pipeline"
|
3
|
+
require "#{name}/version"
|
4
|
+
|
5
|
+
Gem::Specification.new name, Rails2AssetPipeline::VERSION do |s|
|
6
|
+
s.summary = "Familiar asset handling for those stuck on Rails 2"
|
7
|
+
s.authors = ["Michael Grosser"]
|
8
|
+
s.email = "michael@grosser.it"
|
9
|
+
s.homepage = "http://github.com/grosser/#{name}"
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.license = 'MIT'
|
12
|
+
s.add_runtime_dependency "sprockets"
|
13
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rails2AssetPipeline::ViewHelpers do
|
4
|
+
include Rails2AssetPipeline::ViewHelpers
|
5
|
+
|
6
|
+
describe "#pipeline_path" do
|
7
|
+
let(:env){ {} }
|
8
|
+
|
9
|
+
before do
|
10
|
+
Rails2AssetPipeline.stub(:env).and_return env
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns a path with query on development" do
|
14
|
+
Rails.env = "development"
|
15
|
+
env["xxx.js"] = mock(:mtime => Time.at(123456))
|
16
|
+
pipeline_path("xxx.js").should == "/assets/xxx.js?123456"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns a path with md5 on production" do
|
20
|
+
Rails.env = "production"
|
21
|
+
env["xxx.js"] = mock(:digest => "abc", )
|
22
|
+
pipeline_path("xxx.js").should == "/assets/xxx-abc.js"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns a path with md5 on production and complicated file" do
|
26
|
+
Rails.env = "production"
|
27
|
+
env["xxx.yy.js"] = mock(:digest => "abc", )
|
28
|
+
pipeline_path("xxx.yy.js").should == "/assets/xxx-abc.yy.js"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "silently fails with unfound assets" do
|
32
|
+
pipeline_path("xxx.js").should == "/assets/NOT_FOUND"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rails2AssetPipeline do
|
4
|
+
it "has a VERSION" do
|
5
|
+
Rails2AssetPipeline::VERSION.should =~ /^[\.\da-z]+$/
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ".env" do
|
9
|
+
before do
|
10
|
+
Rails2AssetPipeline.instance_variable_set :@env, nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sets itself" do
|
14
|
+
Rails2AssetPipeline.env.should_not == nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "stays the same" do
|
18
|
+
Rails2AssetPipeline.env.object_id.should == Rails2AssetPipeline.env.object_id
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".setup" do
|
23
|
+
it "yields the sprocket env" do
|
24
|
+
result = nil
|
25
|
+
Rails2AssetPipeline.setup{|x| result = x }
|
26
|
+
result.class.should == Sprockets::Environment
|
27
|
+
end
|
28
|
+
|
29
|
+
it "does not recreate the sprockets env" do
|
30
|
+
a,b = nil
|
31
|
+
Rails2AssetPipeline.setup{|x| a = x }
|
32
|
+
Rails2AssetPipeline.setup{|x| b = x }
|
33
|
+
a.object_id.should == b.object_id
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe ".config_ru" do
|
38
|
+
def map(*args)
|
39
|
+
@mapped = args
|
40
|
+
end
|
41
|
+
|
42
|
+
it "sets up a route for development" do
|
43
|
+
Rails.env = "development"
|
44
|
+
instance_exec(&Rails2AssetPipeline.config_ru)
|
45
|
+
@mapped.should == ["/assets"]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "does not set up a route for production" do
|
49
|
+
Rails.env = "production"
|
50
|
+
instance_exec(&Rails2AssetPipeline.config_ru)
|
51
|
+
@mapped.should == nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails2_asset_pipeline
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Grosser
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sprockets
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description:
|
31
|
+
email: michael@grosser.it
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- .travis.yml
|
37
|
+
- Gemfile
|
38
|
+
- Gemfile.lock
|
39
|
+
- Rakefile
|
40
|
+
- Readme.md
|
41
|
+
- lib/rails2_asset_pipeline.rb
|
42
|
+
- lib/rails2_asset_pipeline/tasks.rb
|
43
|
+
- lib/rails2_asset_pipeline/version.rb
|
44
|
+
- lib/rails2_asset_pipeline/view_helpers.rb
|
45
|
+
- lib/tasks/rails2_asset_pipeline.rake
|
46
|
+
- rails2_asset_pipeline.gemspec
|
47
|
+
- spec/rails2_asset_pipeline/view_helpers_spec.rb
|
48
|
+
- spec/rails2_asset_pipeline_spec.rb
|
49
|
+
- spec/spec_helper.rb
|
50
|
+
homepage: http://github.com/grosser/rails2_asset_pipeline
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
hash: -1786090662421693194
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
hash: -1786090662421693194
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.24
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Familiar asset handling for those stuck on Rails 2
|
81
|
+
test_files: []
|