rack-pipeline 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rack-pipeline/base.rb +16 -21
- data/lib/rack-pipeline/compiling.rb +17 -1
- data/lib/rack-pipeline/compiling/coffee-script.rb +13 -0
- data/lib/rack-pipeline/compressing.rb +18 -1
- data/lib/rack-pipeline/compressing/uglifier.rb +13 -0
- data/lib/rack-pipeline/processing.rb +4 -9
- data/lib/rack-pipeline/version.rb +1 -1
- data/rack-pipeline.gemspec +6 -0
- data/test/assets/javascripts/coffee.coffee +1 -0
- data/test/rack-pipeline_base_test.rb +11 -1
- metadata +35 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbe84807caa12bb5e61db1e0265cf6738773dfe8
|
4
|
+
data.tar.gz: 2b32c7ca07cc0a78ca28d2dc26ee64513ee13cc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85882ed222c507c7b341cdb7d4d35cf98f738761356f217d3772bd43b308d6b853c9862ee574a4f530f963168978dfc974895659e19b23cd046fcc070e4e1547
|
7
|
+
data.tar.gz: bd1791e0b871da0f89779b36336cb5c2a1f70c176d563de0bbdd54676d1f8c20815cccedaaaec4d25363951cefda73706d2c437b02471fb0bde838bab25f800e
|
data/lib/rack-pipeline/base.rb
CHANGED
@@ -17,7 +17,7 @@ module RackPipeline
|
|
17
17
|
|
18
18
|
def assets_for(pipes, type, opts = {})
|
19
19
|
Array(pipes).inject([]) do |all,pipe|
|
20
|
-
all += Array(combine
|
20
|
+
all += Array(settings[:combine] ? "#{pipe}.#{type}" : assets[type][pipe].keys)
|
21
21
|
end.compact.uniq
|
22
22
|
end
|
23
23
|
|
@@ -87,9 +87,9 @@ module RackPipeline
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def prepare_pipe(path_info)
|
90
|
-
file = path_info.
|
90
|
+
file = path_info.start_with?('/') ? path_info[1..-1] : path_info
|
91
91
|
type = static_type(file) or return nil
|
92
|
-
unless ready_file =
|
92
|
+
unless ready_file = prepare_file(file, type)
|
93
93
|
pipename = File.basename(file, '.*').to_sym
|
94
94
|
if assets[type] && assets[type][pipename]
|
95
95
|
ready_file = combine(assets[type][pipename], File.basename(file))
|
@@ -100,30 +100,25 @@ module RackPipeline
|
|
100
100
|
raise MustRepopulate
|
101
101
|
end
|
102
102
|
|
103
|
-
def
|
104
|
-
result = nil
|
103
|
+
def prepare_file(source, type)
|
105
104
|
assets[type].each do |pipe,files|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
113
|
-
break if result
|
105
|
+
case files[source]
|
106
|
+
when :raw
|
107
|
+
return source
|
108
|
+
when :source
|
109
|
+
return compile(source, File.basename(source, '.*') + ".#{type}")
|
110
|
+
end
|
114
111
|
end
|
115
|
-
|
112
|
+
nil
|
116
113
|
end
|
117
114
|
|
118
115
|
def file_kind(file)
|
119
116
|
static_type(file) ? :raw : :source
|
120
117
|
end
|
121
118
|
|
122
|
-
def
|
123
|
-
|
124
|
-
|
125
|
-
all[file] = file_kind(file)
|
126
|
-
end
|
119
|
+
def glob_files(dirs)
|
120
|
+
Dir.glob(dirs).sort.each_with_object({}) do |file,all|
|
121
|
+
all[file] = file_kind(file)
|
127
122
|
end
|
128
123
|
end
|
129
124
|
|
@@ -133,8 +128,8 @@ module RackPipeline
|
|
133
128
|
STATIC_TYPES.each do |extname,type|
|
134
129
|
pipes = settings[type]
|
135
130
|
assets[type] = {}
|
136
|
-
pipes.each do |pipe,
|
137
|
-
assets[type][pipe] =
|
131
|
+
pipes.each do |pipe, dirs|
|
132
|
+
assets[type][pipe] = glob_files(dirs)
|
138
133
|
end
|
139
134
|
end
|
140
135
|
end
|
@@ -1,7 +1,23 @@
|
|
1
1
|
module RackPipeline
|
2
2
|
module Compiling
|
3
3
|
def self.process(source, target)
|
4
|
-
|
4
|
+
ext = File.extname source
|
5
|
+
if compiler = compilers[ext]
|
6
|
+
require compiler[1]
|
7
|
+
Compiling.const_get(compiler[0]).process(source, target)
|
8
|
+
else
|
9
|
+
fail LoadError, "no compiler for #{source} => #{target}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.register(ext, klass, feature)
|
14
|
+
compilers[ext] = [klass, feature]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.compilers
|
18
|
+
@compilers ||= {}
|
5
19
|
end
|
6
20
|
end
|
7
21
|
end
|
22
|
+
|
23
|
+
RackPipeline::Compiling.register '.coffee', 'CoffeeScript', 'rack-pipeline/compiling/coffee-script'
|
@@ -1,7 +1,24 @@
|
|
1
1
|
module RackPipeline
|
2
2
|
module Compressing
|
3
3
|
def self.process(source, target)
|
4
|
-
|
4
|
+
ext = File.extname source
|
5
|
+
if compressor = compressors[ext]
|
6
|
+
require compressor[1]
|
7
|
+
Compressing.const_get(compressor[0]).process(source, target)
|
8
|
+
else
|
9
|
+
warn "no compressor found for #{source}"
|
10
|
+
source
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.register(ext, klass, feature)
|
15
|
+
compressors[ext] = [klass, feature]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.compressors
|
19
|
+
@compressors ||= {}
|
5
20
|
end
|
6
21
|
end
|
7
22
|
end
|
23
|
+
|
24
|
+
RackPipeline::Compressing.register '.js', 'Uglifier', 'rack-pipeline/compressing/uglifier'
|
@@ -2,14 +2,10 @@ require 'fileutils'
|
|
2
2
|
|
3
3
|
module RackPipeline
|
4
4
|
module Processing
|
5
|
-
def combine?
|
6
|
-
settings[:combine]
|
7
|
-
end
|
8
|
-
|
9
5
|
def combine(sources, target)
|
10
6
|
cache_target(sources, target) do |target_path|
|
11
7
|
body = sources.inject('') do |all,(source,kind)|
|
12
|
-
all << File.read(
|
8
|
+
all << "/* #{source} */\n\n" + File.read(prepare_file(source, static_type(target))).encode('utf-8') + "\n\n"
|
13
9
|
end
|
14
10
|
File.write(target_path, body)
|
15
11
|
target_path
|
@@ -17,16 +13,15 @@ module RackPipeline
|
|
17
13
|
end
|
18
14
|
|
19
15
|
def compress(source, target)
|
20
|
-
return source unless settings[:compress]
|
16
|
+
return source unless settings[:compress]
|
21
17
|
cache_target(source, target) do |target_path|
|
22
|
-
|
18
|
+
Compressing.process(source, target_path)
|
23
19
|
end
|
24
20
|
end
|
25
21
|
|
26
22
|
def compile(source, target)
|
27
|
-
fail LoadError, "no compiler for #{source} => #{target}" unless defined?(Compiler)
|
28
23
|
cache_target(source, target) do |target_path|
|
29
|
-
|
24
|
+
Compiling.process(source, target_path)
|
30
25
|
end
|
31
26
|
end
|
32
27
|
end
|
data/rack-pipeline.gemspec
CHANGED
@@ -22,4 +22,10 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'minitest'
|
23
23
|
spec.add_development_dependency 'rack-test'
|
24
24
|
spec.add_development_dependency 'awesome_print'
|
25
|
+
|
26
|
+
# compiling
|
27
|
+
spec.add_development_dependency 'coffee-script'
|
28
|
+
|
29
|
+
# compressing
|
30
|
+
spec.add_development_dependency 'uglifier'
|
25
31
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
a = (x) -> x * x
|
@@ -4,7 +4,12 @@ require 'rack-pipeline/base'
|
|
4
4
|
|
5
5
|
describe RackPipeline::Base do
|
6
6
|
SETTINGS_1 = {}
|
7
|
-
SETTINGS_2 = {
|
7
|
+
SETTINGS_2 = {
|
8
|
+
:compress => true,
|
9
|
+
:js => {
|
10
|
+
:coffee => 'assets/**/*.coffee',
|
11
|
+
}
|
12
|
+
}
|
8
13
|
|
9
14
|
before do
|
10
15
|
Dir.chdir File.dirname(__FILE__)
|
@@ -56,6 +61,11 @@ describe RackPipeline::Base do
|
|
56
61
|
response.headers['Content-Type'].must_include 'application/javascript'
|
57
62
|
end
|
58
63
|
|
64
|
+
it 'should properly compile and compress coffeescript' do
|
65
|
+
response = @r2.get('/coffee.js')
|
66
|
+
response.body.must_include '=function('
|
67
|
+
end
|
68
|
+
|
59
69
|
after do
|
60
70
|
FileUtils.rm_r( File.join( Dir.tmpdir, 'RackPipeline' ) )
|
61
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Bochkariov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coffee-script
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: uglifier
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description: Asset pipeline for ruby Rack
|
84
112
|
email:
|
85
113
|
- ujifgc@gmail.com
|
@@ -97,13 +125,16 @@ files:
|
|
97
125
|
- lib/rack-pipeline/base.rb
|
98
126
|
- lib/rack-pipeline/caching.rb
|
99
127
|
- lib/rack-pipeline/compiling.rb
|
128
|
+
- lib/rack-pipeline/compiling/coffee-script.rb
|
100
129
|
- lib/rack-pipeline/compressing.rb
|
130
|
+
- lib/rack-pipeline/compressing/uglifier.rb
|
101
131
|
- lib/rack-pipeline/processing.rb
|
102
132
|
- lib/rack-pipeline/sinatra.rb
|
103
133
|
- lib/rack-pipeline/version.rb
|
104
134
|
- rack-pipeline.gemspec
|
105
135
|
- test/assets/javascripts/a.js
|
106
136
|
- test/assets/javascripts/b.js
|
137
|
+
- test/assets/javascripts/coffee.coffee
|
107
138
|
- test/assets/stylesheets/a.css
|
108
139
|
- test/assets/stylesheets/b.css
|
109
140
|
- test/minitest_helper.rb
|
@@ -129,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
160
|
version: '0'
|
130
161
|
requirements: []
|
131
162
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.2.
|
163
|
+
rubygems_version: 2.2.2
|
133
164
|
signing_key:
|
134
165
|
specification_version: 4
|
135
166
|
summary: A Rack middleware to serve javascript and stylesheet assets for ruby web
|
@@ -137,6 +168,7 @@ summary: A Rack middleware to serve javascript and stylesheet assets for ruby we
|
|
137
168
|
test_files:
|
138
169
|
- test/assets/javascripts/a.js
|
139
170
|
- test/assets/javascripts/b.js
|
171
|
+
- test/assets/javascripts/coffee.coffee
|
140
172
|
- test/assets/stylesheets/a.css
|
141
173
|
- test/assets/stylesheets/b.css
|
142
174
|
- test/minitest_helper.rb
|