golf 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/golf/compiler.rb +79 -25
- data/lib/golf/version.rb +1 -1
- data/lib/golf.rb +0 -1
- data/test/reference_app/golfapp/components/HelloWorld/HelloWorld.css +3 -0
- data/test/reference_app/golfapp/components/HelloWorld/HelloWorld.html +0 -10
- data/test/reference_app/golfapp/components/HelloWorld/HelloWorld.js +3 -0
- data/test/test_compiler.rb +3 -4
- metadata +8 -58
- data/lib/golf/filter.rb +0 -10
- data/lib/golf/filters/dummy_filter.rb +0 -11
data/Gemfile.lock
CHANGED
data/lib/golf/compiler.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
module Golf
|
2
2
|
|
3
|
+
module Filter
|
4
|
+
class Upcase
|
5
|
+
def self.transform(data)
|
6
|
+
data.upcase
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
|
3
13
|
class Compiler
|
4
14
|
|
5
15
|
require 'find'
|
@@ -26,7 +36,7 @@ module Golf
|
|
26
36
|
end
|
27
37
|
|
28
38
|
def component_json
|
29
|
-
|
39
|
+
traverse_components
|
30
40
|
end
|
31
41
|
|
32
42
|
def res_json
|
@@ -105,49 +115,73 @@ module Golf
|
|
105
115
|
traverse("#{@golfpath}/styles", "css")
|
106
116
|
end
|
107
117
|
|
118
|
+
def traverse_components
|
119
|
+
results = {}
|
120
|
+
Dir["#{@golfpath}/components/**/*"].each do |path|
|
121
|
+
name = package_name(path)
|
122
|
+
valid_arr = path_valid_for_filtering?(path)
|
123
|
+
next if FileTest.directory?(path) or !path.include?('.html')
|
124
|
+
data = filtered_read(path)
|
125
|
+
data_arr = extract_parts(data, path)
|
126
|
+
results = results.merge({ name => { "name" => name, "html" => data_arr["html"], "css" => data_arr["css"], "js" => data_arr["js"] }})
|
127
|
+
end
|
128
|
+
JSON.dump(results)
|
129
|
+
end
|
130
|
+
|
131
|
+
|
108
132
|
def traverse(dir, type)
|
109
133
|
results = {}
|
110
134
|
if File.exists?(dir) and File.directory?(dir)
|
111
135
|
Dir["#{dir}/**/*.#{type}"].sort.reverse.each do |path|
|
112
|
-
|
113
|
-
name = package_name(path)
|
114
|
-
arr = path.split('/')
|
115
|
-
last_two = arr.slice(arr.length - 2 ,2)
|
116
|
-
next if last_two[0] != last_two[1].gsub('.html','')
|
117
|
-
else
|
118
|
-
name = path.split('/').last.gsub(".#{type}",'')
|
119
|
-
end
|
136
|
+
name = path.split('/').last.gsub(".#{type}",'')
|
120
137
|
data = filtered_read(path)
|
121
|
-
|
122
|
-
data_arr = extract_parts(data)
|
123
|
-
results = results.merge({ name => { "name" => name, "html" => data_arr["html"], "css" => data_arr["css"], "js" => data_arr["js"] }})
|
124
|
-
else
|
125
|
-
results = results.merge({ name => { "name" => name, "#{type}" => data }})
|
126
|
-
end
|
138
|
+
results = results.merge({ name => { "name" => name, "#{type}" => data }})
|
127
139
|
end
|
128
140
|
end
|
129
141
|
JSON.dump(results)
|
130
142
|
end
|
131
|
-
|
132
|
-
def extract_parts(data)
|
143
|
+
|
144
|
+
def extract_parts(data, path)
|
145
|
+
component_name = path.split('/').last
|
146
|
+
component_dir = path.gsub(component_name, '')
|
147
|
+
#load from file
|
133
148
|
doc = Hpricot(data)
|
134
149
|
arr = {}
|
135
|
-
|
136
|
-
|
150
|
+
css = (doc/'//style').first
|
151
|
+
if css
|
152
|
+
arr["css"] = css
|
153
|
+
end
|
154
|
+
js = (doc/'//script').first
|
155
|
+
if js
|
156
|
+
arr["js"] = js
|
157
|
+
end
|
137
158
|
(doc/'//style').remove
|
138
159
|
(doc/'//script').remove
|
160
|
+
|
161
|
+
|
139
162
|
arr["html"] = doc.to_s
|
163
|
+
|
164
|
+
#load from files, ".js.coffee", etc
|
165
|
+
Dir["#{component_dir}/*"].each do |file_path|
|
166
|
+
valid_arr = path_valid_for_filtering?(file_path)
|
167
|
+
if valid_arr
|
168
|
+
filter_name = valid_arr[1]
|
169
|
+
output_type = valid_arr[0]
|
170
|
+
arr[output_type] = filtered_read(file_path)
|
171
|
+
else
|
172
|
+
extension = file_path.split('/').last.split('.').last
|
173
|
+
arr[extension] = File.read(file_path)
|
174
|
+
end
|
175
|
+
end
|
140
176
|
arr
|
141
177
|
end
|
142
|
-
|
143
|
-
|
144
178
|
|
145
179
|
def filtered_read(path)
|
146
180
|
data = File.read(path)
|
147
181
|
if path.split('.').last == 'html'
|
148
182
|
data = filter_by_block(data)
|
149
183
|
end
|
150
|
-
data = filter_by_extension(data)
|
184
|
+
data = filter_by_extension(data, path)
|
151
185
|
data
|
152
186
|
end
|
153
187
|
|
@@ -173,9 +207,29 @@ module Golf
|
|
173
207
|
data
|
174
208
|
end
|
175
209
|
end
|
176
|
-
|
177
|
-
def
|
178
|
-
|
210
|
+
|
211
|
+
def path_valid_for_filtering?(path)
|
212
|
+
path_arr = path.split('/').last.split('.')
|
213
|
+
if path_arr.count > 2
|
214
|
+
last_two = path_arr[path_arr.length - 2..path_arr.length]
|
215
|
+
if last_two[0] == "js" or last_two[0] == "css" or last_two[0] == "html"
|
216
|
+
last_two
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def filter_by_extension(data, path)
|
222
|
+
valid_arr = path_valid_for_filtering?(path)
|
223
|
+
if valid_arr
|
224
|
+
filter_name = valid_arr[1].capitalize.to_sym
|
225
|
+
if Golf::Filter.constants.include?(filter_name)
|
226
|
+
Golf::Filter.const_get(filter_name).transform(data)
|
227
|
+
else
|
228
|
+
data
|
229
|
+
end
|
230
|
+
else
|
231
|
+
data
|
232
|
+
end
|
179
233
|
end
|
180
234
|
|
181
235
|
def package_name(path)
|
data/lib/golf/version.rb
CHANGED
data/lib/golf.rb
CHANGED
@@ -1,13 +1,3 @@
|
|
1
1
|
<div>
|
2
|
-
<style type="text/golf">
|
3
|
-
div.container {
|
4
|
-
border: 1px solid red;
|
5
|
-
}
|
6
|
-
</style>
|
7
|
-
<script filter="dummy" type="text/golf">
|
8
|
-
function() {
|
9
|
-
$(".container").append("<h1>Hello, world!</h1>");
|
10
|
-
}
|
11
|
-
</script>
|
12
2
|
<div class="container"></div>
|
13
3
|
</div>
|
data/test/test_compiler.rb
CHANGED
@@ -30,22 +30,21 @@ class CompilerTest < Test::Unit::TestCase
|
|
30
30
|
b = JSON.parse @compiler.component_json
|
31
31
|
#assert_equal a.keys.sort,b.keys.sort
|
32
32
|
#assert_equal a,b
|
33
|
-
#puts a["HelloWorld"]["html"
|
34
33
|
#puts '---------'
|
35
|
-
|
34
|
+
puts b["HelloWorld"].inspect
|
36
35
|
#puts '---------'
|
37
36
|
#a.keys.each do |key|
|
38
37
|
# puts "#{key} should be #{a[key].hash}, but was #{b[key].hash}"
|
39
38
|
#end
|
40
39
|
end
|
41
40
|
|
42
|
-
def
|
41
|
+
def te2st_res_generation
|
43
42
|
a = @reference.res
|
44
43
|
b = JSON.parse @compiler.res_json
|
45
44
|
assert_equal a,b
|
46
45
|
end
|
47
46
|
|
48
|
-
def
|
47
|
+
def tesst_res_generation_components
|
49
48
|
a = @reference.res
|
50
49
|
b = JSON.parse @compiler.res_json
|
51
50
|
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: golf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 5
|
8
|
-
- 4
|
9
|
-
version: 0.5.4
|
4
|
+
prerelease:
|
5
|
+
version: 0.5.5
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Micha Niskin, Alan Dipert, Julio Capote
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-04-14 00:00:00 -
|
13
|
+
date: 2011-04-14 00:00:00 -07:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,8 +21,6 @@ dependencies:
|
|
25
21
|
requirements:
|
26
22
|
- - ">="
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
24
|
version: "0"
|
31
25
|
type: :runtime
|
32
26
|
version_requirements: *id001
|
@@ -38,8 +32,6 @@ dependencies:
|
|
38
32
|
requirements:
|
39
33
|
- - ">="
|
40
34
|
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
35
|
version: "0"
|
44
36
|
type: :runtime
|
45
37
|
version_requirements: *id002
|
@@ -51,8 +43,6 @@ dependencies:
|
|
51
43
|
requirements:
|
52
44
|
- - ">="
|
53
45
|
- !ruby/object:Gem::Version
|
54
|
-
segments:
|
55
|
-
- 0
|
56
46
|
version: "0"
|
57
47
|
type: :runtime
|
58
48
|
version_requirements: *id003
|
@@ -64,8 +54,6 @@ dependencies:
|
|
64
54
|
requirements:
|
65
55
|
- - ">="
|
66
56
|
- !ruby/object:Gem::Version
|
67
|
-
segments:
|
68
|
-
- 0
|
69
57
|
version: "0"
|
70
58
|
type: :runtime
|
71
59
|
version_requirements: *id004
|
@@ -88,8 +76,6 @@ files:
|
|
88
76
|
- lib/golf.rb
|
89
77
|
- lib/golf/cli.rb
|
90
78
|
- lib/golf/compiler.rb
|
91
|
-
- lib/golf/filter.rb
|
92
|
-
- lib/golf/filters/dummy_filter.rb
|
93
79
|
- lib/golf/rack.rb
|
94
80
|
- lib/golf/version.rb
|
95
81
|
- resources/app_error.html
|
@@ -180,7 +166,9 @@ files:
|
|
180
166
|
- templates/twitter/golfapp/scripts/00-myscript.js
|
181
167
|
- templates/twitter/golfapp/styles/main.css
|
182
168
|
- test/reference_app/golfapp/components.js
|
169
|
+
- test/reference_app/golfapp/components/HelloWorld/HelloWorld.css
|
183
170
|
- test/reference_app/golfapp/components/HelloWorld/HelloWorld.html
|
171
|
+
- test/reference_app/golfapp/components/HelloWorld/HelloWorld.js
|
184
172
|
- test/reference_app/golfapp/components/golf/cart/Admin/Admin.html
|
185
173
|
- test/reference_app/golfapp/components/golf/cart/Cart/Cart.html
|
186
174
|
- test/reference_app/golfapp/components/golf/cart/Product/Product.html
|
@@ -228,57 +216,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
228
216
|
requirements:
|
229
217
|
- - ">="
|
230
218
|
- !ruby/object:Gem::Version
|
231
|
-
segments:
|
232
|
-
- 0
|
233
219
|
version: "0"
|
234
220
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
235
221
|
none: false
|
236
222
|
requirements:
|
237
223
|
- - ">="
|
238
224
|
- !ruby/object:Gem::Version
|
239
|
-
segments:
|
240
|
-
- 0
|
241
225
|
version: "0"
|
242
226
|
requirements: []
|
243
227
|
|
244
228
|
rubyforge_project: golf
|
245
|
-
rubygems_version: 1.
|
229
|
+
rubygems_version: 1.6.1
|
246
230
|
signing_key:
|
247
231
|
specification_version: 3
|
248
232
|
summary: Component based front end JS Framework
|
249
|
-
test_files:
|
250
|
-
|
251
|
-
- test/reference_app/golfapp/components/HelloWorld/HelloWorld.html
|
252
|
-
- test/reference_app/golfapp/components/golf/cart/Admin/Admin.html
|
253
|
-
- test/reference_app/golfapp/components/golf/cart/Cart/Cart.html
|
254
|
-
- test/reference_app/golfapp/components/golf/cart/Product/Product.html
|
255
|
-
- test/reference_app/golfapp/components/golf/cart/ProductListing/ProductListing.html
|
256
|
-
- test/reference_app/golfapp/components/golf/cart/Store/Store.html
|
257
|
-
- test/reference_app/golfapp/controller.js
|
258
|
-
- test/reference_app/golfapp/img/ Timer & Non-Stick.jpeg
|
259
|
-
- test/reference_app/golfapp/img/134lines.jpeg
|
260
|
-
- test/reference_app/golfapp/img/Q33 Sail Plan.jpeg
|
261
|
-
- test/reference_app/golfapp/img/a/asdf
|
262
|
-
- test/reference_app/golfapp/img/a/b/c/zxcv
|
263
|
-
- test/reference_app/golfapp/img/a/b/qwer
|
264
|
-
- test/reference_app/golfapp/img/em> - Brushed Stainless Steel.jpeg
|
265
|
-
- test/reference_app/golfapp/img/em> - White.jpeg
|
266
|
-
- test/reference_app/golfapp/img/em> Broil CTO7100B.jpeg
|
267
|
-
- test/reference_app/golfapp/img/em> Broiler - Stainless.jpeg
|
268
|
-
- test/reference_app/golfapp/img/em> with Countdo.jpeg
|
269
|
-
- test/reference_app/golfapp/img/em> with Element IQ.jpeg
|
270
|
-
- test/reference_app/golfapp/img/em> with OneTouch ...jpeg
|
271
|
-
- test/reference_app/golfapp/img/em> with Pizza.jpeg
|
272
|
-
- test/reference_app/golfapp/img/em>-1.jpeg
|
273
|
-
- test/reference_app/golfapp/img/em>-2.jpeg
|
274
|
-
- test/reference_app/golfapp/img/em>-3.jpeg
|
275
|
-
- test/reference_app/golfapp/img/em>-Black.jpeg
|
276
|
-
- test/reference_app/golfapp/img/em>.jpeg
|
277
|
-
- test/reference_app/golfapp/img/unnamed.jpeg
|
278
|
-
- test/reference_app/golfapp/plugins/mylib.js
|
279
|
-
- test/reference_app/golfapp/scripts/00-myscript.js
|
280
|
-
- test/reference_app/golfapp/scripts/01-jquery.tmpl.js
|
281
|
-
- test/reference_app/golfapp/styles/main.css
|
282
|
-
- test/test_compiler.rb
|
283
|
-
- test/test_helper.rb
|
284
|
-
- test/test_rack.rb
|
233
|
+
test_files: []
|
234
|
+
|
data/lib/golf/filter.rb
DELETED