ghazel-jammit 0.4.3.1 → 0.4.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/jammit +1 -1
- data/jammit.gemspec +3 -3
- data/lib/jammit.rb +2 -2
- data/lib/jammit/compressor.rb +19 -7
- data/lib/jammit/dependencies.rb +2 -0
- data/lib/jammit/packager.rb +2 -1
- data/lib/jammit/routes.rb +9 -0
- metadata +4 -4
data/bin/jammit
CHANGED
data/jammit.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'ghazel-jammit'
|
3
|
-
s.version = '0.4.
|
4
|
-
s.date = '
|
3
|
+
s.version = '0.4.4.1' # Keep version in sync with jammit.rb
|
4
|
+
s.date = '2010-2-6'
|
5
5
|
|
6
6
|
s.homepage = "http://documentcloud.github.com/jammit/"
|
7
7
|
s.summary = "Industrial Strength Asset Packaging for Rails"
|
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
|
30
30
|
s.add_dependency 'rails', ['>= 2.0.0']
|
31
31
|
s.add_dependency 'yui-compressor', ['>= 0.9.1']
|
32
|
-
s.add_dependency 'closure-compiler', ['>= 0.
|
32
|
+
s.add_dependency 'ghazel-closure-compiler', ['>= 0.2.0.1']
|
33
33
|
|
34
34
|
s.files = Dir['lib/**/*', 'bin/*', 'jammit.gemspec', 'LICENSE', 'README']
|
35
35
|
end
|
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.4.
|
7
|
+
VERSION = "0.4.4"
|
8
8
|
|
9
9
|
ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
|
10
10
|
|
11
11
|
ASSET_ROOT = File.expand_path(defined?(Rails) ? Rails.root : ".") unless defined?(ASSET_ROOT)
|
12
12
|
|
13
|
-
PUBLIC_ROOT = File.join(ASSET_ROOT, 'public')
|
13
|
+
PUBLIC_ROOT = defined?(Rails) ? Rails.public_path : File.join(ASSET_ROOT, 'public')
|
14
14
|
|
15
15
|
DEFAULT_CONFIG_PATH = File.join(ASSET_ROOT, 'config', 'assets.yml')
|
16
16
|
|
data/lib/jammit/compressor.rb
CHANGED
@@ -7,8 +7,6 @@ module Jammit
|
|
7
7
|
# all stylesheets, with all enabled assets inlined into the css.
|
8
8
|
class Compressor
|
9
9
|
|
10
|
-
include ActionView::Helpers::AssetTagHelper
|
11
|
-
|
12
10
|
# Mapping from extension to mime-type of all embeddable assets.
|
13
11
|
EMBED_MIME_TYPES = {
|
14
12
|
'.png' => 'image/png',
|
@@ -25,8 +23,8 @@ module Jammit
|
|
25
23
|
EMBED_EXTS = EMBED_MIME_TYPES.keys
|
26
24
|
EMBED_FONTS = ['.ttf', '.otf']
|
27
25
|
|
28
|
-
#
|
29
|
-
MAX_IMAGE_SIZE =
|
26
|
+
# 32k maximum size for embeddable images (an IE8 limitation).
|
27
|
+
MAX_IMAGE_SIZE = 32768
|
30
28
|
|
31
29
|
# CSS asset-embedding regexes for URL rewriting.
|
32
30
|
EMBED_DETECTOR = /url\(['"]?([^\s)]+\.[a-z]+)(\?\d+)?['"]?\)/
|
@@ -135,8 +133,7 @@ module Jammit
|
|
135
133
|
i = paths[$1] ||= "#{index += 1}-#{File.basename($1)}"
|
136
134
|
"url(mhtml:#{asset_url}!#{i})"
|
137
135
|
end
|
138
|
-
|
139
|
-
mhtml = paths.map do |path, identifier|
|
136
|
+
mhtml = paths.sort.map do |path, identifier|
|
140
137
|
mime, contents = mime_type(path), encoded_contents(path)
|
141
138
|
[MHTML_SEPARATOR, "Content-Location: #{identifier}\r\n", "Content-Type: #{mime}\r\n", "Content-Transfer-Encoding: base64\r\n\r\n", contents, "\r\n"]
|
142
139
|
end
|
@@ -150,7 +147,7 @@ module Jammit
|
|
150
147
|
public_path = absolute_path(asset_path, css_path)
|
151
148
|
return "__EMBED__#{public_path}" if embeddable?(public_path, variant)
|
152
149
|
source = asset_path.absolute? ? asset_path.to_s : relative_path(public_path)
|
153
|
-
rewrite_asset_path(source)
|
150
|
+
rewrite_asset_path(source, public_path)
|
154
151
|
end
|
155
152
|
|
156
153
|
# Get the site-absolute public path for an asset file path that may or may
|
@@ -167,6 +164,21 @@ module Jammit
|
|
167
164
|
File.join('../', absolute_path.sub(PUBLIC_ROOT, ''))
|
168
165
|
end
|
169
166
|
|
167
|
+
# Similar to the AssetTagHelper's method of the same name, this will
|
168
|
+
# append the RAILS_ASSET_ID cache-buster to URLs, if it's defined.
|
169
|
+
def rewrite_asset_path(path, file_path)
|
170
|
+
asset_id = rails_asset_id(file_path)
|
171
|
+
asset_id.blank? ? path : "#{path}?#{asset_id}"
|
172
|
+
end
|
173
|
+
|
174
|
+
# Similar to the AssetTagHelper's method of the same name, this will
|
175
|
+
# determine the correct asset id for a file.
|
176
|
+
def rails_asset_id(path)
|
177
|
+
asset_id = ENV["RAILS_ASSET_ID"]
|
178
|
+
return asset_id if asset_id
|
179
|
+
File.exists?(path) ? File.mtime(path).to_i.to_s : ''
|
180
|
+
end
|
181
|
+
|
170
182
|
# An asset is valid for embedding if it exists, is less than 32K, and is
|
171
183
|
# stored somewhere inside of a folder named "embed".
|
172
184
|
# IE does not support Data-URIs larger than 32K, and you probably shouldn't
|
data/lib/jammit/dependencies.rb
CHANGED
@@ -8,9 +8,11 @@ require 'fileutils'
|
|
8
8
|
|
9
9
|
# Gem Dependencies:
|
10
10
|
require 'rubygems'
|
11
|
+
gem 'rails', '~> 2.0'
|
11
12
|
require 'yui/compressor'
|
12
13
|
require 'closure-compiler'
|
13
14
|
require 'active_support'
|
15
|
+
require 'active_support/core_ext/hash'
|
14
16
|
|
15
17
|
# Load initial configuration before the rest of Jammit.
|
16
18
|
Jammit.load_configuration(Jammit::DEFAULT_CONFIG_PATH) if defined?(Rails)
|
data/lib/jammit/packager.rb
CHANGED
@@ -7,7 +7,8 @@ module Jammit
|
|
7
7
|
class Packager
|
8
8
|
|
9
9
|
# In Rails, the difference between a path and an asset URL is "public".
|
10
|
-
|
10
|
+
PATH_DIFF = PUBLIC_ROOT.sub(ASSET_ROOT, '')
|
11
|
+
PATH_TO_URL = /\A#{Regexp.escape(ASSET_ROOT)}(\/?#{Regexp.escape(PATH_DIFF)})?/
|
11
12
|
|
12
13
|
# Set force to false to allow packages to only be rebuilt when their source
|
13
14
|
# files have changed since the last time their package was built.
|
data/lib/jammit/routes.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Jammit
|
2
2
|
|
3
|
+
# Rails 2.x routing module.
|
3
4
|
module Routes
|
4
5
|
|
5
6
|
# Jammit uses a single route in order to slow down Rails' routing speed
|
@@ -13,4 +14,12 @@ module Jammit
|
|
13
14
|
|
14
15
|
end
|
15
16
|
|
17
|
+
end
|
18
|
+
|
19
|
+
# Rails 3.x routes.
|
20
|
+
if defined?(Jammit::Railtie)
|
21
|
+
Jammit::Railtie.routes do
|
22
|
+
match "/#{Jammit.package_path}/:package.:extension",
|
23
|
+
:to => 'jammit#package', :as => 'jammit'
|
24
|
+
end
|
16
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghazel-jammit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Ashkenas
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-06 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -33,14 +33,14 @@ dependencies:
|
|
33
33
|
version: 0.9.1
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name: closure-compiler
|
36
|
+
name: ghazel-closure-compiler
|
37
37
|
type: :runtime
|
38
38
|
version_requirement:
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0.
|
43
|
+
version: 0.2.0.1
|
44
44
|
version:
|
45
45
|
description: " Jammit is an industrial strength asset packaging library for Rails,\n providing both the CSS and JavaScript concatenation and compression that\n you'd expect, as well as YUI Compressor and Closure Compiler compatibility,\n ahead-of-time gzipping, built-in JavaScript template support, and optional\n Data-URI / MHTML image embedding.\n"
|
46
46
|
email: jeremy@documentcloud.org
|