jammit 0.6.3 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/jammit.gemspec +2 -2
- data/lib/jammit.rb +14 -3
- data/lib/jammit/command_line.rb +4 -0
- data/lib/jammit/compressor.rb +3 -3
- data/lib/jammit/controller.rb +1 -1
- data/lib/jammit/helper.rb +4 -3
- data/lib/jammit/packager.rb +13 -9
- metadata +4 -4
data/LICENSE
CHANGED
data/jammit.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'jammit'
|
3
|
-
s.version = '0.6.
|
4
|
-
s.date = '2011-
|
3
|
+
s.version = '0.6.5' # Keep version in sync with jammit.rb
|
4
|
+
s.date = '2011-11-30'
|
5
5
|
|
6
6
|
s.homepage = "http://documentcloud.github.com/jammit/"
|
7
7
|
s.summary = "Industrial Strength Asset Packaging for Rails"
|
data/lib/jammit.rb
CHANGED
@@ -4,13 +4,13 @@ $LOAD_PATH.push File.expand_path(File.dirname(__FILE__))
|
|
4
4
|
# to all of the configuration options.
|
5
5
|
module Jammit
|
6
6
|
|
7
|
-
VERSION = "0.6.
|
7
|
+
VERSION = "0.6.5"
|
8
8
|
|
9
9
|
ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
|
10
10
|
|
11
11
|
ASSET_ROOT = File.expand_path((defined?(Rails) && Rails.root.to_s.length > 0) ? Rails.root : ENV['RAILS_ROOT'] || ".") unless defined?(ASSET_ROOT)
|
12
12
|
|
13
|
-
|
13
|
+
DEFAULT_PUBLIC_ROOT = (defined?(Rails) && Rails.public_path.to_s.length > 0) ? Rails.public_path : File.join(ASSET_ROOT, 'public') unless defined?(PUBLIC_ROOT)
|
14
14
|
|
15
15
|
DEFAULT_CONFIG_PATH = File.join(ASSET_ROOT, 'config', 'assets.yml')
|
16
16
|
|
@@ -51,12 +51,14 @@ module Jammit
|
|
51
51
|
:embed_assets, :package_assets, :compress_assets, :gzip_assets,
|
52
52
|
:package_path, :mhtml_enabled, :include_jst_script, :config_path,
|
53
53
|
:javascript_compressor, :compressor_options, :css_compressor_options,
|
54
|
-
:template_extension, :template_extension_matcher, :allow_debugging
|
54
|
+
:template_extension, :template_extension_matcher, :allow_debugging,
|
55
|
+
:public_root
|
55
56
|
attr_accessor :compressors
|
56
57
|
end
|
57
58
|
|
58
59
|
# The minimal required configuration.
|
59
60
|
@configuration = {}
|
61
|
+
@public_root = DEFAULT_PUBLIC_ROOT
|
60
62
|
@package_path = DEFAULT_PACKAGE_PATH
|
61
63
|
@compressors = COMPRESSORS
|
62
64
|
|
@@ -87,6 +89,7 @@ module Jammit
|
|
87
89
|
set_template_function(conf[:template_function])
|
88
90
|
set_template_namespace(conf[:template_namespace])
|
89
91
|
set_template_extension(conf[:template_extension])
|
92
|
+
set_public_root(conf[:public_root]) if conf[:public_root]
|
90
93
|
symbolize_keys(conf[:stylesheets]) if conf[:stylesheets]
|
91
94
|
symbolize_keys(conf[:javascripts]) if conf[:javascripts]
|
92
95
|
check_for_deprecations
|
@@ -124,9 +127,11 @@ module Jammit
|
|
124
127
|
:config_path => Jammit::DEFAULT_CONFIG_PATH,
|
125
128
|
:output_folder => nil,
|
126
129
|
:base_url => nil,
|
130
|
+
:public_root => nil,
|
127
131
|
:force => false
|
128
132
|
}.merge(options)
|
129
133
|
load_configuration(options[:config_path])
|
134
|
+
set_public_root(options[:public_root]) if options[:public_root]
|
130
135
|
packager.force = options[:force]
|
131
136
|
packager.package_names = options[:package_names]
|
132
137
|
packager.precache_all(options[:output_folder], options[:base_url])
|
@@ -134,6 +139,12 @@ module Jammit
|
|
134
139
|
|
135
140
|
private
|
136
141
|
|
142
|
+
# Allows command-line definition of `PUBLIC_ROOT`, for those using Jammit
|
143
|
+
# outside of Rails.
|
144
|
+
def self.set_public_root(public_root=nil)
|
145
|
+
@public_root = public_root if public_root
|
146
|
+
end
|
147
|
+
|
137
148
|
# Ensure that the JavaScript compressor is a valid choice.
|
138
149
|
def self.set_javascript_compressor(value)
|
139
150
|
value = value && value.to_sym
|
data/lib/jammit/command_line.rb
CHANGED
@@ -66,6 +66,10 @@ Options:
|
|
66
66
|
opts.on('-p', '--packages LIST', 'list of packages to build (ex: "core,ui", default: all)') do |package_names|
|
67
67
|
@options[:package_names] = package_names.split(/,\s*/).map {|n| n.to_sym }
|
68
68
|
end
|
69
|
+
opts.on('-P', '--public-root PATH', 'path to public assets (default: "public")') do |public_root|
|
70
|
+
puts "Option for PUBLIC_ROOT"
|
71
|
+
@options[:public_root] = public_root
|
72
|
+
end
|
69
73
|
opts.on_tail('-v', '--version', 'display Jammit version') do
|
70
74
|
puts "Jammit version #{Jammit::VERSION}"
|
71
75
|
exit
|
data/lib/jammit/compressor.rb
CHANGED
@@ -187,14 +187,14 @@ module Jammit
|
|
187
187
|
# not be relative, given the path of the stylesheet that contains it.
|
188
188
|
def absolute_path(asset_pathname, css_pathname)
|
189
189
|
(asset_pathname.absolute? ?
|
190
|
-
Pathname.new(File.join(
|
190
|
+
Pathname.new(File.join(Jammit.public_root, asset_pathname)) :
|
191
191
|
css_pathname.dirname + asset_pathname).cleanpath
|
192
192
|
end
|
193
193
|
|
194
194
|
# CSS assets that are referenced by relative paths, and are *not* being
|
195
195
|
# embedded, must be rewritten relative to the newly-merged stylesheet path.
|
196
196
|
def relative_path(absolute_path)
|
197
|
-
File.join('../', absolute_path.sub(
|
197
|
+
File.join('../', absolute_path.sub(Jammit.public_root, ''))
|
198
198
|
end
|
199
199
|
|
200
200
|
# Similar to the AssetTagHelper's method of the same name, this will
|
@@ -246,7 +246,7 @@ module Jammit
|
|
246
246
|
|
247
247
|
# `File.read`, but in "binary" mode.
|
248
248
|
def read_binary_file(path)
|
249
|
-
File.open(path, 'rb') {|f| f.read }
|
249
|
+
File.open(path, 'rb:UTF-8') {|f| f.read }
|
250
250
|
end
|
251
251
|
end
|
252
252
|
|
data/lib/jammit/controller.rb
CHANGED
@@ -11,7 +11,7 @@ module Jammit
|
|
11
11
|
|
12
12
|
SUFFIX_STRIPPER = /-(datauri|mhtml)\Z/
|
13
13
|
|
14
|
-
NOT_FOUND_PATH = "#{
|
14
|
+
NOT_FOUND_PATH = "#{Jammit.public_root}/404.html"
|
15
15
|
|
16
16
|
# The "package" action receives all requests for asset packages that haven't
|
17
17
|
# yet been cached. The package will be built, cached, and gzipped.
|
data/lib/jammit/helper.rb
CHANGED
@@ -25,10 +25,11 @@ module Jammit
|
|
25
25
|
# Writes out the URL to the bundled and compressed javascript package,
|
26
26
|
# except in development, where it references the individual scripts.
|
27
27
|
def include_javascripts(*packages)
|
28
|
+
options = packages.extract_options!
|
28
29
|
html_safe packages.map {|pack|
|
29
30
|
should_package? ? Jammit.asset_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js)
|
30
31
|
}.flatten.map {|pack|
|
31
|
-
javascript_include_tag pack
|
32
|
+
javascript_include_tag pack, options
|
32
33
|
}.join("\n")
|
33
34
|
end
|
34
35
|
|
@@ -72,8 +73,8 @@ module Jammit
|
|
72
73
|
# Generate the stylesheet tags for a batch of packages, with options, by
|
73
74
|
# yielding each package to a block.
|
74
75
|
def tags_with_options(packages, options)
|
75
|
-
packages.dup.map {|package|
|
76
|
-
yield package
|
76
|
+
packages.dup.map {|package|
|
77
|
+
yield package
|
77
78
|
}.flatten.map {|package|
|
78
79
|
stylesheet_link_tag package, options
|
79
80
|
}.join("\n")
|
data/lib/jammit/packager.rb
CHANGED
@@ -6,10 +6,6 @@ module Jammit
|
|
6
6
|
# with the correct timestamps.
|
7
7
|
class Packager
|
8
8
|
|
9
|
-
# In Rails, the difference between a path and an asset URL is "public".
|
10
|
-
PATH_DIFF = PUBLIC_ROOT.sub(ASSET_ROOT, '')
|
11
|
-
PATH_TO_URL = /\A#{Regexp.escape(ASSET_ROOT)}(\/?#{Regexp.escape(PATH_DIFF)})?/
|
12
|
-
|
13
9
|
# Set force to false to allow packages to only be rebuilt when their source
|
14
10
|
# files have changed since the last time their package was built.
|
15
11
|
attr_accessor :force, :package_names
|
@@ -37,7 +33,7 @@ module Jammit
|
|
37
33
|
# Unless forced, will only rebuild assets whose source files have been
|
38
34
|
# changed since their last package build.
|
39
35
|
def precache_all(output_dir=nil, base_url=nil)
|
40
|
-
output_dir ||= File.join(
|
36
|
+
output_dir ||= File.join(Jammit.public_root, Jammit.package_path)
|
41
37
|
cacheable(:js, output_dir).each {|p| cache(p, 'js', pack_javascripts(p), output_dir) }
|
42
38
|
cacheable(:css, output_dir).each do |p|
|
43
39
|
cache(p, 'css', pack_stylesheets(p), output_dir)
|
@@ -89,6 +85,7 @@ module Jammit
|
|
89
85
|
def pack_templates(package)
|
90
86
|
@compressor.compile_jst(package_for(package, :js)[:paths])
|
91
87
|
end
|
88
|
+
|
92
89
|
|
93
90
|
private
|
94
91
|
|
@@ -107,6 +104,11 @@ module Jammit
|
|
107
104
|
Jammit.warn("No assets match '#{glob}'") if paths.empty?
|
108
105
|
paths
|
109
106
|
end
|
107
|
+
|
108
|
+
# In Rails, the difference between a path and an asset URL is "public".
|
109
|
+
def path_to_url
|
110
|
+
@path_to_url ||= /\A#{Regexp.escape(ASSET_ROOT)}(\/?#{Regexp.escape(Jammit.public_root.sub(ASSET_ROOT, ''))})?/
|
111
|
+
end
|
110
112
|
|
111
113
|
# Get the latest mtime of a list of files (plus the config path).
|
112
114
|
def latest_mtime(paths)
|
@@ -125,8 +127,10 @@ module Jammit
|
|
125
127
|
return names.select do |name|
|
126
128
|
pack = package_for(name, extension)
|
127
129
|
cached = [Jammit.filename(name, extension)]
|
128
|
-
|
129
|
-
|
130
|
+
if extension == :css
|
131
|
+
cached.push Jammit.filename(name, extension, :datauri) if Jammit.embed_assets
|
132
|
+
cached.push Jammit.filename(name, extension, :mhtml) if Jammit.mhtml_enabled
|
133
|
+
end
|
130
134
|
cached.map! {|file| File.join(output_dir, file) }
|
131
135
|
if cached.any? {|file| !File.exists?(file) }
|
132
136
|
true
|
@@ -153,10 +157,10 @@ module Jammit
|
|
153
157
|
paths = globs.flatten.uniq.map {|glob| glob_files(glob) }.flatten.uniq
|
154
158
|
packages[name][:paths] = paths
|
155
159
|
if !paths.grep(Jammit.template_extension_matcher).empty?
|
156
|
-
packages[name][:urls] = paths.grep(JS_EXTENSION).map {|path| path.sub(
|
160
|
+
packages[name][:urls] = paths.grep(JS_EXTENSION).map {|path| path.sub(path_to_url, '') }
|
157
161
|
packages[name][:urls] += [Jammit.asset_url(name, Jammit.template_extension)]
|
158
162
|
else
|
159
|
-
packages[name][:urls] = paths.map {|path| path.sub(
|
163
|
+
packages[name][:urls] = paths.map {|path| path.sub(path_to_url, '') }
|
160
164
|
end
|
161
165
|
end
|
162
166
|
packages
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jammit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 5
|
10
|
+
version: 0.6.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeremy Ashkenas
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-30 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: yui-compressor
|