assette 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/assette.gemspec +10 -9
- data/bin/assette +0 -0
- data/lib/assette/cli.rb +6 -0
- data/lib/assette/config.rb +1 -1
- data/lib/assette/file.rb +41 -3
- data/lib/assette/middleware.rb +22 -0
- data/lib/assette/readers/css.rb +19 -0
- data/lib/assette/readers/js.rb +12 -0
- data/lib/assette/readers/sass.rb +2 -2
- data/lib/assette/server.rb +20 -3
- data/lib/assette.rb +10 -0
- metadata +14 -11
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -8,7 +8,6 @@ GEM
|
|
8
8
|
diff-lcs (1.1.2)
|
9
9
|
execjs (0.1.0)
|
10
10
|
git (1.2.5)
|
11
|
-
haml (3.0.25)
|
12
11
|
jeweler (1.5.2)
|
13
12
|
bundler (~> 1.0.0)
|
14
13
|
git (>= 1.2.5)
|
@@ -26,6 +25,7 @@ GEM
|
|
26
25
|
rspec-expectations (2.4.0)
|
27
26
|
diff-lcs (~> 1.1.2)
|
28
27
|
rspec-mocks (2.4.0)
|
28
|
+
sass (3.1.1)
|
29
29
|
thor (0.14.6)
|
30
30
|
yard (0.6.4)
|
31
31
|
|
@@ -36,12 +36,12 @@ DEPENDENCIES
|
|
36
36
|
bundler (~> 1.0.0)
|
37
37
|
coffee-script (~> 2)
|
38
38
|
git
|
39
|
-
haml (~> 3)
|
40
39
|
jeweler (~> 1.5.2)
|
41
40
|
json (>= 1.4)
|
42
41
|
mime-types (>= 1.16)
|
43
42
|
rack (~> 1)
|
44
43
|
rcov
|
45
44
|
rspec (~> 2.4.0)
|
45
|
+
sass (>= 3.1)
|
46
46
|
thor (~> 0)
|
47
47
|
yard (~> 0.6.0)
|
data/Rakefile
CHANGED
@@ -24,7 +24,7 @@ Jeweler::Tasks.new do |gem|
|
|
24
24
|
gem.add_runtime_dependency "rack", '~> 1'
|
25
25
|
gem.add_runtime_dependency "thor", '~> 0'
|
26
26
|
gem.add_runtime_dependency "json", '>= 1.4'
|
27
|
-
gem.add_runtime_dependency "
|
27
|
+
gem.add_runtime_dependency "sass", '>= 3.1'
|
28
28
|
gem.add_runtime_dependency "coffee-script", '~> 2'
|
29
29
|
# gem.add_runtime_dependency "git"
|
30
30
|
gem.add_runtime_dependency "mime-types", ">= 1.16"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
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.2"
|
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-05-07}
|
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}
|
@@ -48,6 +48,7 @@ Gem::Specification.new do |s|
|
|
48
48
|
"lib/assette/compiled_file.rb",
|
49
49
|
"lib/assette/config.rb",
|
50
50
|
"lib/assette/file.rb",
|
51
|
+
"lib/assette/middleware.rb",
|
51
52
|
"lib/assette/post_processor.rb",
|
52
53
|
"lib/assette/post_processors.rb",
|
53
54
|
"lib/assette/post_processors/cache_buster.rb",
|
@@ -74,7 +75,7 @@ Gem::Specification.new do |s|
|
|
74
75
|
s.homepage = %q{http://github.com/Talby/assette}
|
75
76
|
s.licenses = ["MIT"]
|
76
77
|
s.require_paths = ["lib"]
|
77
|
-
s.rubygems_version = %q{1.5.
|
78
|
+
s.rubygems_version = %q{1.5.0}
|
78
79
|
s.summary = %q{Treat all assets as equal}
|
79
80
|
s.test_files = [
|
80
81
|
"examples/config/assets.rb",
|
@@ -95,7 +96,7 @@ Gem::Specification.new do |s|
|
|
95
96
|
s.add_runtime_dependency(%q<rack>, ["~> 1"])
|
96
97
|
s.add_runtime_dependency(%q<thor>, ["~> 0"])
|
97
98
|
s.add_runtime_dependency(%q<json>, [">= 1.4"])
|
98
|
-
s.add_runtime_dependency(%q<
|
99
|
+
s.add_runtime_dependency(%q<sass>, [">= 3.1"])
|
99
100
|
s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
|
100
101
|
s.add_runtime_dependency(%q<git>, [">= 0"])
|
101
102
|
s.add_runtime_dependency(%q<coffee-script>, ["~> 2"])
|
@@ -107,14 +108,14 @@ Gem::Specification.new do |s|
|
|
107
108
|
s.add_runtime_dependency(%q<rack>, ["~> 1"])
|
108
109
|
s.add_runtime_dependency(%q<thor>, ["~> 0"])
|
109
110
|
s.add_runtime_dependency(%q<json>, [">= 1.4"])
|
110
|
-
s.add_runtime_dependency(%q<
|
111
|
+
s.add_runtime_dependency(%q<sass>, [">= 3.1"])
|
111
112
|
s.add_runtime_dependency(%q<coffee-script>, ["~> 2"])
|
112
113
|
s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
|
113
114
|
else
|
114
115
|
s.add_dependency(%q<rack>, ["~> 1"])
|
115
116
|
s.add_dependency(%q<thor>, ["~> 0"])
|
116
117
|
s.add_dependency(%q<json>, [">= 1.4"])
|
117
|
-
s.add_dependency(%q<
|
118
|
+
s.add_dependency(%q<sass>, [">= 3.1"])
|
118
119
|
s.add_dependency(%q<mime-types>, [">= 1.16"])
|
119
120
|
s.add_dependency(%q<git>, [">= 0"])
|
120
121
|
s.add_dependency(%q<coffee-script>, ["~> 2"])
|
@@ -126,7 +127,7 @@ Gem::Specification.new do |s|
|
|
126
127
|
s.add_dependency(%q<rack>, ["~> 1"])
|
127
128
|
s.add_dependency(%q<thor>, ["~> 0"])
|
128
129
|
s.add_dependency(%q<json>, [">= 1.4"])
|
129
|
-
s.add_dependency(%q<
|
130
|
+
s.add_dependency(%q<sass>, [">= 3.1"])
|
130
131
|
s.add_dependency(%q<coffee-script>, ["~> 2"])
|
131
132
|
s.add_dependency(%q<mime-types>, [">= 1.16"])
|
132
133
|
end
|
@@ -134,7 +135,7 @@ Gem::Specification.new do |s|
|
|
134
135
|
s.add_dependency(%q<rack>, ["~> 1"])
|
135
136
|
s.add_dependency(%q<thor>, ["~> 0"])
|
136
137
|
s.add_dependency(%q<json>, [">= 1.4"])
|
137
|
-
s.add_dependency(%q<
|
138
|
+
s.add_dependency(%q<sass>, [">= 3.1"])
|
138
139
|
s.add_dependency(%q<mime-types>, [">= 1.16"])
|
139
140
|
s.add_dependency(%q<git>, [">= 0"])
|
140
141
|
s.add_dependency(%q<coffee-script>, ["~> 2"])
|
@@ -146,7 +147,7 @@ Gem::Specification.new do |s|
|
|
146
147
|
s.add_dependency(%q<rack>, ["~> 1"])
|
147
148
|
s.add_dependency(%q<thor>, ["~> 0"])
|
148
149
|
s.add_dependency(%q<json>, [">= 1.4"])
|
149
|
-
s.add_dependency(%q<
|
150
|
+
s.add_dependency(%q<sass>, [">= 3.1"])
|
150
151
|
s.add_dependency(%q<coffee-script>, ["~> 2"])
|
151
152
|
s.add_dependency(%q<mime-types>, [">= 1.16"])
|
152
153
|
end
|
data/bin/assette
CHANGED
File without changes
|
data/lib/assette/cli.rb
CHANGED
@@ -65,6 +65,12 @@ module Assette
|
|
65
65
|
|
66
66
|
opts[:daemonize] = true
|
67
67
|
opts[:pid] = pid_file
|
68
|
+
else
|
69
|
+
Assette.logger.level = Logger::DEBUG
|
70
|
+
Assette.logger.datetime_format = "%H:%M:%S"
|
71
|
+
Assette.logger.formatter = Proc.new do |severity, datetime, progname, msg|
|
72
|
+
"#{severity}: #{progname} - #{msg}\n"
|
73
|
+
end
|
68
74
|
end
|
69
75
|
|
70
76
|
say "Starting Assette server on port #{opts[:Port]}"
|
data/lib/assette/config.rb
CHANGED
data/lib/assette/file.rb
CHANGED
@@ -41,6 +41,8 @@ class Assette::File < ::File
|
|
41
41
|
|
42
42
|
def code
|
43
43
|
reader_class.new(self).compile
|
44
|
+
rescue => e
|
45
|
+
target_class.error(e.to_s,path)
|
44
46
|
end
|
45
47
|
|
46
48
|
def all_code_array
|
@@ -68,7 +70,16 @@ class Assette::File < ::File
|
|
68
70
|
end
|
69
71
|
|
70
72
|
def target_path
|
71
|
-
File.join(dirname,filename.gsub(reader_class.extension,target_class.extension))
|
73
|
+
File.expand_path(File.join(dirname,filename.gsub(reader_class.extension,target_class.extension)))
|
74
|
+
end
|
75
|
+
|
76
|
+
def relative_target_path
|
77
|
+
tp = target_path
|
78
|
+
Assette.config.file_paths.each do |fp|
|
79
|
+
f = File.expand_path(fp)
|
80
|
+
tp.gsub! f, ''
|
81
|
+
end
|
82
|
+
tp
|
72
83
|
end
|
73
84
|
|
74
85
|
def filename
|
@@ -102,9 +113,12 @@ class Assette::File < ::File
|
|
102
113
|
|
103
114
|
p = ::File.expand_path(::File.join(dirname,m[1]))
|
104
115
|
|
116
|
+
Assette.logger.info("Dependecy Checking") {p}
|
117
|
+
|
105
118
|
# Check for _filename if filename doesn't exist
|
106
119
|
unless ::File.exist?(p)
|
107
120
|
p2 = p.gsub /(.*\/)?(.+)/, '\1_\2'
|
121
|
+
Assette.logger.info("Dependecy Checking") {p2}
|
108
122
|
if ::File.exist?(p2)
|
109
123
|
p = p2
|
110
124
|
else
|
@@ -121,6 +135,8 @@ class Assette::File < ::File
|
|
121
135
|
|
122
136
|
end
|
123
137
|
|
138
|
+
Assette.logger.debug('Dependencies') {"For: #{path}\n#{@dependencies.pretty_inspect}"}
|
139
|
+
|
124
140
|
@dependencies
|
125
141
|
end
|
126
142
|
|
@@ -166,13 +182,35 @@ class Assette::File < ::File
|
|
166
182
|
code << f.comment_str % "Time taken to generate: #{Time.now-start}s"
|
167
183
|
end
|
168
184
|
|
169
|
-
def rack_resp_if_exists path
|
185
|
+
def rack_resp_if_exists path, opts = {}
|
170
186
|
return unless File.exist?(path)
|
171
187
|
start = Time.now
|
172
188
|
f = open(path)
|
173
|
-
|
189
|
+
|
190
|
+
if opts[:deparr]
|
191
|
+
code = f.dependencies.collect do |d|
|
192
|
+
d.relative_target_path
|
193
|
+
end
|
194
|
+
|
195
|
+
code << f.relative_target_path
|
196
|
+
|
197
|
+
resp = {:dependencies => code, :target_type => f.target_class.mime_type, :target_extension => f.extension}
|
198
|
+
|
199
|
+
return [200,{"Content-Type" => 'text/javascript'}, [resp.to_json]]
|
200
|
+
end
|
201
|
+
|
202
|
+
if opts[:nodep]
|
203
|
+
code = [f.code]
|
204
|
+
type = f.target_class.mime_type
|
205
|
+
else
|
206
|
+
code = f.all_code_array
|
207
|
+
type = f.target_class.mime_type
|
208
|
+
end
|
209
|
+
|
174
210
|
code << "\n"
|
175
211
|
code << f.comment_str % "Time taken to generate: #{Time.now-start}s"
|
212
|
+
|
213
|
+
[200,{"Content-Type" => type.content_type},code]
|
176
214
|
end
|
177
215
|
|
178
216
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'assette/server'
|
2
|
+
|
3
|
+
module Assette
|
4
|
+
class Middleware
|
5
|
+
def initialize(app, *args)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
if env['PATH_INFO'] == '/'
|
11
|
+
return @app.call(env)
|
12
|
+
end
|
13
|
+
|
14
|
+
assette_resp = Assette::Server.call(env)
|
15
|
+
if assette_resp[0] == 200
|
16
|
+
assette_resp
|
17
|
+
else
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/assette/readers/css.rb
CHANGED
@@ -6,6 +6,25 @@ class Assette::Reader::Css < Assette::Reader(:css)
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
|
9
|
+
def error str, stack = nil
|
10
|
+
<<-CSS
|
11
|
+
body:before {
|
12
|
+
position: absolute;
|
13
|
+
top: 0px;
|
14
|
+
padding: 10px;
|
15
|
+
font-size: 18px;
|
16
|
+
text-align: center;
|
17
|
+
width: 100%;
|
18
|
+
display: block;
|
19
|
+
content: #{str.inspect};
|
20
|
+
background-color: #992E40;
|
21
|
+
color: white;
|
22
|
+
font-weight:bold;
|
23
|
+
z-index: 9999;
|
24
|
+
}
|
25
|
+
CSS
|
26
|
+
end
|
27
|
+
|
9
28
|
def comment_str
|
10
29
|
'/* %s */'
|
11
30
|
end
|
data/lib/assette/readers/js.rb
CHANGED
@@ -6,6 +6,18 @@ class Assette::Reader::Js < Assette::Reader(:js)
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
|
9
|
+
def error str, path=nil
|
10
|
+
if path
|
11
|
+
<<-JS
|
12
|
+
console.group("Compiling Error in file #{path}");
|
13
|
+
console.error(#{str.to_json});
|
14
|
+
console.groupEnd();
|
15
|
+
JS
|
16
|
+
else
|
17
|
+
"console.error(#{str.to_json});"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
9
21
|
def comment_str
|
10
22
|
'// %s'
|
11
23
|
end
|
data/lib/assette/readers/sass.rb
CHANGED
data/lib/assette/server.rb
CHANGED
@@ -6,6 +6,19 @@ module Assette
|
|
6
6
|
@env = env
|
7
7
|
@path = env["PATH_INFO"]
|
8
8
|
|
9
|
+
@params = env["QUERY_STRING"].split('&').inject({}) do |resp,v|
|
10
|
+
k,v = v.split('=')
|
11
|
+
|
12
|
+
if v == '1' || v.nil?
|
13
|
+
v = true
|
14
|
+
elsif v == '0'
|
15
|
+
v = false
|
16
|
+
end
|
17
|
+
|
18
|
+
resp[k.to_sym] = v
|
19
|
+
resp
|
20
|
+
end
|
21
|
+
|
9
22
|
# Assette.config.asset_path
|
10
23
|
end
|
11
24
|
|
@@ -14,18 +27,21 @@ module Assette
|
|
14
27
|
Assette.config.file_paths.each do |p|
|
15
28
|
|
16
29
|
Assette::Reader.possible_targets(File.join(p,path)).each do |pp|
|
17
|
-
|
30
|
+
Assette.logger.debug('Checking for compiled file') {pp}
|
31
|
+
f = Assette::File.rack_resp_if_exists( pp, @params )
|
32
|
+
Assette.logger.info("Found File") {"Compiled file at #{pp}"} if f
|
18
33
|
break if f
|
19
34
|
end
|
20
35
|
|
21
36
|
break if f
|
22
37
|
end
|
38
|
+
|
23
39
|
f
|
24
40
|
end
|
25
41
|
|
26
42
|
def path_extension
|
27
43
|
m = path.match(/\.(\w+)$/)
|
28
|
-
m[1]
|
44
|
+
m ? m[1] : :none
|
29
45
|
end
|
30
46
|
|
31
47
|
def has_registered_reader?
|
@@ -47,6 +63,7 @@ module Assette
|
|
47
63
|
new_path = File.join(p,path)
|
48
64
|
if File.exist?(new_path)
|
49
65
|
new_path = File.join(Dir.pwd,new_path)
|
66
|
+
Assette.logger.info("Found File") {"Raw file at #{new_path}"}
|
50
67
|
f = Rack::File.new(p).call(@env)
|
51
68
|
end
|
52
69
|
|
@@ -58,7 +75,7 @@ module Assette
|
|
58
75
|
|
59
76
|
def rack_resp
|
60
77
|
if has_registered_reader? && (f = find_compiled_file)
|
61
|
-
|
78
|
+
f
|
62
79
|
elsif f = find_file
|
63
80
|
f
|
64
81
|
else
|
data/lib/assette.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'forwardable'
|
3
3
|
require 'mime/types'
|
4
|
+
require 'logger'
|
5
|
+
require 'pp'
|
4
6
|
|
5
7
|
coffee_type = MIME::Type.new('text/coffeescript') do |t|
|
6
8
|
t.encoding = '8bit'
|
@@ -18,6 +20,14 @@ module Assette
|
|
18
20
|
extend self
|
19
21
|
CONFIG_WRAPPER = 'ASSETTE CONFIG'
|
20
22
|
VERSION = File.open(File.expand_path(File.dirname(__FILE__)+'/../VERSION')).read
|
23
|
+
|
24
|
+
def logger
|
25
|
+
@logger ||= Logger.new(STDOUT)
|
26
|
+
end
|
27
|
+
|
28
|
+
def logger=(l)
|
29
|
+
@logger = l
|
30
|
+
end
|
21
31
|
end
|
22
32
|
|
23
33
|
%w{config reader readers post_processor post_processors
|
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: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
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-05-07 00:00:00 -04:00
|
19
19
|
default_executable: assette
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -62,16 +62,17 @@ dependencies:
|
|
62
62
|
type: :runtime
|
63
63
|
requirement: *id003
|
64
64
|
- !ruby/object:Gem::Dependency
|
65
|
-
name:
|
65
|
+
name: sass
|
66
66
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
67
67
|
none: false
|
68
68
|
requirements:
|
69
|
-
- -
|
69
|
+
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
hash: 5
|
72
72
|
segments:
|
73
73
|
- 3
|
74
|
-
|
74
|
+
- 1
|
75
|
+
version: "3.1"
|
75
76
|
prerelease: false
|
76
77
|
type: :runtime
|
77
78
|
requirement: *id004
|
@@ -240,16 +241,17 @@ dependencies:
|
|
240
241
|
type: :runtime
|
241
242
|
requirement: *id015
|
242
243
|
- !ruby/object:Gem::Dependency
|
243
|
-
name:
|
244
|
+
name: sass
|
244
245
|
version_requirements: &id016 !ruby/object:Gem::Requirement
|
245
246
|
none: false
|
246
247
|
requirements:
|
247
|
-
- -
|
248
|
+
- - ">="
|
248
249
|
- !ruby/object:Gem::Version
|
249
250
|
hash: 5
|
250
251
|
segments:
|
251
252
|
- 3
|
252
|
-
|
253
|
+
- 1
|
254
|
+
version: "3.1"
|
253
255
|
prerelease: false
|
254
256
|
type: :runtime
|
255
257
|
requirement: *id016
|
@@ -321,6 +323,7 @@ files:
|
|
321
323
|
- lib/assette/compiled_file.rb
|
322
324
|
- lib/assette/config.rb
|
323
325
|
- lib/assette/file.rb
|
326
|
+
- lib/assette/middleware.rb
|
324
327
|
- lib/assette/post_processor.rb
|
325
328
|
- lib/assette/post_processors.rb
|
326
329
|
- lib/assette/post_processors/cache_buster.rb
|
@@ -373,7 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
373
376
|
requirements: []
|
374
377
|
|
375
378
|
rubyforge_project:
|
376
|
-
rubygems_version: 1.5.
|
379
|
+
rubygems_version: 1.5.0
|
377
380
|
signing_key:
|
378
381
|
specification_version: 3
|
379
382
|
summary: Treat all assets as equal
|