jammit 0.2.6 → 0.2.7
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/jammit.gemspec +1 -1
- data/lib/jammit.rb +2 -2
- data/lib/jammit/command_line.rb +8 -3
- data/lib/jammit/packager.rb +24 -3
- metadata +1 -1
data/jammit.gemspec
CHANGED
data/lib/jammit.rb
CHANGED
|
@@ -4,7 +4,7 @@ $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.2.
|
|
7
|
+
VERSION = "0.2.7"
|
|
8
8
|
|
|
9
9
|
ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
|
|
10
10
|
|
|
@@ -133,7 +133,7 @@ require 'closure-compiler'
|
|
|
133
133
|
require 'activesupport'
|
|
134
134
|
|
|
135
135
|
# Load initial configuration before the rest of Jammit.
|
|
136
|
-
Jammit.load_configuration(Jammit::DEFAULT_CONFIG_PATH)
|
|
136
|
+
Jammit.load_configuration(Jammit::DEFAULT_CONFIG_PATH) if defined?(RAILS_ENV)
|
|
137
137
|
|
|
138
138
|
# Jammit Core:
|
|
139
139
|
require 'jammit/compressor'
|
data/lib/jammit/command_line.rb
CHANGED
|
@@ -27,6 +27,7 @@ Options:
|
|
|
27
27
|
parse_options
|
|
28
28
|
ensure_configuration_file
|
|
29
29
|
Jammit.load_configuration(@options[:config_path])
|
|
30
|
+
Jammit.packager.force = @options[:force]
|
|
30
31
|
Jammit.packager.precache_all(@options[:output_folder], @options[:base_url])
|
|
31
32
|
end
|
|
32
33
|
|
|
@@ -46,9 +47,10 @@ Options:
|
|
|
46
47
|
# *--base-url*...
|
|
47
48
|
def parse_options
|
|
48
49
|
@options = {
|
|
49
|
-
:config_path
|
|
50
|
-
:output_folder
|
|
51
|
-
:base_url
|
|
50
|
+
:config_path => Jammit::DEFAULT_CONFIG_PATH,
|
|
51
|
+
:output_folder => nil,
|
|
52
|
+
:base_url => nil,
|
|
53
|
+
:force => false
|
|
52
54
|
}
|
|
53
55
|
@option_parser = OptionParser.new do |opts|
|
|
54
56
|
opts.on('-o', '--output PATH', 'output folder for packages (default: "public/assets")') do |output_folder|
|
|
@@ -60,6 +62,9 @@ Options:
|
|
|
60
62
|
opts.on('-u', '--base-url URL', 'base URL for MHTML (ex: "http://example.com")') do |base_url|
|
|
61
63
|
@options[:base_url] = base_url
|
|
62
64
|
end
|
|
65
|
+
opts.on('-f', '--force', 'force a rebuild of all assets') do |force|
|
|
66
|
+
@options[:force] = force
|
|
67
|
+
end
|
|
63
68
|
opts.on_tail('-v', '--version', 'display Jammit version') do
|
|
64
69
|
puts "Jammit version #{Jammit::VERSION}"
|
|
65
70
|
exit
|
data/lib/jammit/packager.rb
CHANGED
|
@@ -9,11 +9,16 @@ module Jammit
|
|
|
9
9
|
# In Rails, the difference between a path and an asset URL is "public".
|
|
10
10
|
PATH_TO_URL = /\A#{ASSET_ROOT}(\/public)?/
|
|
11
11
|
|
|
12
|
+
# Set force to false to allow packages to only be rebuilt when their source
|
|
13
|
+
# files have changed since the last time their package was built.
|
|
14
|
+
attr_accessor :force
|
|
15
|
+
|
|
12
16
|
# Creating a new Packager will rebuild the list of assets from the
|
|
13
17
|
# Jammit.configuration. When assets.yml is being changed on the fly,
|
|
14
18
|
# create a new Packager.
|
|
15
19
|
def initialize
|
|
16
20
|
@compressor = Compressor.new
|
|
21
|
+
@force = true
|
|
17
22
|
@config = {
|
|
18
23
|
:css => (Jammit.configuration[:stylesheets] || {}).symbolize_keys,
|
|
19
24
|
:js => (Jammit.configuration[:javascripts] || {}).symbolize_keys,
|
|
@@ -29,11 +34,13 @@ module Jammit
|
|
|
29
34
|
# Ask the packager to precache all defined assets, along with their gzip'd
|
|
30
35
|
# versions. In order to prebuild the MHTML stylesheets, we need to know the
|
|
31
36
|
# base_url, because IE only supports MHTML with absolute references.
|
|
37
|
+
# Unless forced, will only rebuild assets whose source files have been
|
|
38
|
+
# changed since their last package build.
|
|
32
39
|
def precache_all(output_dir=nil, base_url=nil)
|
|
33
40
|
output_dir ||= "#{ASSET_ROOT}/public/#{Jammit.package_path}"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
cacheable(:js, output_dir).each {|p| cache(p, 'js', pack_javascripts(p), output_dir) }
|
|
42
|
+
cacheable(:jst, output_dir).each {|p| cache(p, 'jst', pack_templates(p), output_dir) }
|
|
43
|
+
cacheable(:css, output_dir).each do |p|
|
|
37
44
|
cache(p, 'css', pack_stylesheets(p), output_dir)
|
|
38
45
|
if Jammit.embed_images
|
|
39
46
|
cache(p, 'css', pack_stylesheets(p, :datauri), output_dir, :datauri)
|
|
@@ -94,6 +101,20 @@ module Jammit
|
|
|
94
101
|
Dir[absolute ? glob : File.join(ASSET_ROOT, glob)]
|
|
95
102
|
end
|
|
96
103
|
|
|
104
|
+
# Return a list of all of the packages that should be cached. If "force" is
|
|
105
|
+
# true, this is all of them -- otherwise only the packages whose source
|
|
106
|
+
# files have changed since the last package build.
|
|
107
|
+
def cacheable(extension, output_dir)
|
|
108
|
+
names = @packages[extension].keys
|
|
109
|
+
return names if @force
|
|
110
|
+
return names.select do |name|
|
|
111
|
+
pack = package_for(name, extension)
|
|
112
|
+
cached = File.join(output_dir, Jammit.filename(name, extension))
|
|
113
|
+
since = File.exists?(cached) && File.mtime(cached)
|
|
114
|
+
!since || pack[:paths].any? {|src| File.mtime(src) > since }
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
97
118
|
# Compiles the list of assets that goes into each package. Runs an ordered
|
|
98
119
|
# list of Dir.globs, taking the merged unique result.
|
|
99
120
|
def create_packages(config)
|