wavy 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wavy/parsers/mixin.rb +143 -47
- data/lib/wavy/utils/filesys.rb +17 -0
- data/lib/wavy/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 822ce721c0f7b44814c30ae88dc79fe9f545c638
|
4
|
+
data.tar.gz: 327d19af49b0f994bed7422133e609fc8e2fd8cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18ed4d2f4f01eecd450316f9c67ff56bd915b0fa52c08cc650c3b6b6ca00e6c2c12faecab8c95f123ceb50e0f640972ca606613d9b5e327c4e0a4ca847f867d0
|
7
|
+
data.tar.gz: f8b3afbb9092ba731eceaed653c5cb57179d4ae8f46c3d72e84ae407721c2cd2808140b2610fd5ef33cfa12ad4b312eb7a6d39bea02f639605a7d523fcaecb01
|
data/lib/wavy/parsers/mixin.rb
CHANGED
@@ -4,6 +4,93 @@ module Wavy
|
|
4
4
|
|
5
5
|
class Mixin
|
6
6
|
|
7
|
+
# Parses all function and template mixins
|
8
|
+
#
|
9
|
+
# @param (String) data Content
|
10
|
+
# @param (String|Boolean) path Template path
|
11
|
+
#
|
12
|
+
# @return (String) data Parsed content
|
13
|
+
def self.parse(template, path = false)
|
14
|
+
template = parseTemplates(template, path)
|
15
|
+
|
16
|
+
return template
|
17
|
+
end
|
18
|
+
|
19
|
+
# Finds all included mixin functions.
|
20
|
+
#
|
21
|
+
# @param (String) data Content
|
22
|
+
# @param (String) path Template path
|
23
|
+
#
|
24
|
+
# @return (String) data Parsed content
|
25
|
+
def self.parseTemplates(template, path)
|
26
|
+
pattern = /(@import)\s\"(.*)\"/
|
27
|
+
|
28
|
+
indent = ""
|
29
|
+
template_new = ""
|
30
|
+
|
31
|
+
saved_templates = Wavy::Models::Mixins.getTemplates
|
32
|
+
|
33
|
+
template.each_line.with_index do |line, i|
|
34
|
+
matches = line.scan(pattern)
|
35
|
+
|
36
|
+
line = parseFunctions(line)
|
37
|
+
|
38
|
+
if matches.length > 0
|
39
|
+
matches.each do |match|
|
40
|
+
if(saved_templates["template-"+match[1]])
|
41
|
+
imported_file = saved_templates["template-"+match[1]]
|
42
|
+
else
|
43
|
+
Wavy::Parsers::Mixin.definedTemplate(line, path)
|
44
|
+
saved_templates = Wavy::Models::Mixins.getTemplates
|
45
|
+
|
46
|
+
imported_file = saved_templates["template-"+match[1]]
|
47
|
+
end
|
48
|
+
|
49
|
+
content = imported_file.content
|
50
|
+
|
51
|
+
find = "@import \"#{match[1]}\""
|
52
|
+
|
53
|
+
new_content = ""
|
54
|
+
|
55
|
+
current_indent = indent.dup
|
56
|
+
current_indent << line.slice(0..(line.index(find)))
|
57
|
+
current_indent[-1] = ""
|
58
|
+
|
59
|
+
same_line = false
|
60
|
+
|
61
|
+
if current_indent.strip.empty? == false
|
62
|
+
same_line = true
|
63
|
+
end
|
64
|
+
|
65
|
+
content = parseFunctions(content)
|
66
|
+
|
67
|
+
content.each_line.with_index do |content_line, ii|
|
68
|
+
if same_line == true
|
69
|
+
content_line = content_line.strip
|
70
|
+
content_line.delete!("\n")
|
71
|
+
else
|
72
|
+
if i > 0 && ii > 0
|
73
|
+
new_content << current_indent
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
new_content << content_line
|
78
|
+
end
|
79
|
+
|
80
|
+
new_line = current_indent
|
81
|
+
new_line << new_content
|
82
|
+
new_line << "\n"
|
83
|
+
|
84
|
+
line = new_line
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
template_new << line
|
89
|
+
end
|
90
|
+
|
91
|
+
return template_new
|
92
|
+
end
|
93
|
+
|
7
94
|
# Finds all user-defined mixins.
|
8
95
|
#
|
9
96
|
# @param (String) data Content
|
@@ -28,7 +115,7 @@ module Wavy
|
|
28
115
|
#
|
29
116
|
# @param (String) content Content
|
30
117
|
# @param (String|Boolean) path Template path
|
31
|
-
def self.
|
118
|
+
def self.definedTemplate(content, path = false)
|
32
119
|
pattern = /(@import)\s\"(.*)\"/
|
33
120
|
matches = content.scan(pattern)
|
34
121
|
|
@@ -93,7 +180,7 @@ module Wavy
|
|
93
180
|
file_match = file_match[0]
|
94
181
|
|
95
182
|
content = FILE_IMPORTER.load(file_path)
|
96
|
-
content =
|
183
|
+
content = parseTemplates(content, file_path)
|
97
184
|
|
98
185
|
mixin_node = Wavy::Nodes::Mixin.new(name, content, false)
|
99
186
|
|
@@ -113,19 +200,6 @@ module Wavy
|
|
113
200
|
end
|
114
201
|
end
|
115
202
|
|
116
|
-
# Parses all function and template mixins
|
117
|
-
#
|
118
|
-
# @param (String) data Content
|
119
|
-
# @param (String|Boolean) path Template path
|
120
|
-
#
|
121
|
-
# @return (String) data Parsed content
|
122
|
-
def self.parse(template, path = false)
|
123
|
-
template = parseFunctions(template)
|
124
|
-
template = parseTemplates(template, path)
|
125
|
-
|
126
|
-
return template
|
127
|
-
end
|
128
|
-
|
129
203
|
# Finds all included mixin functions.
|
130
204
|
#
|
131
205
|
# @param (String) template Content
|
@@ -158,48 +232,70 @@ module Wavy
|
|
158
232
|
end
|
159
233
|
|
160
234
|
# Search for includes within mixins
|
161
|
-
content =
|
235
|
+
content = parseFunctions(content)
|
162
236
|
|
163
237
|
# Find mixin string to replace
|
164
238
|
find = "@include #{match[1]}(#{match[2]})"
|
165
|
-
template = template.gsub(find, content)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
239
|
|
170
|
-
|
171
|
-
|
240
|
+
indent = ""
|
241
|
+
new_template = ""
|
242
|
+
new_content = ""
|
172
243
|
|
173
|
-
|
174
|
-
|
175
|
-
# @param (String) data Content
|
176
|
-
# @param (String) path Template path
|
177
|
-
#
|
178
|
-
# @return (String) data Parsed content
|
179
|
-
def self.parseTemplates(template, path)
|
180
|
-
# Search for mixin includes
|
181
|
-
pattern = /(@import)\s\"(.*)\"/
|
182
|
-
matches = template.scan(pattern)
|
244
|
+
template.each_line.with_index do |line, i|
|
245
|
+
matches = line.scan(find)
|
183
246
|
|
184
|
-
|
247
|
+
if matches.length > 0
|
248
|
+
current_indent = indent.dup
|
249
|
+
current_indent << line.slice(0..(line.index(find)))
|
250
|
+
current_indent[-1] = ""
|
185
251
|
|
186
|
-
|
187
|
-
if matches.length > 0
|
188
|
-
matches.each do |match|
|
189
|
-
if(mixins["template-"+match[1]])
|
252
|
+
line.delete!("\n")
|
190
253
|
|
191
|
-
|
192
|
-
content = mixin.content
|
254
|
+
same_line = false
|
193
255
|
|
194
|
-
|
195
|
-
|
256
|
+
if current_indent.strip.empty? == false
|
257
|
+
same_line = true
|
258
|
+
end
|
196
259
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
260
|
+
content_tab_length = 0
|
261
|
+
|
262
|
+
content.each_line.with_index do |content_line, ii|
|
263
|
+
match_indent = content_line.scan(/^(\s*|\t*)\S/)
|
264
|
+
|
265
|
+
if same_line == true
|
266
|
+
content_line = content_line.strip
|
267
|
+
content_line.delete!("\n")
|
268
|
+
else
|
269
|
+
if ii > 1 && same_line == false
|
270
|
+
new_content << current_indent
|
271
|
+
end
|
272
|
+
|
273
|
+
if ii == 1 && match_indent[0] && match_indent[0][0]
|
274
|
+
content_tab_length = match_indent[0][0].length
|
275
|
+
end
|
276
|
+
|
277
|
+
if match_indent[0] && match_indent[0][0] && match_indent[0][0].length >= content_tab_length
|
278
|
+
content_line.slice!(0, content_tab_length)
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
if ii > 0
|
284
|
+
new_content << content_line
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
if same_line == true && i == (template.lines.count-1)
|
289
|
+
line << "\n"
|
290
|
+
end
|
291
|
+
|
292
|
+
line = line.gsub(find, new_content)
|
293
|
+
end
|
294
|
+
|
295
|
+
new_template << line
|
296
|
+
end
|
297
|
+
|
298
|
+
template = new_template
|
203
299
|
end
|
204
300
|
end
|
205
301
|
end
|
data/lib/wavy/utils/filesys.rb
CHANGED
@@ -35,6 +35,23 @@ module Wavy
|
|
35
35
|
load(new_name, false)
|
36
36
|
end
|
37
37
|
|
38
|
+
def guess_indent(file)
|
39
|
+
i = 0
|
40
|
+
file.each_line.with_index {|line, i|
|
41
|
+
break if i > 3
|
42
|
+
match = /^\s+/.match(line)
|
43
|
+
next unless match
|
44
|
+
return {
|
45
|
+
:tab? => line.start_with?("\t"),
|
46
|
+
:indent => match[0].size
|
47
|
+
}
|
48
|
+
}
|
49
|
+
return { # returns default settings
|
50
|
+
:tab? => true,
|
51
|
+
:indent => 4
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
38
55
|
end
|
39
56
|
|
40
57
|
end
|
data/lib/wavy/version.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wavy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Govaere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Wavy is a
|
13
|
+
description: Wavy is a templating engine for preprocessing HTML, heavily influenced
|
14
|
+
by the simplicity of Sass. Think Sass for HTML.
|
14
15
|
email: matthew.govaere@gmail.com
|
15
16
|
executables:
|
16
17
|
- wavy
|
@@ -57,5 +58,5 @@ rubyforge_project:
|
|
57
58
|
rubygems_version: 2.4.1
|
58
59
|
signing_key:
|
59
60
|
specification_version: 4
|
60
|
-
summary: A simple templating engine for
|
61
|
+
summary: A simple templating engine for HTML – Inspired By Sass
|
61
62
|
test_files: []
|