rails_asset_packager 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +15 -0
- data/TODO +1 -3
- data/lib/rails_asset_packager/asset_package.rb +32 -22
- data/lib/rails_asset_packager/asset_package_helper.rb +13 -13
- data/lib/rails_asset_packager/version.rb +1 -1
- metadata +3 -3
data/CHANGELOG
CHANGED
@@ -1,4 +1,19 @@
|
|
1
1
|
------------------------------------------------------------------------
|
2
|
+
v0.1.3 | plainprogrammer | 2011-01-25
|
3
|
+
|
4
|
+
* Fixed issue with *_merged helpers that was causing calls to error out.
|
5
|
+
* Fixed issue with *_merged helpers that was causing calls to get escaped by Rails instead of rendering properly.
|
6
|
+
------------------------------------------------------------------------
|
7
|
+
v0.1.2 | plainprogrammer | 2011-01-25
|
8
|
+
|
9
|
+
* Fixed test suite.
|
10
|
+
------------------------------------------------------------------------
|
11
|
+
v0.1.1 | plainprogrammer | 2011-01-18
|
12
|
+
|
13
|
+
* Fixed issues with development dependencies.
|
14
|
+
* Updated Rakefile to properly include testing and documentation tasks.
|
15
|
+
* Did some minor refactoring inside caching tasks.
|
16
|
+
------------------------------------------------------------------------
|
2
17
|
v0.1.0 | plainprogrammer | 2011-01-16
|
3
18
|
|
4
19
|
* Converted project into Gem
|
data/TODO
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
TODO
|
2
2
|
====
|
3
3
|
* FEATURE: Add means to track which files that have been uploaded to S3 have been
|
4
|
-
modified to prevent uploading all assets every time you call
|
4
|
+
modified to prevent uploading all assets every time you call
|
5
5
|
'rake asset:cache:production.'
|
6
6
|
* BUG: Make it so that the asset:cache rake tasks execute properly when called
|
7
7
|
from other rake tasks outside rails_asset_packager rake file.
|
8
8
|
* FEATURE: Add capability to ignore assets already included in packaged assets
|
9
9
|
when uploading to S3.
|
10
|
-
* BUG: Fix inability to use the two helpers, stylesheet_link_merged and
|
11
|
-
javascript_include_merged. Start by fixing test suite.
|
@@ -1,20 +1,30 @@
|
|
1
1
|
module RailsAssetPackager
|
2
2
|
class AssetPackage
|
3
3
|
|
4
|
-
@asset_base_path = "#{Rails.root}/public"
|
5
|
-
@asset_packages_yml = File.exists?("#{Rails.root}/config/asset_packages.yml") ? YAML.load_file("#{Rails.root}/config/asset_packages.yml") : nil
|
6
|
-
|
7
4
|
# singleton methods
|
8
5
|
class << self
|
9
|
-
attr_accessor :asset_base_path,
|
10
|
-
:asset_packages_yml
|
11
|
-
|
12
6
|
attr_writer :merge_environments
|
13
|
-
|
7
|
+
|
8
|
+
def asset_base_path
|
9
|
+
@@asset_base_path ||= "#{Rails.root}/public"
|
10
|
+
end
|
11
|
+
|
12
|
+
def asset_base_path=(path)
|
13
|
+
@@asset_base_path = path
|
14
|
+
end
|
15
|
+
|
16
|
+
def asset_packages_yml
|
17
|
+
@@asset_packages_yml ||= File.exists?("#{Rails.root}/config/asset_packages.yml") ? YAML.load_file("#{Rails.root}/config/asset_packages.yml") : nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def asset_packages_yml=(path)
|
21
|
+
@@asset_packages_yml = path
|
22
|
+
end
|
23
|
+
|
14
24
|
def merge_environments
|
15
25
|
@merge_environments ||= ["production"]
|
16
26
|
end
|
17
|
-
|
27
|
+
|
18
28
|
def parse_path(path)
|
19
29
|
/^(?:(.*)\/)?([^\/]+)$/.match(path).to_a
|
20
30
|
end
|
@@ -89,10 +99,10 @@ module RailsAssetPackager
|
|
89
99
|
end
|
90
100
|
|
91
101
|
end
|
92
|
-
|
102
|
+
|
93
103
|
# instance methods
|
94
104
|
attr_accessor :asset_type, :target, :target_dir, :sources
|
95
|
-
|
105
|
+
|
96
106
|
def initialize(asset_type, package_hash)
|
97
107
|
target_parts = self.class.parse_path(package_hash.keys.first)
|
98
108
|
@target_dir = target_parts[1].to_s
|
@@ -104,7 +114,7 @@ module RailsAssetPackager
|
|
104
114
|
@file_name = "#{@target}_packaged.#{@extension}"
|
105
115
|
@full_path = File.join(@asset_path, @file_name)
|
106
116
|
end
|
107
|
-
|
117
|
+
|
108
118
|
def package_exists?
|
109
119
|
File.exists?(@full_path)
|
110
120
|
end
|
@@ -138,14 +148,14 @@ module RailsAssetPackager
|
|
138
148
|
|
139
149
|
def merged_file
|
140
150
|
merged_file = ""
|
141
|
-
@sources.each {|s|
|
142
|
-
File.open("#{@asset_path}/#{s}.#{@extension}", "r") { |f|
|
143
|
-
merged_file += f.read + "\n"
|
151
|
+
@sources.each {|s|
|
152
|
+
File.open("#{@asset_path}/#{s}.#{@extension}", "r") { |f|
|
153
|
+
merged_file += f.read + "\n"
|
144
154
|
}
|
145
155
|
}
|
146
156
|
merged_file
|
147
157
|
end
|
148
|
-
|
158
|
+
|
149
159
|
def compressed_file
|
150
160
|
case @asset_type
|
151
161
|
when "javascripts" then compress_js(merged_file)
|
@@ -156,24 +166,24 @@ module RailsAssetPackager
|
|
156
166
|
def compress_js(source)
|
157
167
|
jsmin_path = File.dirname(__FILE__) + '/..'
|
158
168
|
tmp_path = "#{Rails.root}/tmp/#{@target}_packaged"
|
159
|
-
|
169
|
+
|
160
170
|
# write out to a temp file
|
161
171
|
File.open("#{tmp_path}_uncompressed.js", "w") {|f| f.write(source) }
|
162
|
-
|
172
|
+
|
163
173
|
# compress file with JSMin library
|
164
174
|
`ruby #{jsmin_path}/jsmin.rb <#{tmp_path}_uncompressed.js >#{tmp_path}_compressed.js \n`
|
165
175
|
|
166
176
|
# read it back in and trim it
|
167
177
|
result = ""
|
168
178
|
File.open("#{tmp_path}_compressed.js", "r") { |f| result += f.read.strip }
|
169
|
-
|
179
|
+
|
170
180
|
# delete temp files if they exist
|
171
181
|
File.delete("#{tmp_path}_uncompressed.js") if File.exists?("#{tmp_path}_uncompressed.js")
|
172
182
|
File.delete("#{tmp_path}_compressed.js") if File.exists?("#{tmp_path}_compressed.js")
|
173
183
|
|
174
184
|
result
|
175
185
|
end
|
176
|
-
|
186
|
+
|
177
187
|
def compress_css(source)
|
178
188
|
source.gsub!(/\s+/, " ") # collapse space
|
179
189
|
source.gsub!(/\/\*(.*?)\*\//, "") # remove comments - caution, might want to remove this if using css hacks
|
@@ -190,11 +200,11 @@ module RailsAssetPackager
|
|
190
200
|
when "stylesheets" then "css"
|
191
201
|
end
|
192
202
|
end
|
193
|
-
|
203
|
+
|
194
204
|
def log(message)
|
195
205
|
self.class.log(message)
|
196
206
|
end
|
197
|
-
|
207
|
+
|
198
208
|
def self.log(message)
|
199
209
|
puts message
|
200
210
|
end
|
@@ -206,6 +216,6 @@ module RailsAssetPackager
|
|
206
216
|
file_list.reverse! if extension == "js"
|
207
217
|
file_list
|
208
218
|
end
|
209
|
-
|
219
|
+
|
210
220
|
end
|
211
221
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module RailsAssetPackager
|
2
2
|
module AssetPackageHelper
|
3
|
-
|
3
|
+
|
4
4
|
def should_merge?
|
5
5
|
AssetPackage.merge_environments.include?(Rails.env)
|
6
6
|
end
|
@@ -8,32 +8,32 @@ module RailsAssetPackager
|
|
8
8
|
def javascript_include_merged(*sources)
|
9
9
|
options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
|
10
10
|
|
11
|
-
if sources.include?(:defaults)
|
12
|
-
sources = sources[0..(sources.index(:defaults))] +
|
13
|
-
['prototype', 'effects', 'dragdrop', 'controls'] +
|
14
|
-
(File.exists?("#{Rails.root}/public/javascripts/application.js") ? ['application'] : []) +
|
11
|
+
if sources.include?(:defaults)
|
12
|
+
sources = sources[0..(sources.index(:defaults))] +
|
13
|
+
['prototype', 'effects', 'dragdrop', 'controls'] +
|
14
|
+
(File.exists?("#{Rails.root}/public/javascripts/application.js") ? ['application'] : []) +
|
15
15
|
sources[(sources.index(:defaults) + 1)..sources.length]
|
16
16
|
sources.delete(:defaults)
|
17
17
|
end
|
18
18
|
|
19
19
|
sources.collect!{|s| s.to_s}
|
20
|
-
sources = (should_merge? ?
|
21
|
-
AssetPackage.targets_from_sources("javascripts", sources) :
|
20
|
+
sources = (should_merge? ?
|
21
|
+
AssetPackage.targets_from_sources("javascripts", sources) :
|
22
22
|
AssetPackage.sources_from_targets("javascripts", sources))
|
23
|
-
|
24
|
-
sources.collect {|source| javascript_include_tag(source, options) }.join("\n")
|
23
|
+
|
24
|
+
raw(sources.collect {|source| javascript_include_tag(source, options) }.join("\n"))
|
25
25
|
end
|
26
26
|
|
27
27
|
def stylesheet_link_merged(*sources)
|
28
28
|
options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
|
29
29
|
|
30
30
|
sources.collect!{|s| s.to_s}
|
31
|
-
sources = (should_merge? ?
|
32
|
-
AssetPackage.targets_from_sources("stylesheets", sources) :
|
31
|
+
sources = (should_merge? ?
|
32
|
+
AssetPackage.targets_from_sources("stylesheets", sources) :
|
33
33
|
AssetPackage.sources_from_targets("stylesheets", sources))
|
34
34
|
|
35
|
-
sources.collect { |source| stylesheet_link_tag(source, options) }.join("\n")
|
35
|
+
raw(sources.collect { |source| stylesheet_link_tag(source, options) }.join("\n"))
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
39
|
-
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_asset_packager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Scott Becker
|