hamlit 1.5.4 → 1.5.5
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.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/CHANGELOG.md +6 -0
- data/Rakefile +5 -0
- data/doc/README.md +10 -0
- data/doc/engine/old_attributes.md +68 -0
- data/doc/engine/script.md +105 -0
- data/doc/engine/text.md +88 -0
- data/doc/filters/coffee.md +125 -0
- data/doc/filters/erb.md +31 -0
- data/doc/filters/javascript.md +83 -0
- data/doc/filters/less.md +57 -0
- data/doc/filters/markdown.md +31 -0
- data/doc/filters/plain.md +25 -0
- data/doc/filters/sass.md +62 -0
- data/doc/filters/scss.md +68 -0
- data/hamlit.gemspec +1 -1
- data/lib/hamlit/engine.rb +1 -10
- data/lib/hamlit/parser.rb +11 -6
- data/lib/hamlit/parsers/multiline.rb +1 -1
- data/lib/hamlit/parsers/text.rb +2 -1
- data/lib/hamlit/version.rb +1 -1
- data/spec/hamlit/engine/indent_spec.rb +1 -1
- data/spec/hamlit/engine/multiline_spec.rb +2 -2
- data/spec/hamlit/engine/new_attribute_spec.rb +2 -2
- data/spec/hamlit/engine/old_attributes_spec.rb +17 -7
- data/spec/hamlit/engine/silent_script_spec.rb +4 -4
- data/spec/hamlit/engine/tag_spec.rb +0 -62
- data/spec/hamlit/engine/text_spec.rb +96 -15
- data/spec/hamlit/filters/plain_spec.rb +15 -0
- data/spec/spec_helper.rb +183 -40
- data/test +3 -0
- metadata +17 -4
data/spec/spec_helper.rb
CHANGED
@@ -17,18 +17,20 @@ module HamlitSpecHelper
|
|
17
17
|
def assert_render(haml, html, options = {})
|
18
18
|
errs = array_wrap(options.delete(:error_with) || [])
|
19
19
|
impls = array_wrap(options.delete(:compatible_only) || [:haml, :faml] - errs)
|
20
|
-
|
21
|
-
html = html.unindent
|
20
|
+
fails = [:haml, :faml] - impls - errs
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
(
|
31
|
-
|
22
|
+
test = TestCase.new
|
23
|
+
test.src_haml = haml.unindent
|
24
|
+
test.hamlit_html = html.unindent
|
25
|
+
|
26
|
+
expect(render_string(test.src_haml, options)).to eq(test.hamlit_html)
|
27
|
+
impls.each { |i| expect_compatibility(i, test, options) }
|
28
|
+
errs.each { |i| expect_compatibility(i, test, options, type: :error) }
|
29
|
+
fails.each { |i| expect_compatibility(i, test, options, type: :failure) }
|
30
|
+
|
31
|
+
if TestCase.generate_docs? && (errs.any? || fails.any?)
|
32
|
+
write_caller!(test)
|
33
|
+
TestCase.register_test!(test)
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
@@ -46,48 +48,57 @@ module HamlitSpecHelper
|
|
46
48
|
|
47
49
|
private
|
48
50
|
|
49
|
-
def
|
51
|
+
def write_caller!(test)
|
52
|
+
line = caller.find{ |l| l =~ %r{spec/hamlit} }
|
53
|
+
path, lineno = line.match(/^([^:]+):([0-9]+)/).to_a.last(2)
|
54
|
+
test.lineno = lineno.to_i - 1
|
55
|
+
test.dir, test.file = path.gsub(%r{^.+spec/hamlit/}, '').split('/')
|
56
|
+
end
|
57
|
+
|
58
|
+
def expect_compatibility(impl, test, options, type: :success)
|
50
59
|
case impl
|
51
60
|
when :haml
|
52
|
-
expect_haml(
|
61
|
+
expect_haml(impl, test, options, type)
|
53
62
|
when :faml
|
54
|
-
expect_faml(
|
63
|
+
expect_faml(impl, test, options, type)
|
55
64
|
end
|
56
65
|
end
|
57
66
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
|
67
|
+
def expect_haml(impl, test, options, type)
|
68
|
+
expect_implementation(impl, test, options, type) do |test, options|
|
69
|
+
options = DEFAULT_OPTIONS.merge(options)
|
70
|
+
Haml::Engine.new(test.src_haml, options).render(Object.new, {})
|
71
|
+
end
|
72
|
+
end
|
62
73
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
faml_html = eval Faml::Engine.new(options).call(haml)
|
69
|
-
expect(hamlit_html).to_not eq(faml_html)
|
70
|
-
when :error
|
71
|
-
expect {
|
72
|
-
eval Faml::Engine.new(options).call(haml)
|
73
|
-
}.to raise_error
|
74
|
+
def expect_faml(impl, test, options, type)
|
75
|
+
expect_implementation(impl, test, options, type) do |test, options|
|
76
|
+
options = options.dup
|
77
|
+
options.delete(:escape_html)
|
78
|
+
eval Faml::Engine.new(options).call(test.src_haml)
|
74
79
|
end
|
75
80
|
end
|
76
81
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
82
|
+
def expect_implementation(impl, test, options, type, &block)
|
83
|
+
if type == :error
|
84
|
+
expect { block.call(test, options) }.to raise_error
|
85
|
+
begin
|
86
|
+
block.call(test, options)
|
87
|
+
rescue Exception => e
|
88
|
+
err = "#{e.class}: #{e.message}"
|
89
|
+
test.send(:"#{impl}_html=", err)
|
90
|
+
end
|
91
|
+
return
|
92
|
+
end
|
93
|
+
|
94
|
+
result = block.call(test, options)
|
95
|
+
test.send(:"#{impl}_html=", result)
|
96
|
+
|
80
97
|
case type
|
81
98
|
when :success
|
82
|
-
|
83
|
-
expect(hamlit_html).to eq(haml_html)
|
99
|
+
expect(test.hamlit_html).to eq(result)
|
84
100
|
when :failure
|
85
|
-
|
86
|
-
expect(hamlit_html).to_not eq(haml_html)
|
87
|
-
when :error
|
88
|
-
expect {
|
89
|
-
Haml::Engine.new(haml, options).render(Object.new, {})
|
90
|
-
}.to raise_error
|
101
|
+
expect(test.hamlit_html).to_not eq(result)
|
91
102
|
end
|
92
103
|
end
|
93
104
|
|
@@ -95,6 +106,128 @@ module HamlitSpecHelper
|
|
95
106
|
return arr if arr.is_a?(Array)
|
96
107
|
[arr]
|
97
108
|
end
|
109
|
+
|
110
|
+
def tests
|
111
|
+
@tests ||= []
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# This is used to generate a document automatically.
|
116
|
+
class TestCase < Struct.new(:file, :dir, :lineno, :src_haml, :haml_html, :faml_html, :hamlit_html)
|
117
|
+
class << self
|
118
|
+
def incompatibilities
|
119
|
+
@incompatibilities ||= []
|
120
|
+
end
|
121
|
+
|
122
|
+
def generate_docs!
|
123
|
+
prepare_dirs!
|
124
|
+
generate_toc!
|
125
|
+
|
126
|
+
incompatibilities.group_by(&:doc_path).each do |path, tests|
|
127
|
+
doc = tests.sort_by(&:lineno).map(&:document).join("\n")
|
128
|
+
full_path = File.join(doc_dir, path)
|
129
|
+
File.write(full_path, doc)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def generate_docs?
|
134
|
+
ENV['AUTODOC']
|
135
|
+
end
|
136
|
+
|
137
|
+
def register_test!(test)
|
138
|
+
incompatibilities << test unless @skipdoc
|
139
|
+
end
|
140
|
+
|
141
|
+
def skipdoc(&block)
|
142
|
+
@skipdoc = true
|
143
|
+
block.call
|
144
|
+
ensure
|
145
|
+
@skipdoc = false
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
def generate_toc!
|
151
|
+
table_of_contents = <<-TOC.unindent
|
152
|
+
# Hamlit incompatibilities
|
153
|
+
|
154
|
+
This is a document generated from RSpec test cases.
|
155
|
+
Showing incompatibilities against [Haml](https://github.com/haml/haml) and [Faml](https://github.com/eagletmt/faml).
|
156
|
+
TOC
|
157
|
+
|
158
|
+
incompatibilities.group_by(&:dir).each do |dir, tests|
|
159
|
+
# TODO: Split incompatibility documents into haml and faml
|
160
|
+
# There are too many noisy documents now.
|
161
|
+
next if dir == 'filters'
|
162
|
+
|
163
|
+
table_of_contents << "\n## #{dir}\n"
|
164
|
+
|
165
|
+
tests.group_by(&:doc_path).each do |path, tests|
|
166
|
+
test = tests.first
|
167
|
+
file_path = File.join(test.dir, test.file)
|
168
|
+
base_url = 'https://github.com/k0kubun/hamlit/blob/master/doc/'
|
169
|
+
table_of_contents << "\n- [#{escape_markdown(file_path)}](#{File.join(base_url, path)})"
|
170
|
+
end
|
171
|
+
table_of_contents << "\n"
|
172
|
+
end
|
173
|
+
|
174
|
+
path = File.join(doc_dir, 'README.md')
|
175
|
+
File.write(path, table_of_contents)
|
176
|
+
end
|
177
|
+
|
178
|
+
def prepare_dirs!
|
179
|
+
system("rm -rf #{doc_dir}")
|
180
|
+
incompatibilities.map(&:dir).uniq.each do |dir|
|
181
|
+
system("mkdir -p #{doc_dir}/#{dir}")
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def doc_dir
|
186
|
+
@doc_dir ||= File.expand_path('./doc')
|
187
|
+
end
|
188
|
+
|
189
|
+
def escape_markdown(text)
|
190
|
+
text.gsub(/_/, '\\_')
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def document
|
195
|
+
base_url = 'https://github.com/k0kubun/hamlit/blob/master/spec/hamlit'
|
196
|
+
url = File.join(base_url, dir, file)
|
197
|
+
doc = <<-DOC
|
198
|
+
# [#{escape_markdown("#{file}:#{lineno}")}](#{url}#L#{lineno})
|
199
|
+
## Input
|
200
|
+
```haml
|
201
|
+
#{src_haml}
|
202
|
+
```
|
203
|
+
|
204
|
+
## Output
|
205
|
+
DOC
|
206
|
+
|
207
|
+
html_by_name = {
|
208
|
+
'Haml' => haml_html,
|
209
|
+
'Faml' => faml_html,
|
210
|
+
'Hamlit' => hamlit_html,
|
211
|
+
}
|
212
|
+
html_by_name.group_by(&:last).each do |html, pairs|
|
213
|
+
doc << "### #{pairs.map(&:first).join(', ')}\n"
|
214
|
+
doc << "```html\n"
|
215
|
+
doc << "#{html}\n"
|
216
|
+
doc << "```\n\n"
|
217
|
+
end
|
218
|
+
|
219
|
+
doc
|
220
|
+
end
|
221
|
+
|
222
|
+
def doc_path
|
223
|
+
File.join(dir, file.gsub(/_spec\.rb$/, '.md'))
|
224
|
+
end
|
225
|
+
|
226
|
+
private
|
227
|
+
|
228
|
+
def escape_markdown(text)
|
229
|
+
self.class.send(:escape_markdown, text)
|
230
|
+
end
|
98
231
|
end
|
99
232
|
|
100
233
|
RSpec.configure do |config|
|
@@ -107,4 +240,14 @@ RSpec.configure do |config|
|
|
107
240
|
config.mock_with :rspec do |mocks|
|
108
241
|
mocks.verify_partial_doubles = true
|
109
242
|
end
|
243
|
+
|
244
|
+
config.around(:each, skipdoc: true) do |example|
|
245
|
+
TestCase.skipdoc do
|
246
|
+
example.run
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
config.after(:suite) do
|
251
|
+
TestCase.generate_docs! if TestCase.generate_docs?
|
252
|
+
end
|
110
253
|
end
|
data/test
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamlit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.7.
|
33
|
+
version: 0.7.6
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.7.
|
40
|
+
version: 0.7.6
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: thor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -313,6 +313,18 @@ files:
|
|
313
313
|
- benchmarks/view.rbhtml
|
314
314
|
- benchmarks/view.slim
|
315
315
|
- bin/hamlit
|
316
|
+
- doc/README.md
|
317
|
+
- doc/engine/old_attributes.md
|
318
|
+
- doc/engine/script.md
|
319
|
+
- doc/engine/text.md
|
320
|
+
- doc/filters/coffee.md
|
321
|
+
- doc/filters/erb.md
|
322
|
+
- doc/filters/javascript.md
|
323
|
+
- doc/filters/less.md
|
324
|
+
- doc/filters/markdown.md
|
325
|
+
- doc/filters/plain.md
|
326
|
+
- doc/filters/sass.md
|
327
|
+
- doc/filters/scss.md
|
316
328
|
- hamlit.gemspec
|
317
329
|
- lib/hamlit.rb
|
318
330
|
- lib/hamlit/attribute.rb
|
@@ -390,6 +402,7 @@ files:
|
|
390
402
|
- spec/hamlit/filters/javascript_spec.rb
|
391
403
|
- spec/hamlit/filters/less_spec.rb
|
392
404
|
- spec/hamlit/filters/markdown_spec.rb
|
405
|
+
- spec/hamlit/filters/plain_spec.rb
|
393
406
|
- spec/hamlit/filters/ruby_spec.rb
|
394
407
|
- spec/hamlit/filters/sass_spec.rb
|
395
408
|
- spec/hamlit/filters/scss_spec.rb
|
@@ -504,6 +517,7 @@ test_files:
|
|
504
517
|
- spec/hamlit/filters/javascript_spec.rb
|
505
518
|
- spec/hamlit/filters/less_spec.rb
|
506
519
|
- spec/hamlit/filters/markdown_spec.rb
|
520
|
+
- spec/hamlit/filters/plain_spec.rb
|
507
521
|
- spec/hamlit/filters/ruby_spec.rb
|
508
522
|
- spec/hamlit/filters/sass_spec.rb
|
509
523
|
- spec/hamlit/filters/scss_spec.rb
|
@@ -573,4 +587,3 @@ test_files:
|
|
573
587
|
- spec/rails/vendor/assets/javascripts/.keep
|
574
588
|
- spec/rails/vendor/assets/stylesheets/.keep
|
575
589
|
- spec/spec_helper.rb
|
576
|
-
has_rdoc:
|