hamlit 1.5.9 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/doc/README.md +15 -2
- data/doc/engine/indent.md +24 -0
- data/doc/engine/new_attribute.md +77 -0
- data/doc/engine/old_attributes.md +127 -0
- data/doc/engine/silent_script.md +97 -0
- data/doc/engine/tag.md +48 -0
- data/doc/engine/text.md +7 -1
- data/doc/faml/README.md +19 -0
- data/doc/faml/engine/indent.md +24 -0
- data/doc/faml/engine/old_attributes.md +108 -0
- data/doc/faml/engine/silent_script.md +97 -0
- data/doc/faml/engine/text.md +35 -0
- data/doc/faml/filters/coffee.md +125 -0
- data/doc/faml/filters/erb.md +24 -0
- data/doc/faml/filters/javascript.md +27 -0
- data/doc/faml/filters/less.md +57 -0
- data/doc/faml/filters/plain.md +25 -0
- data/doc/faml/filters/sass.md +62 -0
- data/doc/faml/filters/scss.md +68 -0
- data/doc/haml/README.md +15 -0
- data/doc/haml/engine/new_attribute.md +77 -0
- data/doc/haml/engine/old_attributes.md +142 -0
- data/doc/haml/engine/tag.md +48 -0
- data/doc/haml/engine/text.md +59 -0
- data/doc/haml/filters/erb.md +26 -0
- data/doc/haml/filters/javascript.md +76 -0
- data/doc/haml/filters/markdown.md +31 -0
- data/lib/hamlit/compilers/attributes.rb +1 -1
- data/lib/hamlit/compilers/new_attribute.rb +6 -6
- data/lib/hamlit/compilers/old_attribute.rb +2 -2
- data/lib/hamlit/compilers/text.rb +7 -10
- data/lib/hamlit/concerns/lexable.rb +32 -0
- data/lib/hamlit/parser.rb +9 -8
- data/lib/hamlit/parsers/attribute.rb +6 -3
- data/lib/hamlit/version.rb +1 -1
- data/spec/hamlit/engine/indent_spec.rb +1 -1
- data/spec/hamlit/engine/new_attribute_spec.rb +13 -2
- data/spec/hamlit/engine/old_attributes_spec.rb +5 -5
- data/spec/hamlit/engine/silent_script_spec.rb +4 -4
- data/spec/hamlit/engine/tag_spec.rb +23 -0
- data/spec/hamlit/engine/text_spec.rb +7 -3
- data/spec/spec_helper.rb +7 -231
- data/spec/spec_helper/document_generator.rb +93 -0
- data/spec/spec_helper/render_helper.rb +112 -0
- data/spec/spec_helper/test_case.rb +55 -0
- metadata +33 -3
- data/lib/hamlit/concerns/ripperable.rb +0 -20
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'haml'
|
2
|
+
require 'faml'
|
3
|
+
require 'hamlit'
|
4
|
+
require 'unindent'
|
5
|
+
|
6
|
+
module RenderHelper
|
7
|
+
DEFAULT_OPTIONS = { ugly: true, escape_html: true }.freeze
|
8
|
+
|
9
|
+
def parse_string(str)
|
10
|
+
Hamlit::Parser.new.call(str)
|
11
|
+
end
|
12
|
+
|
13
|
+
def render_string(str, options = {})
|
14
|
+
eval Hamlit::Engine.new(options).call(str)
|
15
|
+
end
|
16
|
+
|
17
|
+
def assert_render(haml, html, options = {})
|
18
|
+
errs = array_wrap(options.delete(:error_with) || [])
|
19
|
+
impls = array_wrap(options.delete(:compatible_only) || [:haml, :faml] - errs)
|
20
|
+
fails = [:haml, :faml] - impls - errs
|
21
|
+
|
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 DocumentGenerator.generate_docs? && (errs.any? || fails.any?)
|
32
|
+
write_caller!(test)
|
33
|
+
DocumentGenerator.register_test!(test)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def assert_parse(haml, &block)
|
38
|
+
haml = haml.unindent
|
39
|
+
ast = block.call
|
40
|
+
|
41
|
+
expect(parse_string(haml)).to eq(ast)
|
42
|
+
end
|
43
|
+
|
44
|
+
def assert_compile(before, after)
|
45
|
+
result = described_class.new.call(before)
|
46
|
+
expect(result).to eq(after)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def write_caller!(test)
|
52
|
+
example = RSpec.current_example
|
53
|
+
test.lineno = example.metadata[:line_number]
|
54
|
+
test.dir, test.file = example.file_path.gsub(%r{^.+spec/hamlit/}, '').split('/')
|
55
|
+
end
|
56
|
+
|
57
|
+
def expect_compatibility(impl, test, options, type: :success)
|
58
|
+
case impl
|
59
|
+
when :haml
|
60
|
+
expect_haml(impl, test, options, type)
|
61
|
+
when :faml
|
62
|
+
expect_faml(impl, test, options, type)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def expect_haml(impl, test, options, type)
|
67
|
+
expect_implementation(impl, test, options, type) do |test, options|
|
68
|
+
options = DEFAULT_OPTIONS.merge(options)
|
69
|
+
Haml::Engine.new(test.src_haml, options).render(Object.new, {})
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def expect_faml(impl, test, options, type)
|
74
|
+
expect_implementation(impl, test, options, type) do |test, options|
|
75
|
+
options = options.dup
|
76
|
+
options.delete(:escape_html)
|
77
|
+
eval Faml::Engine.new(options).call(test.src_haml)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def expect_implementation(impl, test, options, type, &block)
|
82
|
+
if type == :error
|
83
|
+
expect { block.call(test, options) }.to raise_error
|
84
|
+
begin
|
85
|
+
block.call(test, options)
|
86
|
+
rescue Exception => e
|
87
|
+
err = "#{e.class}: #{e.message}"
|
88
|
+
test.send(:"#{impl}_html=", err)
|
89
|
+
end
|
90
|
+
return
|
91
|
+
end
|
92
|
+
|
93
|
+
result = block.call(test, options)
|
94
|
+
test.send(:"#{impl}_html=", result)
|
95
|
+
|
96
|
+
case type
|
97
|
+
when :success
|
98
|
+
expect(test.hamlit_html).to eq(result)
|
99
|
+
when :failure
|
100
|
+
expect(test.hamlit_html).to_not eq(result)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def array_wrap(arr)
|
105
|
+
return arr if arr.is_a?(Array)
|
106
|
+
[arr]
|
107
|
+
end
|
108
|
+
|
109
|
+
def tests
|
110
|
+
@tests ||= []
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'unindent'
|
2
|
+
|
3
|
+
# This is used to generate a document automatically.
|
4
|
+
class TestCase < Struct.new(:file, :dir, :lineno, :src_haml, :haml_html, :faml_html, :hamlit_html)
|
5
|
+
def document(impl)
|
6
|
+
base_path = '/spec/hamlit'
|
7
|
+
path = File.join(base_path, dir, file)
|
8
|
+
doc = <<-DOC
|
9
|
+
# [#{escape_markdown("#{file}:#{lineno}")}](#{path}#L#{lineno})
|
10
|
+
## Input
|
11
|
+
```haml
|
12
|
+
#{src_haml}
|
13
|
+
```
|
14
|
+
|
15
|
+
## Output
|
16
|
+
DOC
|
17
|
+
|
18
|
+
html_by_name = {
|
19
|
+
'Haml' => haml_html,
|
20
|
+
'Faml' => faml_html,
|
21
|
+
'Hamlit' => hamlit_html,
|
22
|
+
}
|
23
|
+
|
24
|
+
case impl
|
25
|
+
when 'haml'
|
26
|
+
html_by_name.delete('Faml')
|
27
|
+
when 'faml'
|
28
|
+
html_by_name.delete('Haml')
|
29
|
+
end
|
30
|
+
|
31
|
+
html_by_name.group_by(&:last).each do |html, pairs|
|
32
|
+
doc << "### #{pairs.map(&:first).join(', ')}\n"
|
33
|
+
doc << "```html\n"
|
34
|
+
doc << "#{html}\n"
|
35
|
+
doc << "```\n\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
doc
|
39
|
+
end
|
40
|
+
|
41
|
+
def doc_path
|
42
|
+
File.join(dir, file.gsub(/_spec\.rb$/, '.md'))
|
43
|
+
end
|
44
|
+
|
45
|
+
def spec_path
|
46
|
+
path = File.join(dir, file)
|
47
|
+
escape_markdown(path)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def escape_markdown(text)
|
53
|
+
text.gsub(/_/, '\\_')
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamlit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -299,8 +299,24 @@ files:
|
|
299
299
|
- benchmarks/view.slim
|
300
300
|
- bin/hamlit
|
301
301
|
- doc/README.md
|
302
|
+
- doc/engine/indent.md
|
303
|
+
- doc/engine/new_attribute.md
|
302
304
|
- doc/engine/old_attributes.md
|
305
|
+
- doc/engine/silent_script.md
|
306
|
+
- doc/engine/tag.md
|
303
307
|
- doc/engine/text.md
|
308
|
+
- doc/faml/README.md
|
309
|
+
- doc/faml/engine/indent.md
|
310
|
+
- doc/faml/engine/old_attributes.md
|
311
|
+
- doc/faml/engine/silent_script.md
|
312
|
+
- doc/faml/engine/text.md
|
313
|
+
- doc/faml/filters/coffee.md
|
314
|
+
- doc/faml/filters/erb.md
|
315
|
+
- doc/faml/filters/javascript.md
|
316
|
+
- doc/faml/filters/less.md
|
317
|
+
- doc/faml/filters/plain.md
|
318
|
+
- doc/faml/filters/sass.md
|
319
|
+
- doc/faml/filters/scss.md
|
304
320
|
- doc/filters/coffee.md
|
305
321
|
- doc/filters/erb.md
|
306
322
|
- doc/filters/javascript.md
|
@@ -309,6 +325,14 @@ files:
|
|
309
325
|
- doc/filters/plain.md
|
310
326
|
- doc/filters/sass.md
|
311
327
|
- doc/filters/scss.md
|
328
|
+
- doc/haml/README.md
|
329
|
+
- doc/haml/engine/new_attribute.md
|
330
|
+
- doc/haml/engine/old_attributes.md
|
331
|
+
- doc/haml/engine/tag.md
|
332
|
+
- doc/haml/engine/text.md
|
333
|
+
- doc/haml/filters/erb.md
|
334
|
+
- doc/haml/filters/javascript.md
|
335
|
+
- doc/haml/filters/markdown.md
|
312
336
|
- hamlit.gemspec
|
313
337
|
- lib/hamlit.rb
|
314
338
|
- lib/hamlit/attribute.rb
|
@@ -331,9 +355,9 @@ files:
|
|
331
355
|
- lib/hamlit/concerns/escapable.rb
|
332
356
|
- lib/hamlit/concerns/included.rb
|
333
357
|
- lib/hamlit/concerns/indentable.rb
|
358
|
+
- lib/hamlit/concerns/lexable.rb
|
334
359
|
- lib/hamlit/concerns/line_reader.rb
|
335
360
|
- lib/hamlit/concerns/registerable.rb
|
336
|
-
- lib/hamlit/concerns/ripperable.rb
|
337
361
|
- lib/hamlit/concerns/string_interpolation.rb
|
338
362
|
- lib/hamlit/concerns/whitespace.rb
|
339
363
|
- lib/hamlit/engine.rb
|
@@ -457,6 +481,9 @@ files:
|
|
457
481
|
- spec/rails/vendor/assets/javascripts/.keep
|
458
482
|
- spec/rails/vendor/assets/stylesheets/.keep
|
459
483
|
- spec/spec_helper.rb
|
484
|
+
- spec/spec_helper/document_generator.rb
|
485
|
+
- spec/spec_helper/render_helper.rb
|
486
|
+
- spec/spec_helper/test_case.rb
|
460
487
|
- test
|
461
488
|
homepage: https://github.com/k0kubun/hamlit
|
462
489
|
licenses:
|
@@ -573,3 +600,6 @@ test_files:
|
|
573
600
|
- spec/rails/vendor/assets/javascripts/.keep
|
574
601
|
- spec/rails/vendor/assets/stylesheets/.keep
|
575
602
|
- spec/spec_helper.rb
|
603
|
+
- spec/spec_helper/document_generator.rb
|
604
|
+
- spec/spec_helper/render_helper.rb
|
605
|
+
- spec/spec_helper/test_case.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'ripper'
|
2
|
-
|
3
|
-
module Hamlit
|
4
|
-
module Concerns
|
5
|
-
module Ripperable
|
6
|
-
TYPE_POSITION = 1
|
7
|
-
|
8
|
-
def skip_tokens!(tokens, *types)
|
9
|
-
while types.include?(type_of(tokens.first))
|
10
|
-
tokens.shift
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def type_of(token)
|
15
|
-
return nil unless token
|
16
|
-
token[TYPE_POSITION]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|