assette 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.irbrc +2 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +10 -5
- data/Rakefile +9 -1
- data/VERSION +1 -1
- data/assette.gemspec +16 -4
- data/examples/config/assets.rb +1 -0
- data/examples/myapp/templates/bar/index.html.mustache +3 -0
- data/lib/assette.rb +2 -2
- data/lib/assette/config.rb +32 -0
- data/lib/assette/file.rb +36 -13
- data/lib/assette/post_processors/cache_buster.rb +13 -11
- data/lib/assette/reader.rb +7 -0
- data/lib/assette/readers.rb +4 -2
- data/lib/assette/readers/css.rb +6 -0
- data/lib/assette/readers/js.rb +6 -0
- data/lib/assette/server.rb +10 -0
- data/lib/assette/template_set.rb +14 -9
- data/lib/assette/view_helper.rb +60 -0
- data/spec/helper_spec.rb +99 -0
- data/spec/spec_helper.rb +2 -0
- data/test/helper.rb +21 -0
- data/test/test_server.rb +154 -0
- metadata +39 -16
data/.irbrc
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -4,9 +4,10 @@ GEM
|
|
4
4
|
coffee-script (2.2.0)
|
5
5
|
coffee-script-source
|
6
6
|
execjs
|
7
|
-
coffee-script-source (1.
|
7
|
+
coffee-script-source (1.1.1)
|
8
8
|
diff-lcs (1.1.2)
|
9
|
-
execjs (
|
9
|
+
execjs (1.0.0)
|
10
|
+
multi_json (~> 1.0)
|
10
11
|
git (1.2.5)
|
11
12
|
jeweler (1.5.2)
|
12
13
|
bundler (~> 1.0.0)
|
@@ -14,8 +15,11 @@ GEM
|
|
14
15
|
rake
|
15
16
|
json (1.5.1)
|
16
17
|
mime-types (1.16)
|
17
|
-
|
18
|
-
|
18
|
+
multi_json (1.0.3)
|
19
|
+
rack (1.3.0)
|
20
|
+
rack-test (0.6.0)
|
21
|
+
rack (>= 1.0)
|
22
|
+
rake (0.9.0)
|
19
23
|
rcov (0.9.9)
|
20
24
|
rspec (2.4.0)
|
21
25
|
rspec-core (~> 2.4.0)
|
@@ -27,7 +31,7 @@ GEM
|
|
27
31
|
rspec-mocks (2.4.0)
|
28
32
|
sass (3.1.1)
|
29
33
|
thor (0.14.6)
|
30
|
-
yard (0.6.
|
34
|
+
yard (0.6.8)
|
31
35
|
|
32
36
|
PLATFORMS
|
33
37
|
ruby
|
@@ -40,6 +44,7 @@ DEPENDENCIES
|
|
40
44
|
json (>= 1.4)
|
41
45
|
mime-types (>= 1.16)
|
42
46
|
rack (~> 1)
|
47
|
+
rack-test
|
43
48
|
rcov
|
44
49
|
rspec (~> 2.4.0)
|
45
50
|
sass (>= 3.1)
|
data/Rakefile
CHANGED
@@ -9,6 +9,8 @@ rescue Bundler::BundlerError => e
|
|
9
9
|
end
|
10
10
|
require 'rake'
|
11
11
|
|
12
|
+
include Rake::DSL
|
13
|
+
|
12
14
|
require 'jeweler'
|
13
15
|
Jeweler::Tasks.new do |gem|
|
14
16
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
@@ -26,7 +28,6 @@ Jeweler::Tasks.new do |gem|
|
|
26
28
|
gem.add_runtime_dependency "json", '>= 1.4'
|
27
29
|
gem.add_runtime_dependency "sass", '>= 3.1'
|
28
30
|
gem.add_runtime_dependency "coffee-script", '~> 2'
|
29
|
-
# gem.add_runtime_dependency "git"
|
30
31
|
gem.add_runtime_dependency "mime-types", ">= 1.16"
|
31
32
|
end
|
32
33
|
Jeweler::RubygemsDotOrgTasks.new
|
@@ -46,3 +47,10 @@ task :default => :spec
|
|
46
47
|
|
47
48
|
require 'yard'
|
48
49
|
YARD::Rake::YardocTask.new
|
50
|
+
|
51
|
+
require 'rake/testtask'
|
52
|
+
Rake::TestTask.new(:test) do |test|
|
53
|
+
test.libs << 'lib' << 'test'
|
54
|
+
test.pattern = 'test/**/test_*.rb'
|
55
|
+
test.verbose = true
|
56
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/assette.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{assette}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tal Atlas"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-06-14}
|
13
13
|
s.default_executable = %q{assette}
|
14
14
|
s.description = %q{Renders all asset types (coffeescript/sass/scss) as equals}
|
15
15
|
s.email = %q{me@tal.by}
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
]
|
21
21
|
s.files = [
|
22
22
|
".document",
|
23
|
+
".irbrc",
|
23
24
|
".rspec",
|
24
25
|
"Gemfile",
|
25
26
|
"Gemfile.lock",
|
@@ -30,6 +31,7 @@ Gem::Specification.new do |s|
|
|
30
31
|
"assette.gemspec",
|
31
32
|
"bin/assette",
|
32
33
|
"examples/config/assets.rb",
|
34
|
+
"examples/myapp/templates/bar/index.html.mustache",
|
33
35
|
"examples/myapp/templates/foo/_partial.html.mustache",
|
34
36
|
"examples/myapp/templates/foo/index.html.mustache",
|
35
37
|
"examples/public/images/test.pdf",
|
@@ -63,14 +65,18 @@ Gem::Specification.new do |s|
|
|
63
65
|
"lib/assette/server.rb",
|
64
66
|
"lib/assette/template.rb",
|
65
67
|
"lib/assette/template_set.rb",
|
68
|
+
"lib/assette/view_helper.rb",
|
66
69
|
"spec/assette_spec.rb",
|
67
70
|
"spec/config_spec.rb",
|
68
71
|
"spec/file_spec.rb",
|
72
|
+
"spec/helper_spec.rb",
|
69
73
|
"spec/post_processor_spec.rb",
|
70
74
|
"spec/reader_spec.rb",
|
71
75
|
"spec/server_spec.rb",
|
72
76
|
"spec/spec_helper.rb",
|
73
|
-
"spec/template_spec.rb"
|
77
|
+
"spec/template_spec.rb",
|
78
|
+
"test/helper.rb",
|
79
|
+
"test/test_server.rb"
|
74
80
|
]
|
75
81
|
s.homepage = %q{http://github.com/Talby/assette}
|
76
82
|
s.licenses = ["MIT"]
|
@@ -82,11 +88,14 @@ Gem::Specification.new do |s|
|
|
82
88
|
"spec/assette_spec.rb",
|
83
89
|
"spec/config_spec.rb",
|
84
90
|
"spec/file_spec.rb",
|
91
|
+
"spec/helper_spec.rb",
|
85
92
|
"spec/post_processor_spec.rb",
|
86
93
|
"spec/reader_spec.rb",
|
87
94
|
"spec/server_spec.rb",
|
88
95
|
"spec/spec_helper.rb",
|
89
|
-
"spec/template_spec.rb"
|
96
|
+
"spec/template_spec.rb",
|
97
|
+
"test/helper.rb",
|
98
|
+
"test/test_server.rb"
|
90
99
|
]
|
91
100
|
|
92
101
|
if s.respond_to? :specification_version then
|
@@ -105,6 +114,7 @@ Gem::Specification.new do |s|
|
|
105
114
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
106
115
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
107
116
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
117
|
+
s.add_development_dependency(%q<rack-test>, [">= 0"])
|
108
118
|
s.add_runtime_dependency(%q<rack>, ["~> 1"])
|
109
119
|
s.add_runtime_dependency(%q<thor>, ["~> 0"])
|
110
120
|
s.add_runtime_dependency(%q<json>, [">= 1.4"])
|
@@ -124,6 +134,7 @@ Gem::Specification.new do |s|
|
|
124
134
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
125
135
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
126
136
|
s.add_dependency(%q<rcov>, [">= 0"])
|
137
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
127
138
|
s.add_dependency(%q<rack>, ["~> 1"])
|
128
139
|
s.add_dependency(%q<thor>, ["~> 0"])
|
129
140
|
s.add_dependency(%q<json>, [">= 1.4"])
|
@@ -144,6 +155,7 @@ Gem::Specification.new do |s|
|
|
144
155
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
145
156
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
146
157
|
s.add_dependency(%q<rcov>, [">= 0"])
|
158
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
147
159
|
s.add_dependency(%q<rack>, ["~> 1"])
|
148
160
|
s.add_dependency(%q<thor>, ["~> 0"])
|
149
161
|
s.add_dependency(%q<json>, [">= 1.4"])
|
data/examples/config/assets.rb
CHANGED
data/lib/assette.rb
CHANGED
@@ -19,7 +19,7 @@ MIME::Types.add coffee_type, sass_type
|
|
19
19
|
module Assette
|
20
20
|
extend self
|
21
21
|
CONFIG_WRAPPER = 'ASSETTE CONFIG'
|
22
|
-
VERSION = File.open(File.expand_path(File.dirname(__FILE__)+'/../VERSION')).read
|
22
|
+
VERSION = File.open(File.expand_path(File.dirname(__FILE__)+'/../VERSION')).read.freeze
|
23
23
|
|
24
24
|
def logger
|
25
25
|
@logger ||= Logger.new(STDOUT)
|
@@ -31,6 +31,6 @@ module Assette
|
|
31
31
|
end
|
32
32
|
|
33
33
|
%w{config reader readers post_processor post_processors
|
34
|
-
compiled_file file template_set template}.each do |f|
|
34
|
+
compiled_file file template_set template view_helper}.each do |f|
|
35
35
|
require File.dirname(__FILE__)+'/assette/'+f
|
36
36
|
end
|
data/lib/assette/config.rb
CHANGED
@@ -10,6 +10,10 @@ module Assette
|
|
10
10
|
@config = Assette::Config.load(p)
|
11
11
|
end
|
12
12
|
|
13
|
+
def compiled_path i, path
|
14
|
+
File.join(Assette.config.asset_host(i),Assette.config.compiled_path(path))
|
15
|
+
end
|
16
|
+
|
13
17
|
class Config
|
14
18
|
MULTIPLES = %w{file_path asset_host}.freeze
|
15
19
|
SINGLES = %w{asset_dir templates_path template_format cache_method
|
@@ -26,6 +30,7 @@ module Assette
|
|
26
30
|
|
27
31
|
attr_reader *OPTIONS
|
28
32
|
attr_accessor :compiling, :sha
|
33
|
+
attr_writer :env
|
29
34
|
|
30
35
|
DEFAULTS = {
|
31
36
|
:asset_dir => 'assets',
|
@@ -43,6 +48,33 @@ module Assette
|
|
43
48
|
end
|
44
49
|
end
|
45
50
|
|
51
|
+
def env
|
52
|
+
return @env if @env
|
53
|
+
|
54
|
+
case
|
55
|
+
when defined?(ENVIRONMENT)
|
56
|
+
ENVIRONMENT
|
57
|
+
when defined?(Merb)
|
58
|
+
Merb.env
|
59
|
+
when defined?(Rails)
|
60
|
+
Rails.env
|
61
|
+
else
|
62
|
+
ENV['RACK_ENV'] || ENV['RAILS_ENV']
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def env? e
|
67
|
+
env == e
|
68
|
+
end
|
69
|
+
|
70
|
+
def prod?
|
71
|
+
env == 'production'
|
72
|
+
end
|
73
|
+
|
74
|
+
def dev?
|
75
|
+
!prod?
|
76
|
+
end
|
77
|
+
|
46
78
|
def find_file_from_relative_path path
|
47
79
|
a = Assette.config.file_paths.find do |pp|
|
48
80
|
File.exist?(File.join(pp,path))
|
data/lib/assette/file.rb
CHANGED
@@ -14,7 +14,7 @@ class Assette::File < ::File
|
|
14
14
|
if klass = Assette::Reader::ALL[extension]
|
15
15
|
klass
|
16
16
|
else
|
17
|
-
raise "Can't find reader class Assette::Reader::#{extension.capitalize}"
|
17
|
+
raise Assette::Reader::UnknownReader, "Can't find reader class Assette::Reader::#{extension.capitalize}"
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -27,7 +27,7 @@ class Assette::File < ::File
|
|
27
27
|
if @target_class = Assette::Reader::ALL[ex.to_s]
|
28
28
|
@target_class
|
29
29
|
else
|
30
|
-
raise "Can't find reader class Assette::Reader::#{ex.capitalize}"
|
30
|
+
raise Assette::Reader::UnknownReader, "Can't find reader class Assette::Reader::#{ex.capitalize}"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -35,8 +35,9 @@ class Assette::File < ::File
|
|
35
35
|
@mime_type ||= MIME::Types.type_for(path).first
|
36
36
|
end
|
37
37
|
|
38
|
-
def comment_str
|
39
|
-
target_class.comment_str
|
38
|
+
def comment_str(str = nil)
|
39
|
+
comm = target_class.comment_str
|
40
|
+
str ? (comm % str) : comm
|
40
41
|
end
|
41
42
|
|
42
43
|
def code
|
@@ -45,13 +46,15 @@ class Assette::File < ::File
|
|
45
46
|
target_class.error(e.to_s,path)
|
46
47
|
end
|
47
48
|
|
49
|
+
def template_set
|
50
|
+
Assette::TemplateSet.new(templates)
|
51
|
+
end
|
52
|
+
|
48
53
|
def all_code_array
|
49
54
|
dep = Assette::CompiledFile.new(self)
|
50
55
|
|
51
56
|
if !templates.empty?
|
52
|
-
|
53
|
-
|
54
|
-
dep << set.compile
|
57
|
+
dep << template_set.compile
|
55
58
|
end
|
56
59
|
|
57
60
|
dependencies.each {|d| dep.add_dependency(d)}
|
@@ -62,7 +65,11 @@ class Assette::File < ::File
|
|
62
65
|
end
|
63
66
|
|
64
67
|
def all_code
|
65
|
-
|
68
|
+
if target_class.respond_to? :compile_array
|
69
|
+
target_class.compile_array all_code_array
|
70
|
+
else
|
71
|
+
all_code_array.join("\n")
|
72
|
+
end
|
66
73
|
end
|
67
74
|
|
68
75
|
def dirname
|
@@ -82,6 +89,10 @@ class Assette::File < ::File
|
|
82
89
|
tp
|
83
90
|
end
|
84
91
|
|
92
|
+
def dev_tag
|
93
|
+
target_class.tag "#{relative_target_path}?nodep"
|
94
|
+
end
|
95
|
+
|
85
96
|
def filename
|
86
97
|
File.basename(path)
|
87
98
|
end
|
@@ -172,6 +183,18 @@ class Assette::File < ::File
|
|
172
183
|
end
|
173
184
|
end
|
174
185
|
|
186
|
+
def path_array
|
187
|
+
code = []
|
188
|
+
|
189
|
+
code << "/__templates/#{templates.join(':')}" unless templates.empty?
|
190
|
+
|
191
|
+
code += dependencies.collect do |d|
|
192
|
+
d.relative_target_path
|
193
|
+
end
|
194
|
+
|
195
|
+
code << relative_target_path
|
196
|
+
end
|
197
|
+
|
175
198
|
class << self
|
176
199
|
|
177
200
|
def all_code_for *args
|
@@ -182,20 +205,20 @@ class Assette::File < ::File
|
|
182
205
|
code << f.comment_str % "Time taken to generate: #{Time.now-start}s"
|
183
206
|
end
|
184
207
|
|
208
|
+
# This code is aweful. gotta fix it
|
209
|
+
#shitty
|
185
210
|
def rack_resp_if_exists path, opts = {}
|
186
211
|
return unless File.exist?(path)
|
187
212
|
start = Time.now
|
188
213
|
f = open(path)
|
189
214
|
|
190
215
|
if opts[:deparr]
|
191
|
-
code = f.
|
192
|
-
d.relative_target_path
|
193
|
-
end
|
194
|
-
|
195
|
-
code << f.relative_target_path
|
216
|
+
code = f.path_array
|
196
217
|
|
197
218
|
resp = {:dependencies => code, :target_type => f.target_class.mime_type, :target_extension => f.extension}
|
198
219
|
|
220
|
+
resp[:generation_time] = Time.now-start
|
221
|
+
|
199
222
|
return [200,{"Content-Type" => 'text/javascript'}, [resp.to_json]]
|
200
223
|
end
|
201
224
|
|
@@ -1,18 +1,20 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Assette
|
2
|
+
class PostProcessor::CacheBuster < Assette::PostProcessor(:css)
|
3
|
+
URL_MATCHER = /url\((?:["'])?(?!http)(?!\/\/)([\w\/\.\-\s\?=]+)(?:["'])?\)/i
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def should_process?
|
6
|
+
Assette.config.compiling?
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
def processor
|
10
|
+
@@i ||= -1
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
@str.gsub(URL_MATCHER) do |s|
|
13
|
+
url = Assette.compiled_path @@i+=1, $1
|
13
14
|
|
14
|
-
|
15
|
+
%Q{url("#{url}")}
|
16
|
+
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
19
|
+
end
|
18
20
|
end
|
data/lib/assette/reader.rb
CHANGED
@@ -3,6 +3,7 @@ module Assette
|
|
3
3
|
extend self
|
4
4
|
OUTPUTS = Hash.new {|h,k| h[k] = []}
|
5
5
|
ALL = {}
|
6
|
+
OUTPUT_MAP = {}
|
6
7
|
|
7
8
|
def possible_targets path
|
8
9
|
match = path.match(/(.+\.)([a-z]+)$/i)
|
@@ -13,6 +14,10 @@ module Assette
|
|
13
14
|
OUTPUTS[ext.to_sym].collect { |cla| file + cla.extension }
|
14
15
|
end
|
15
16
|
|
17
|
+
def target_class ex
|
18
|
+
Assette::Reader::ALL[Assette::Reader::OUTPUT_MAP[ex]]
|
19
|
+
end
|
20
|
+
|
16
21
|
class Base
|
17
22
|
attr_reader :file
|
18
23
|
def initialize(file)
|
@@ -74,6 +79,7 @@ module Assette
|
|
74
79
|
|
75
80
|
if ex = extension
|
76
81
|
Assette::Reader::ALL[ex] = self
|
82
|
+
Assette::Reader::OUTPUT_MAP[ex] = outputs.to_s
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
@@ -85,6 +91,7 @@ module Assette
|
|
85
91
|
|
86
92
|
end
|
87
93
|
|
94
|
+
class UnknownReader < StandardError; end
|
88
95
|
end
|
89
96
|
|
90
97
|
def self.Reader(type)
|
data/lib/assette/readers.rb
CHANGED
data/lib/assette/readers/css.rb
CHANGED
data/lib/assette/readers/js.rb
CHANGED
data/lib/assette/server.rb
CHANGED
@@ -73,7 +73,17 @@ module Assette
|
|
73
73
|
f
|
74
74
|
end
|
75
75
|
|
76
|
+
def looking_for_template?
|
77
|
+
m = path.match /__templates\/(.+)/
|
78
|
+
m[1].gsub(/.js$/,'').split(':') if m
|
79
|
+
end
|
80
|
+
|
76
81
|
def rack_resp
|
82
|
+
if templates = looking_for_template?
|
83
|
+
set = TemplateSet.new(templates)
|
84
|
+
return [200,{"Content-Type" => Reader::Js.mime_type.content_type},[set.compile]]
|
85
|
+
end
|
86
|
+
|
77
87
|
if has_registered_reader? && (f = find_compiled_file)
|
78
88
|
f
|
79
89
|
elsif f = find_file
|
data/lib/assette/template_set.rb
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
module Assette
|
2
|
+
#shitty
|
3
|
+
def preloader_file
|
4
|
+
p = Assette.config.template_preloader
|
5
|
+
pp = Assette.config.find_file_from_relative_path(p) if p
|
6
|
+
Assette::File.open(pp) if pp
|
7
|
+
end
|
8
|
+
|
9
|
+
#shitty
|
10
|
+
def preloader_code
|
11
|
+
pp = preloader_file
|
12
|
+
pp.all_code if pp
|
13
|
+
end
|
2
14
|
|
3
15
|
class TemplateSet
|
4
16
|
attr_reader :templates
|
@@ -36,14 +48,7 @@ module Assette
|
|
36
48
|
end
|
37
49
|
end
|
38
50
|
|
39
|
-
def
|
40
|
-
p = Assette.config.template_preloader
|
41
|
-
if p && pp = Assette.config.find_file_from_relative_path(p)
|
42
|
-
Assette::File.open(pp).all_code
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def compile
|
51
|
+
def compile(opts={})
|
47
52
|
coffee = Array.new
|
48
53
|
|
49
54
|
vars = storage_variable
|
@@ -67,7 +72,7 @@ module Assette
|
|
67
72
|
end
|
68
73
|
|
69
74
|
t = Assette::Reader::Coffee.compile_str(coffee.join("\n"))
|
70
|
-
pre =
|
75
|
+
pre = Assette.preloader_code unless opts[:no_preloader]
|
71
76
|
pre ? [pre,t].join("\n") : t
|
72
77
|
end
|
73
78
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Assette
|
2
|
+
module ViewHelper
|
3
|
+
|
4
|
+
module Development
|
5
|
+
def asset_tag file
|
6
|
+
output = ["<!-- Assets for #{file} -->"]
|
7
|
+
real_path = Assette.config.find_file_from_relative_path(file)
|
8
|
+
f = Assette::File.open(real_path)
|
9
|
+
|
10
|
+
output << Assette::Reader::Js.tag("/__templates/#{f.templates.join(':')}") unless f.templates.empty?
|
11
|
+
|
12
|
+
f.dependencies.each do |d|
|
13
|
+
output << d.dev_tag
|
14
|
+
end
|
15
|
+
output << f.dev_tag
|
16
|
+
|
17
|
+
output << "<!-- END #{file} -->"
|
18
|
+
|
19
|
+
output.join("\n")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Production
|
24
|
+
ASSET_TAGS = Hash.new
|
25
|
+
|
26
|
+
# Store the path name for each asset so to speed up things a little and to make sure it's alwasy getting the smae host
|
27
|
+
def asset_tag file
|
28
|
+
ASSET_TAGS[file] ||= __asset_tag(file)
|
29
|
+
end
|
30
|
+
|
31
|
+
def __asset_tag file
|
32
|
+
ex = file.match(/\.(\w+)$/)
|
33
|
+
if ex && target_class = Assette::Reader.target_class(ex[1])
|
34
|
+
@__asset_iterator ||= -1 # Conerns about whether this will get re_instantiated on each request must investigate
|
35
|
+
|
36
|
+
file.gsub!(/\.(\w+)$/) do |s|
|
37
|
+
".#{Assette::Reader::OUTPUT_MAP[$1]}"
|
38
|
+
end
|
39
|
+
|
40
|
+
url = Assette.compiled_path @__asset_iterator+=1, file
|
41
|
+
|
42
|
+
target_class.tag url
|
43
|
+
else
|
44
|
+
<<-HTML
|
45
|
+
<!-- Can't find file or reader for #{file.inspect}-->
|
46
|
+
HTML
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.included receiver
|
52
|
+
if Assette.config.prod?
|
53
|
+
receiver.send :include, Production
|
54
|
+
else
|
55
|
+
receiver.send :include, Development
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
data/spec/helper_spec.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Assette::ViewHelper do
|
4
|
+
|
5
|
+
after(:all) do
|
6
|
+
Dir.chdir(@dir_before)
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
@dir_before = Dir.pwd
|
11
|
+
Dir.chdir(File.dirname(__FILE__) + '/../examples')
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Assette::ViewHelper::Development do
|
15
|
+
before :all do
|
16
|
+
Assette.config.env = 'development'
|
17
|
+
|
18
|
+
class DevHelper
|
19
|
+
include Assette::ViewHelper
|
20
|
+
end
|
21
|
+
|
22
|
+
@dev = DevHelper.new
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be a development helper" do
|
26
|
+
@dev.should be_a Assette::ViewHelper::Development
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return dev tag" do
|
30
|
+
tag = @dev.asset_tag 'javascripts/test.coffee'
|
31
|
+
tag.should include '<script src="/__templates/foo" type="text/javascript"></script>'
|
32
|
+
tag.should include '<script src="/javascripts/one.js?nodep" type="text/javascript"></script>'
|
33
|
+
tag.should include '<script src="/javascripts/test.js?nodep" type="text/javascript"></script>'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe Assette::ViewHelper::Production do
|
38
|
+
before :all do
|
39
|
+
Assette.config.env = 'production'
|
40
|
+
|
41
|
+
class ProdHelper
|
42
|
+
include Assette::ViewHelper
|
43
|
+
attr_reader :__asset_iterator
|
44
|
+
end
|
45
|
+
|
46
|
+
@prod = ProdHelper.new
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should be a production helper" do
|
50
|
+
@prod.should be_a Assette::ViewHelper::Production
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return prod tag" do
|
54
|
+
tag = @prod.asset_tag 'javascripts/test.coffee'
|
55
|
+
tag.strip.should == '<script src="http://cdn1.gilt.com/javascripts/test.js" type="text/javascript"></script>'
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "cachebusting" do
|
59
|
+
before :all do
|
60
|
+
@pre_sha = Assette.config.sha
|
61
|
+
Assette.config.sha = @sha = '1234567890abcdef'
|
62
|
+
end
|
63
|
+
|
64
|
+
after :all do
|
65
|
+
Assette.config.sha = @pre_sha
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should use path" do
|
69
|
+
Assette.config.instance_variable_set(:@cache_method,'path')
|
70
|
+
tag = @prod.asset_tag 'javascripts/test2.coffee'
|
71
|
+
tag.strip.should include %Q{.gilt.com/#{@sha}/javascripts/test2.js}
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should use param" do
|
75
|
+
Assette.config.instance_variable_set(:@cache_method,'param')
|
76
|
+
tag = @prod.asset_tag 'javascripts/test3.coffee'
|
77
|
+
tag.strip.should include %Q{gilt.com/javascripts/test3.js?v=#{@sha}}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "caching" do
|
82
|
+
before do
|
83
|
+
@prod2 = ProdHelper.new
|
84
|
+
@prod3 = ProdHelper.new
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should only generate a link the first time" do
|
88
|
+
@prod2.should_not_receive(:__asset_tag)
|
89
|
+
file = 'javascripts/asdfasdf.coffee'
|
90
|
+
tag = @prod.asset_tag file
|
91
|
+
tag2 = @prod2.asset_tag file
|
92
|
+
|
93
|
+
tag.should == tag2
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/test/helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
14
|
+
require 'assette'
|
15
|
+
|
16
|
+
Assette.logger.level = Logger::WARN
|
17
|
+
|
18
|
+
Dir.chdir(File.join(File.dirname(__FILE__),'../examples/'))
|
19
|
+
|
20
|
+
class Test::Unit::TestCase
|
21
|
+
end
|
data/test/test_server.rb
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'rack/test'
|
3
|
+
require 'assette/server'
|
4
|
+
|
5
|
+
class ServerTest < Test::Unit::TestCase
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
def app
|
9
|
+
Assette::Server
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_test_coffee
|
13
|
+
get "/javascripts/test.js"
|
14
|
+
|
15
|
+
assert last_response.ok?
|
16
|
+
is_js?
|
17
|
+
has_pre_template
|
18
|
+
has_foo_template
|
19
|
+
has_bar_template false
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_nodep
|
23
|
+
get "/javascripts/test.js?nodep"
|
24
|
+
|
25
|
+
assert last_response.ok?
|
26
|
+
is_js?
|
27
|
+
has_pre_template false
|
28
|
+
has_foo_template false
|
29
|
+
has_bar_template false
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_two_scss
|
33
|
+
get '/stylesheets/two2.css'
|
34
|
+
|
35
|
+
assert last_response.ok?
|
36
|
+
is_css?
|
37
|
+
assert_match /#foo3/, last_response.body
|
38
|
+
assert_match /#one/, last_response.body
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_all_template
|
42
|
+
get '/__templates/all'
|
43
|
+
|
44
|
+
assert last_response.ok?
|
45
|
+
is_js?
|
46
|
+
has_pre_template
|
47
|
+
has_foo_template
|
48
|
+
has_bar_template
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_all_template2
|
52
|
+
get '/__templates/foo:bar'
|
53
|
+
|
54
|
+
assert last_response.ok?
|
55
|
+
is_js?
|
56
|
+
has_pre_template
|
57
|
+
has_foo_template
|
58
|
+
has_bar_template
|
59
|
+
|
60
|
+
get '/__templates/bar:foo.js'
|
61
|
+
|
62
|
+
assert last_response.ok?
|
63
|
+
is_js?
|
64
|
+
has_pre_template
|
65
|
+
has_foo_template
|
66
|
+
has_bar_template
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_foo_template
|
70
|
+
get '/__templates/foo'
|
71
|
+
|
72
|
+
assert last_response.ok?
|
73
|
+
is_js?
|
74
|
+
has_pre_template
|
75
|
+
has_foo_template
|
76
|
+
has_bar_template false
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_bar_template
|
80
|
+
get '/__templates/bar.js'
|
81
|
+
|
82
|
+
assert last_response.ok?
|
83
|
+
is_js?
|
84
|
+
has_pre_template
|
85
|
+
has_foo_template false
|
86
|
+
has_bar_template
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_getting_js_dependencies
|
90
|
+
get "/javascripts/test.js?deparr"
|
91
|
+
json = nil
|
92
|
+
assert_nothing_raised do
|
93
|
+
json = JSON.parse(last_response.body)
|
94
|
+
end
|
95
|
+
|
96
|
+
assert json['dependencies'].is_a?(Array)
|
97
|
+
assert_equal json['target_type'], 'application/javascript'
|
98
|
+
assert json['dependencies'].include?('/__templates/foo')
|
99
|
+
assert json['dependencies'].include?('/javascripts/one.js')
|
100
|
+
assert json['dependencies'].include?('/javascripts/test.js')
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_getting_js_dependencies
|
104
|
+
get '/stylesheets/two2.css?deparr'
|
105
|
+
json = nil
|
106
|
+
assert_nothing_raised do
|
107
|
+
json = JSON.parse(last_response.body)
|
108
|
+
end
|
109
|
+
|
110
|
+
assert json['dependencies'].is_a?(Array)
|
111
|
+
assert_equal json['target_type'], 'text/css'
|
112
|
+
assert json['dependencies'].include?('/stylesheets/two2.css')
|
113
|
+
|
114
|
+
|
115
|
+
get '/stylesheets/two.css?deparr'
|
116
|
+
json = JSON.parse(last_response.body)
|
117
|
+
|
118
|
+
assert json['dependencies'].is_a?(Array)
|
119
|
+
assert_equal json['target_type'], 'text/css'
|
120
|
+
assert_equal json['dependencies'], ['/stylesheets/one.css','/stylesheets/two.css']
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def is_js?
|
126
|
+
assert_equal last_response.content_type, 'application/javascript'
|
127
|
+
end
|
128
|
+
|
129
|
+
def is_css?
|
130
|
+
assert_equal last_response.content_type, 'text/css'
|
131
|
+
end
|
132
|
+
|
133
|
+
def has_pre_template(tf = true)
|
134
|
+
has_or_not tf, /Handlebars\.registerPartial =/, last_response.body
|
135
|
+
end
|
136
|
+
|
137
|
+
def has_foo_template(tf = true)
|
138
|
+
has_or_not tf, /GC\.foo\.t\["foo\/index"\]/, last_response.body
|
139
|
+
end
|
140
|
+
|
141
|
+
def has_bar_template(tf = true)
|
142
|
+
has_or_not tf, /GC\.foo\.t\["bar\/index"\]/, last_response.body
|
143
|
+
end
|
144
|
+
|
145
|
+
def has_or_not(tf, *args)
|
146
|
+
args.flatten!
|
147
|
+
if tf
|
148
|
+
assert_match(*args)
|
149
|
+
else
|
150
|
+
assert_no_match(*args)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assette
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tal Atlas
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-06-14 00:00:00 -04:00
|
19
19
|
default_executable: assette
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -198,8 +198,22 @@ dependencies:
|
|
198
198
|
type: :development
|
199
199
|
requirement: *id012
|
200
200
|
- !ruby/object:Gem::Dependency
|
201
|
-
name: rack
|
201
|
+
name: rack-test
|
202
202
|
version_requirements: &id013 !ruby/object:Gem::Requirement
|
203
|
+
none: false
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
hash: 3
|
208
|
+
segments:
|
209
|
+
- 0
|
210
|
+
version: "0"
|
211
|
+
prerelease: false
|
212
|
+
type: :development
|
213
|
+
requirement: *id013
|
214
|
+
- !ruby/object:Gem::Dependency
|
215
|
+
name: rack
|
216
|
+
version_requirements: &id014 !ruby/object:Gem::Requirement
|
203
217
|
none: false
|
204
218
|
requirements:
|
205
219
|
- - ~>
|
@@ -210,10 +224,10 @@ dependencies:
|
|
210
224
|
version: "1"
|
211
225
|
prerelease: false
|
212
226
|
type: :runtime
|
213
|
-
requirement: *
|
227
|
+
requirement: *id014
|
214
228
|
- !ruby/object:Gem::Dependency
|
215
229
|
name: thor
|
216
|
-
version_requirements: &
|
230
|
+
version_requirements: &id015 !ruby/object:Gem::Requirement
|
217
231
|
none: false
|
218
232
|
requirements:
|
219
233
|
- - ~>
|
@@ -224,10 +238,10 @@ dependencies:
|
|
224
238
|
version: "0"
|
225
239
|
prerelease: false
|
226
240
|
type: :runtime
|
227
|
-
requirement: *
|
241
|
+
requirement: *id015
|
228
242
|
- !ruby/object:Gem::Dependency
|
229
243
|
name: json
|
230
|
-
version_requirements: &
|
244
|
+
version_requirements: &id016 !ruby/object:Gem::Requirement
|
231
245
|
none: false
|
232
246
|
requirements:
|
233
247
|
- - ">="
|
@@ -239,10 +253,10 @@ dependencies:
|
|
239
253
|
version: "1.4"
|
240
254
|
prerelease: false
|
241
255
|
type: :runtime
|
242
|
-
requirement: *
|
256
|
+
requirement: *id016
|
243
257
|
- !ruby/object:Gem::Dependency
|
244
258
|
name: sass
|
245
|
-
version_requirements: &
|
259
|
+
version_requirements: &id017 !ruby/object:Gem::Requirement
|
246
260
|
none: false
|
247
261
|
requirements:
|
248
262
|
- - ">="
|
@@ -254,10 +268,10 @@ dependencies:
|
|
254
268
|
version: "3.1"
|
255
269
|
prerelease: false
|
256
270
|
type: :runtime
|
257
|
-
requirement: *
|
271
|
+
requirement: *id017
|
258
272
|
- !ruby/object:Gem::Dependency
|
259
273
|
name: coffee-script
|
260
|
-
version_requirements: &
|
274
|
+
version_requirements: &id018 !ruby/object:Gem::Requirement
|
261
275
|
none: false
|
262
276
|
requirements:
|
263
277
|
- - ~>
|
@@ -268,10 +282,10 @@ dependencies:
|
|
268
282
|
version: "2"
|
269
283
|
prerelease: false
|
270
284
|
type: :runtime
|
271
|
-
requirement: *
|
285
|
+
requirement: *id018
|
272
286
|
- !ruby/object:Gem::Dependency
|
273
287
|
name: mime-types
|
274
|
-
version_requirements: &
|
288
|
+
version_requirements: &id019 !ruby/object:Gem::Requirement
|
275
289
|
none: false
|
276
290
|
requirements:
|
277
291
|
- - ">="
|
@@ -283,7 +297,7 @@ dependencies:
|
|
283
297
|
version: "1.16"
|
284
298
|
prerelease: false
|
285
299
|
type: :runtime
|
286
|
-
requirement: *
|
300
|
+
requirement: *id019
|
287
301
|
description: Renders all asset types (coffeescript/sass/scss) as equals
|
288
302
|
email: me@tal.by
|
289
303
|
executables:
|
@@ -295,6 +309,7 @@ extra_rdoc_files:
|
|
295
309
|
- README.rdoc
|
296
310
|
files:
|
297
311
|
- .document
|
312
|
+
- .irbrc
|
298
313
|
- .rspec
|
299
314
|
- Gemfile
|
300
315
|
- Gemfile.lock
|
@@ -305,6 +320,7 @@ files:
|
|
305
320
|
- assette.gemspec
|
306
321
|
- bin/assette
|
307
322
|
- examples/config/assets.rb
|
323
|
+
- examples/myapp/templates/bar/index.html.mustache
|
308
324
|
- examples/myapp/templates/foo/_partial.html.mustache
|
309
325
|
- examples/myapp/templates/foo/index.html.mustache
|
310
326
|
- examples/public/images/test.pdf
|
@@ -338,14 +354,18 @@ files:
|
|
338
354
|
- lib/assette/server.rb
|
339
355
|
- lib/assette/template.rb
|
340
356
|
- lib/assette/template_set.rb
|
357
|
+
- lib/assette/view_helper.rb
|
341
358
|
- spec/assette_spec.rb
|
342
359
|
- spec/config_spec.rb
|
343
360
|
- spec/file_spec.rb
|
361
|
+
- spec/helper_spec.rb
|
344
362
|
- spec/post_processor_spec.rb
|
345
363
|
- spec/reader_spec.rb
|
346
364
|
- spec/server_spec.rb
|
347
365
|
- spec/spec_helper.rb
|
348
366
|
- spec/template_spec.rb
|
367
|
+
- test/helper.rb
|
368
|
+
- test/test_server.rb
|
349
369
|
has_rdoc: true
|
350
370
|
homepage: http://github.com/Talby/assette
|
351
371
|
licenses:
|
@@ -385,8 +405,11 @@ test_files:
|
|
385
405
|
- spec/assette_spec.rb
|
386
406
|
- spec/config_spec.rb
|
387
407
|
- spec/file_spec.rb
|
408
|
+
- spec/helper_spec.rb
|
388
409
|
- spec/post_processor_spec.rb
|
389
410
|
- spec/reader_spec.rb
|
390
411
|
- spec/server_spec.rb
|
391
412
|
- spec/spec_helper.rb
|
392
413
|
- spec/template_spec.rb
|
414
|
+
- test/helper.rb
|
415
|
+
- test/test_server.rb
|