jammit 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/jammit.gemspec +2 -2
- data/lib/jammit.rb +2 -2
- data/lib/jammit/compressor.rb +24 -7
- data/lib/jammit/dependencies.rb +2 -0
- data/lib/jammit/packager.rb +2 -1
- metadata +2 -2
data/jammit.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'jammit'
|
3
|
-
s.version = '0.4.
|
4
|
-
s.date = '
|
3
|
+
s.version = '0.4.4' # 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"
|
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
@@ -23,8 +23,8 @@ module Jammit
|
|
23
23
|
EMBED_EXTS = EMBED_MIME_TYPES.keys
|
24
24
|
EMBED_FONTS = ['.ttf', '.otf']
|
25
25
|
|
26
|
-
#
|
27
|
-
MAX_IMAGE_SIZE =
|
26
|
+
# 32k maximum size for embeddable images (an IE8 limitation).
|
27
|
+
MAX_IMAGE_SIZE = 32768
|
28
28
|
|
29
29
|
# CSS asset-embedding regexes for URL rewriting.
|
30
30
|
EMBED_DETECTOR = /url\(['"]?([^\s)]+\.[a-z]+)(\?\d+)?['"]?\)/
|
@@ -110,7 +110,7 @@ module Jammit
|
|
110
110
|
File.read(css_path).gsub(EMBED_DETECTOR) do |url|
|
111
111
|
ipath, cpath = Pathname.new($1), Pathname.new(File.expand_path(css_path))
|
112
112
|
is_url = URI.parse($1).absolute?
|
113
|
-
is_url ? url : "url(#{
|
113
|
+
is_url ? url : "url(#{construct_asset_path(ipath, cpath, variant)})"
|
114
114
|
end
|
115
115
|
end
|
116
116
|
stylesheets.join("\n")
|
@@ -133,7 +133,7 @@ module Jammit
|
|
133
133
|
i = paths[$1] ||= "#{index += 1}-#{File.basename($1)}"
|
134
134
|
"url(mhtml:#{asset_url}!#{i})"
|
135
135
|
end
|
136
|
-
mhtml = paths.map do |path, identifier|
|
136
|
+
mhtml = paths.sort.map do |path, identifier|
|
137
137
|
mime, contents = mime_type(path), encoded_contents(path)
|
138
138
|
[MHTML_SEPARATOR, "Content-Location: #{identifier}\r\n", "Content-Type: #{mime}\r\n", "Content-Transfer-Encoding: base64\r\n\r\n", contents, "\r\n"]
|
139
139
|
end
|
@@ -143,10 +143,11 @@ module Jammit
|
|
143
143
|
# Return a rewritten asset URL for a new stylesheet -- the asset should
|
144
144
|
# be tagged for embedding if embeddable, and referenced at the correct level
|
145
145
|
# if relative.
|
146
|
-
def
|
146
|
+
def construct_asset_path(asset_path, css_path, variant)
|
147
147
|
public_path = absolute_path(asset_path, css_path)
|
148
148
|
return "__EMBED__#{public_path}" if embeddable?(public_path, variant)
|
149
|
-
asset_path.absolute? ? asset_path.to_s : relative_path(public_path)
|
149
|
+
source = asset_path.absolute? ? asset_path.to_s : relative_path(public_path)
|
150
|
+
rewrite_asset_path(source, public_path)
|
150
151
|
end
|
151
152
|
|
152
153
|
# Get the site-absolute public path for an asset file path that may or may
|
@@ -163,6 +164,21 @@ module Jammit
|
|
163
164
|
File.join('../', absolute_path.sub(PUBLIC_ROOT, ''))
|
164
165
|
end
|
165
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
|
+
|
166
182
|
# An asset is valid for embedding if it exists, is less than 32K, and is
|
167
183
|
# stored somewhere inside of a folder named "embed".
|
168
184
|
# IE does not support Data-URIs larger than 32K, and you probably shouldn't
|
@@ -179,7 +195,8 @@ module Jammit
|
|
179
195
|
|
180
196
|
# Return the Base64-encoded contents of an asset on a single line.
|
181
197
|
def encoded_contents(asset_path)
|
182
|
-
|
198
|
+
data = File.open(asset_path, 'rb'){|f| f.read }
|
199
|
+
Base64.encode64(data).gsub(/\n/, '')
|
183
200
|
end
|
184
201
|
|
185
202
|
# Grab the mime-type of an asset, by filename.
|
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.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jammit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
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 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|