jsrequire 0.1.2 → 0.1.3
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/VERSION +1 -1
- data/jsrequire.gemspec +6 -2
- data/lib/jsrequire.rb +42 -14
- data/test/fixtures/javascripts/coffee/coke.coffee +0 -0
- data/test/fixtures/javascripts/coffee/other.coffee +3 -0
- data/test/fixtures/javascripts/coffee/tea.js +1 -0
- data/test/fixtures/javascripts/i_can_cook.coffee +2 -0
- data/test/test_jsrequire.rb +4 -0
- metadata +8 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/jsrequire.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{jsrequire}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["aekym"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-10}
|
13
13
|
s.description = %q{Organizes requirements of assets in JavaScript files, resolved dependencies of js files and helps include depending css files.}
|
14
14
|
s.email = %q{me@aekym.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,8 +28,12 @@ Gem::Specification.new do |s|
|
|
28
28
|
"test/fixtures/different-place/b.js",
|
29
29
|
"test/fixtures/javascripts/a.js",
|
30
30
|
"test/fixtures/javascripts/c.js",
|
31
|
+
"test/fixtures/javascripts/coffee/coke.coffee",
|
32
|
+
"test/fixtures/javascripts/coffee/other.coffee",
|
33
|
+
"test/fixtures/javascripts/coffee/tea.js",
|
31
34
|
"test/fixtures/javascripts/file.with.dot.js",
|
32
35
|
"test/fixtures/javascripts/hook.js",
|
36
|
+
"test/fixtures/javascripts/i_can_cook.coffee",
|
33
37
|
"test/fixtures/javascripts/namespace/a.js",
|
34
38
|
"test/fixtures/javascripts/namespace/json_reader.js",
|
35
39
|
"test/fixtures/javascripts/namespace/norequire.js",
|
data/lib/jsrequire.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class JsRequire
|
2
|
+
ALLOWED_EXTENSIONS = %w(coffee js)
|
2
3
|
|
3
4
|
class FileNotFoundInLoadpath < ArgumentError; end
|
4
5
|
|
@@ -128,7 +129,7 @@ class JsRequire
|
|
128
129
|
end
|
129
130
|
|
130
131
|
|
131
|
-
def
|
132
|
+
def find_file_with_extension(filename, current_dir = nil)
|
132
133
|
return filename if is_file?(filename)
|
133
134
|
|
134
135
|
loadpaths = @extract_loadpaths + @additional_loadpaths
|
@@ -147,7 +148,21 @@ class JsRequire
|
|
147
148
|
end
|
148
149
|
end
|
149
150
|
|
150
|
-
|
151
|
+
false
|
152
|
+
end
|
153
|
+
|
154
|
+
def find_file(filename, current_dir = nil)
|
155
|
+
file = false
|
156
|
+
|
157
|
+
file = find_file_with_extension(filename, current_dir)
|
158
|
+
return file unless file == false
|
159
|
+
|
160
|
+
ALLOWED_EXTENSIONS.each do |extension|
|
161
|
+
file = find_file_with_extension("#{filename}.#{extension}", current_dir)
|
162
|
+
return file unless file == false
|
163
|
+
end
|
164
|
+
|
165
|
+
raise FileNotFoundInLoadpath, "File '#{filename}' not found in loadpaths '#{(@extract_loadpaths + @additional_loadpaths).join("', '")}'."
|
151
166
|
end
|
152
167
|
|
153
168
|
def exec_preprocessor(action, parameter)
|
@@ -167,21 +182,12 @@ class JsRequire
|
|
167
182
|
js = []
|
168
183
|
|
169
184
|
File.open(filename, "r").each_line do |line|
|
170
|
-
if
|
171
|
-
\s* # optional leading whitespace
|
172
|
-
\/\*\s* # opening comment
|
173
|
-
(\w+)\s+ # action
|
174
|
-
(.*) # parameter
|
175
|
-
\*\/\s*$/x # closing comment
|
176
|
-
|
177
|
-
action = $1
|
178
|
-
parameter = $2.strip
|
179
|
-
|
185
|
+
if val = parse_line(line)
|
180
186
|
# fire callbacks
|
181
|
-
action, parameter = exec_preprocessor(
|
187
|
+
action, parameter = exec_preprocessor(val[0], val[1])
|
182
188
|
|
183
189
|
case action
|
184
|
-
when "js" then js <<
|
190
|
+
when "js" then js << parameter
|
185
191
|
end
|
186
192
|
else
|
187
193
|
break
|
@@ -191,6 +197,28 @@ class JsRequire
|
|
191
197
|
js.uniq.map { |f| find_file(f, File.dirname(filename)) }
|
192
198
|
end
|
193
199
|
|
200
|
+
def parse_line(line)
|
201
|
+
case line
|
202
|
+
when /^
|
203
|
+
\s* # optional leading whitespace
|
204
|
+
\/\*\s* # opening comment
|
205
|
+
(\w+)\s+ # action
|
206
|
+
(.*) # parameter
|
207
|
+
\*\/\s*$ # closing comment
|
208
|
+
/x then
|
209
|
+
[$1, $2.strip]
|
210
|
+
when /^
|
211
|
+
\s* # optional leading whitespace
|
212
|
+
\#\s* # opening comment
|
213
|
+
(\w+)\s+ # action
|
214
|
+
(.*)$ # parameter
|
215
|
+
/x then
|
216
|
+
[$1, $2.strip]
|
217
|
+
else
|
218
|
+
nil
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
194
222
|
|
195
223
|
def extract_dependencies_recursive(files, included_files = [])
|
196
224
|
js = []
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
/* js .coke */
|
data/test/test_jsrequire.rb
CHANGED
@@ -117,6 +117,10 @@ class TestJsRequire < Test::Unit::TestCase
|
|
117
117
|
assert_equal additional_loadpaths, @jsrequire.instance_eval("@additional_loadpaths")
|
118
118
|
end
|
119
119
|
|
120
|
+
should "work with CoffeeScript files, too" do
|
121
|
+
assert_requires("i_can_cook.coffee", ["coffee/other.coffee", "coffee/tea.js", "coffee/coke.coffee"])
|
122
|
+
end
|
123
|
+
|
120
124
|
end
|
121
125
|
|
122
126
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsrequire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- aekym
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-08-10 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -40,8 +40,12 @@ files:
|
|
40
40
|
- test/fixtures/different-place/b.js
|
41
41
|
- test/fixtures/javascripts/a.js
|
42
42
|
- test/fixtures/javascripts/c.js
|
43
|
+
- test/fixtures/javascripts/coffee/coke.coffee
|
44
|
+
- test/fixtures/javascripts/coffee/other.coffee
|
45
|
+
- test/fixtures/javascripts/coffee/tea.js
|
43
46
|
- test/fixtures/javascripts/file.with.dot.js
|
44
47
|
- test/fixtures/javascripts/hook.js
|
48
|
+
- test/fixtures/javascripts/i_can_cook.coffee
|
45
49
|
- test/fixtures/javascripts/namespace/a.js
|
46
50
|
- test/fixtures/javascripts/namespace/json_reader.js
|
47
51
|
- test/fixtures/javascripts/namespace/norequire.js
|