assette 0.0.0
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/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +36 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +43 -0
- data/VERSION +1 -0
- data/assette.gemspec +113 -0
- data/examples/app/templates/foo/index.html.mustache +3 -0
- data/examples/config.ru +7 -0
- data/examples/defaults.rb +5 -0
- data/examples/defaults.yml +7 -0
- data/examples/public/images/test.pdf +0 -0
- data/examples/public/javascripts/foo.js +6 -0
- data/examples/public/javascripts/one.js +1 -0
- data/examples/public/javascripts/test.coffee +5 -0
- data/examples/public/javascripts/three.js +5 -0
- data/examples/public/javascripts/two.js +6 -0
- data/examples/public/stylesheets/one.css +1 -0
- data/examples/public/stylesheets/one1.sass +2 -0
- data/examples/public/stylesheets/two.css +7 -0
- data/examples/public/stylesheets/two2.scss +5 -0
- data/lib/assette.rb +24 -0
- data/lib/assette/compiled_file.rb +36 -0
- data/lib/assette/config.rb +35 -0
- data/lib/assette/file.rb +176 -0
- data/lib/assette/reader.rb +96 -0
- data/lib/assette/readers.rb +4 -0
- data/lib/assette/readers/coffee.rb +31 -0
- data/lib/assette/readers/css.rb +14 -0
- data/lib/assette/readers/js.rb +13 -0
- data/lib/assette/readers/sass.rb +18 -0
- data/lib/assette/readers/scss.rb +9 -0
- data/lib/assette/server.rb +83 -0
- data/lib/assette/template.rb +21 -0
- data/lib/assette/template_set.rb +76 -0
- data/spec/assette_spec.rb +5 -0
- data/spec/file_spec.rb +97 -0
- data/spec/reader_spec.rb +41 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/template_spec.rb +43 -0
- metadata +249 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
module Assette
|
2
|
+
|
3
|
+
class Template < Assette::File
|
4
|
+
def compile
|
5
|
+
format = Assette.config.template_format.dup
|
6
|
+
|
7
|
+
format.gsub!('{*path*}',local_path.to_json)
|
8
|
+
format.gsub!('{*template*}',stringify_body)
|
9
|
+
end
|
10
|
+
|
11
|
+
def stringify_body
|
12
|
+
%Q{"""#{read}"""}
|
13
|
+
end
|
14
|
+
|
15
|
+
def local_path
|
16
|
+
lp = path.gsub(Assette.config.templates_path,'')
|
17
|
+
lp.gsub!(/((\.html)?\.\w+)$/,'')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Assette
|
2
|
+
|
3
|
+
class TemplateSet
|
4
|
+
attr_reader :templates
|
5
|
+
|
6
|
+
def initialize *location
|
7
|
+
if location.size == 1
|
8
|
+
location = location.pop
|
9
|
+
end
|
10
|
+
|
11
|
+
if location.is_a?(Array)
|
12
|
+
location = 'all' if location.include?(:all) || location.include?('all')
|
13
|
+
else
|
14
|
+
location = location.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
path = Assette.config.templates_path
|
18
|
+
|
19
|
+
if location == 'all'
|
20
|
+
dirs = [File.join(path,'*')]
|
21
|
+
elsif location.is_a?(Array)
|
22
|
+
dirs = location.collect do |l|
|
23
|
+
File.join(path,l)
|
24
|
+
end
|
25
|
+
else
|
26
|
+
dirs = [File.join(path,location)]
|
27
|
+
end
|
28
|
+
|
29
|
+
@paths = []
|
30
|
+
dirs.each do |dir|
|
31
|
+
@paths += Dir[File.join(dir,'*')]
|
32
|
+
end
|
33
|
+
|
34
|
+
@templates = @paths.collect do |p|
|
35
|
+
Template.open(p)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def compile
|
40
|
+
coffee = Array.new
|
41
|
+
|
42
|
+
vars = storage_variable
|
43
|
+
|
44
|
+
used = []
|
45
|
+
vars.each do |var|
|
46
|
+
used << var
|
47
|
+
|
48
|
+
if used.size == 1
|
49
|
+
str = "window[#{var.to_json}] ||= {}"
|
50
|
+
else
|
51
|
+
str = used.join('.')
|
52
|
+
str << " = (#{str} || {})"
|
53
|
+
end
|
54
|
+
|
55
|
+
coffee << str
|
56
|
+
end
|
57
|
+
|
58
|
+
templates.each do |template|
|
59
|
+
coffee << template.compile
|
60
|
+
end
|
61
|
+
|
62
|
+
Assette::Reader::Coffee.compile_str(coffee.join("\n"))
|
63
|
+
end
|
64
|
+
|
65
|
+
def storage_variable
|
66
|
+
format = Assette.config.template_format
|
67
|
+
if m = format.match(/^([\w\.]+)\[/)
|
68
|
+
vars = m[1].split('.')
|
69
|
+
else
|
70
|
+
[]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
data/spec/file_spec.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Assette::File do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@dir_before = Dir.pwd
|
7
|
+
Dir.chdir(File.dirname(__FILE__) + '/../examples')
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:all) do
|
11
|
+
Dir.chdir(@dir_before)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "javascript" do
|
15
|
+
|
16
|
+
subject do
|
17
|
+
Assette::File.open('public/javascripts/foo.js')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should equal" do
|
21
|
+
subject.should == Assette::File.open(subject.path)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should description" do
|
25
|
+
subject.dependencies.should have(2).files
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have the right reader class" do
|
29
|
+
subject.reader_class.should == Assette::Reader::Js
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should compile" do
|
33
|
+
subject.code.should == subject.text
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have templates" do
|
37
|
+
all_code = subject.all_code
|
38
|
+
all_code.should include('{{foo}}')
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe Assette::Reader::Coffee do
|
44
|
+
subject do
|
45
|
+
Assette::File.open('public/javascripts/test.coffee')
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should description" do
|
49
|
+
subject.dependencies.should have(1).file
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should " do
|
53
|
+
subject.code.should == "(function() {\n var test;\n test = 'test';\n}).call(this);\n"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should " do
|
57
|
+
all_code = subject.all_code
|
58
|
+
all_code.should include('window.one = 1;')
|
59
|
+
all_code.should include('test = \'test\';')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe Assette::Reader::Css do
|
64
|
+
subject do
|
65
|
+
Assette::File.open('public/stylesheets/two.css')
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should work" do
|
69
|
+
all_code = subject.all_code
|
70
|
+
all_code.should include('#one {}')
|
71
|
+
all_code.should include('#two {}')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe Assette::Reader::Scss do
|
76
|
+
subject do
|
77
|
+
Assette::File.open('public/stylesheets/two2.scss')
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should work" do
|
81
|
+
all_code = subject.all_code
|
82
|
+
all_code.should include 'width: 800px;'
|
83
|
+
all_code.should include 'width: 2400px;'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe Assette::Reader::Sass do
|
88
|
+
subject do
|
89
|
+
Assette::File.open('public/stylesheets/one1.sass')
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should work" do
|
93
|
+
all_code = subject.all_code
|
94
|
+
all_code.should include 'width: 800px;'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/spec/reader_spec.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Assette::Reader do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
|
7
|
+
class Assette::Reader::Txt < Assette::Reader(:txt)
|
8
|
+
def compile
|
9
|
+
@file.text
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should set outputs on creation" do
|
16
|
+
Assette::Reader::Txt.outputs.should == :txt
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should make the reader map" do
|
20
|
+
Assette::Reader::ALL.should include('txt' => Assette::Reader::Txt)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have mime type" do
|
24
|
+
Assette::Reader::Txt.mime_type.should == MIME::Types.type_for("test.txt").first
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should build the right target list" do
|
28
|
+
targets = Assette::Reader.possible_targets('/test/.hidden/one.file.css')
|
29
|
+
%w{
|
30
|
+
/test/.hidden/one.file.css
|
31
|
+
/test/.hidden/one.file.sass
|
32
|
+
/test/.hidden/one.file.scss
|
33
|
+
}.each do |p|
|
34
|
+
targets.should include p
|
35
|
+
end
|
36
|
+
|
37
|
+
targets = Assette::Reader.possible_targets('/test/.hidden/file.js')
|
38
|
+
targets.should include "/test/.hidden/file.js"
|
39
|
+
targets.should include "/test/.hidden/file.coffee"
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'assette'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Templates" do
|
4
|
+
before(:all) do
|
5
|
+
@dir_before = Dir.pwd
|
6
|
+
Dir.chdir(File.dirname(__FILE__) + '/../examples')
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:all) do
|
10
|
+
Dir.chdir(@dir_before)
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
describe Assette::TemplateSet do
|
15
|
+
|
16
|
+
it "should get correct list of files" do
|
17
|
+
f = Assette::Template.open("app/templates/foo/index.html.mustache")
|
18
|
+
|
19
|
+
a = Assette::TemplateSet.new(:all)
|
20
|
+
a.templates.should include f
|
21
|
+
|
22
|
+
a = Assette::TemplateSet.new(:foo)
|
23
|
+
a.templates.should == [f]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should compile" do
|
27
|
+
a = Assette::TemplateSet.new(:all)
|
28
|
+
a.compile.should include('{{foo}}')
|
29
|
+
|
30
|
+
a = Assette::TemplateSet.new(:foo)
|
31
|
+
a.compile.should include('{{foo}}')
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe Assette::Template do
|
37
|
+
|
38
|
+
subject do
|
39
|
+
Assette::Template.open("app/templates/foo/index.html.mustache")
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: assette
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 0.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Tal Atlas
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-06 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: json
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
prerelease: false
|
33
|
+
type: :runtime
|
34
|
+
requirement: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: haml
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
prerelease: false
|
47
|
+
type: :runtime
|
48
|
+
requirement: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: mime-types
|
51
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 47
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 16
|
60
|
+
version: "1.16"
|
61
|
+
prerelease: false
|
62
|
+
type: :runtime
|
63
|
+
requirement: *id003
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: rspec
|
66
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ~>
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 31
|
72
|
+
segments:
|
73
|
+
- 2
|
74
|
+
- 4
|
75
|
+
- 0
|
76
|
+
version: 2.4.0
|
77
|
+
prerelease: false
|
78
|
+
type: :development
|
79
|
+
requirement: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: yard
|
82
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 7
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
- 6
|
91
|
+
- 0
|
92
|
+
version: 0.6.0
|
93
|
+
prerelease: false
|
94
|
+
type: :development
|
95
|
+
requirement: *id005
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: bundler
|
98
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 23
|
104
|
+
segments:
|
105
|
+
- 1
|
106
|
+
- 0
|
107
|
+
- 0
|
108
|
+
version: 1.0.0
|
109
|
+
prerelease: false
|
110
|
+
type: :development
|
111
|
+
requirement: *id006
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: jeweler
|
114
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ~>
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
hash: 7
|
120
|
+
segments:
|
121
|
+
- 1
|
122
|
+
- 5
|
123
|
+
- 2
|
124
|
+
version: 1.5.2
|
125
|
+
prerelease: false
|
126
|
+
type: :development
|
127
|
+
requirement: *id007
|
128
|
+
- !ruby/object:Gem::Dependency
|
129
|
+
name: rcov
|
130
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
hash: 3
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
version: "0"
|
139
|
+
prerelease: false
|
140
|
+
type: :development
|
141
|
+
requirement: *id008
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: mime-types
|
144
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 47
|
150
|
+
segments:
|
151
|
+
- 1
|
152
|
+
- 16
|
153
|
+
version: "1.16"
|
154
|
+
prerelease: false
|
155
|
+
type: :runtime
|
156
|
+
requirement: *id009
|
157
|
+
description: longer description of your gem
|
158
|
+
email: me@tal.by
|
159
|
+
executables: []
|
160
|
+
|
161
|
+
extensions: []
|
162
|
+
|
163
|
+
extra_rdoc_files:
|
164
|
+
- LICENSE.txt
|
165
|
+
- README.rdoc
|
166
|
+
files:
|
167
|
+
- .document
|
168
|
+
- .rspec
|
169
|
+
- Gemfile
|
170
|
+
- Gemfile.lock
|
171
|
+
- LICENSE.txt
|
172
|
+
- README.rdoc
|
173
|
+
- Rakefile
|
174
|
+
- VERSION
|
175
|
+
- assette.gemspec
|
176
|
+
- examples/app/templates/foo/index.html.mustache
|
177
|
+
- examples/config.ru
|
178
|
+
- examples/defaults.rb
|
179
|
+
- examples/defaults.yml
|
180
|
+
- examples/public/images/test.pdf
|
181
|
+
- examples/public/javascripts/foo.js
|
182
|
+
- examples/public/javascripts/one.js
|
183
|
+
- examples/public/javascripts/test.coffee
|
184
|
+
- examples/public/javascripts/three.js
|
185
|
+
- examples/public/javascripts/two.js
|
186
|
+
- examples/public/stylesheets/one.css
|
187
|
+
- examples/public/stylesheets/one1.sass
|
188
|
+
- examples/public/stylesheets/two.css
|
189
|
+
- examples/public/stylesheets/two2.scss
|
190
|
+
- lib/assette.rb
|
191
|
+
- lib/assette/compiled_file.rb
|
192
|
+
- lib/assette/config.rb
|
193
|
+
- lib/assette/file.rb
|
194
|
+
- lib/assette/reader.rb
|
195
|
+
- lib/assette/readers.rb
|
196
|
+
- lib/assette/readers/coffee.rb
|
197
|
+
- lib/assette/readers/css.rb
|
198
|
+
- lib/assette/readers/js.rb
|
199
|
+
- lib/assette/readers/sass.rb
|
200
|
+
- lib/assette/readers/scss.rb
|
201
|
+
- lib/assette/server.rb
|
202
|
+
- lib/assette/template.rb
|
203
|
+
- lib/assette/template_set.rb
|
204
|
+
- spec/assette_spec.rb
|
205
|
+
- spec/file_spec.rb
|
206
|
+
- spec/reader_spec.rb
|
207
|
+
- spec/spec_helper.rb
|
208
|
+
- spec/template_spec.rb
|
209
|
+
has_rdoc: true
|
210
|
+
homepage: http://github.com/Talby/assette
|
211
|
+
licenses:
|
212
|
+
- MIT
|
213
|
+
post_install_message:
|
214
|
+
rdoc_options: []
|
215
|
+
|
216
|
+
require_paths:
|
217
|
+
- lib
|
218
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
219
|
+
none: false
|
220
|
+
requirements:
|
221
|
+
- - ">="
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
hash: 3
|
224
|
+
segments:
|
225
|
+
- 0
|
226
|
+
version: "0"
|
227
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
228
|
+
none: false
|
229
|
+
requirements:
|
230
|
+
- - ">="
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
hash: 3
|
233
|
+
segments:
|
234
|
+
- 0
|
235
|
+
version: "0"
|
236
|
+
requirements: []
|
237
|
+
|
238
|
+
rubyforge_project:
|
239
|
+
rubygems_version: 1.5.0
|
240
|
+
signing_key:
|
241
|
+
specification_version: 3
|
242
|
+
summary: Asset manager thing
|
243
|
+
test_files:
|
244
|
+
- examples/defaults.rb
|
245
|
+
- spec/assette_spec.rb
|
246
|
+
- spec/file_spec.rb
|
247
|
+
- spec/reader_spec.rb
|
248
|
+
- spec/spec_helper.rb
|
249
|
+
- spec/template_spec.rb
|