faml 0.2.8 → 0.2.9
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/.travis.yml +1 -1
- data/CHANGELOG.md +6 -0
- data/README.md +4 -0
- data/Rakefile +20 -3
- data/benchmark/compiling.rb +23 -0
- data/lib/faml/cli.rb +2 -1
- data/lib/faml/compiler.rb +8 -1
- data/lib/faml/element_parser.rb +2 -2
- data/lib/faml/line_parser.rb +3 -3
- data/lib/faml/parser.rb +14 -2
- data/lib/faml/ruby_multiline.rb +1 -1
- data/lib/faml/static_hash_parser.rb +3 -1
- data/lib/faml/version.rb +1 -1
- data/spec/compiler_newline_spec.rb +40 -0
- data/spec/render/attribute_spec.rb +7 -0
- data/spec/render/doctype_spec.rb +7 -0
- data/spec/render/multiline_spec.rb +9 -0
- data/spec/render/plain_spec.rb +7 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da0d5a40e368fd95bce13511a6c083c338a79698
|
4
|
+
data.tar.gz: 5835483174f686095295d5a93dcd00decd5c1e49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc1faad685fd051a3a2fcbd63f4dc6059b300d6e66a57aad98e77662f13da0bcc4205bd261f2d90bfa9bb5f9abf23ba504be2c988e168ef9f282a90ec7dd6c09
|
7
|
+
data.tar.gz: 1cf54d88358b06fdd8f9b2c78a2415820fc83a0f806ab16bd4a98b076b03fcc8bbf93e069d0f3cb5fc1337c8b5a682acbeca952c35b33df612200386a2ff0b68
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.2.9 (2015-04-04)
|
2
|
+
- Keep code newlines with multiline
|
3
|
+
- https://github.com/eagletmt/faml/issues/18
|
4
|
+
- Disable haml multiline syntax within filter
|
5
|
+
- Fix `__LINE__` and `__FILE__` in attribute lists
|
6
|
+
|
1
7
|
## 0.2.8 (2015-04-02)
|
2
8
|
- Allow empty silent script body
|
3
9
|
- For compatibility with haml
|
data/README.md
CHANGED
@@ -58,6 +58,10 @@ is always rendered as
|
|
58
58
|
|
59
59
|
It's equivalent to haml's "ugly" mode.
|
60
60
|
|
61
|
+
### No Haml::Helpers except for preserve
|
62
|
+
I won't provide helper methods of Haml::Helpers except for `preserve` .
|
63
|
+
If you really need other helper methods, please open an issue.
|
64
|
+
|
61
65
|
### Others
|
62
66
|
If you find other incompatibility, please report it to me :-p.
|
63
67
|
|
data/Rakefile
CHANGED
@@ -10,24 +10,41 @@ end
|
|
10
10
|
require 'rspec/core/rake_task'
|
11
11
|
RSpec::Core::RakeTask.new(:spec)
|
12
12
|
|
13
|
+
task :benchmark => ['benchmark:rendering', 'benchmark:compiling']
|
14
|
+
|
13
15
|
namespace :benchmark do
|
14
16
|
task :rendering => ['benchmark:rendering:haml', 'benchmark:rendering:attributes', 'benchmark:rendering:slim']
|
15
17
|
namespace :rendering do
|
16
|
-
desc "Run benchmark with Haml's standard template"
|
18
|
+
desc "Run rendering benchmark with Haml's standard template"
|
17
19
|
task :haml do
|
18
20
|
haml_gem = Gem::Specification.find_by_name('haml')
|
19
21
|
standard_haml_path = File.join(haml_gem.gem_dir, 'test', 'templates', 'standard.haml')
|
20
22
|
sh 'ruby', 'benchmark/rendering.rb', standard_haml_path
|
21
23
|
end
|
22
24
|
|
23
|
-
desc "Run benchmark for attribute builder"
|
25
|
+
desc "Run rendering benchmark for attribute builder"
|
24
26
|
task :attributes do
|
25
27
|
sh 'ruby', 'benchmark/rendering.rb', 'benchmark/attribute_builder.haml', 'benchmark/attribute_builder.slim'
|
26
28
|
end
|
27
29
|
|
28
|
-
desc "Run slim's benchmark"
|
30
|
+
desc "Run slim's rendering benchmark"
|
29
31
|
task :slim do
|
30
32
|
sh 'ruby', 'benchmark/slim.rb'
|
31
33
|
end
|
32
34
|
end
|
35
|
+
|
36
|
+
task :compiling => ['benchmark:compiling:haml', 'benchmark:compiling:slim']
|
37
|
+
namespace :compiling do
|
38
|
+
desc "Run compiling benchmark with Haml's standard template"
|
39
|
+
task :haml do
|
40
|
+
haml_gem = Gem::Specification.find_by_name('haml')
|
41
|
+
standard_haml_path = File.join(haml_gem.gem_dir, 'test', 'templates', 'standard.haml')
|
42
|
+
sh 'ruby', 'benchmark/compiling.rb', standard_haml_path
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "Run slim's compiling benchmark"
|
46
|
+
task :slim do
|
47
|
+
sh 'ruby', 'benchmark/compiling.rb', 'benchmark/view.haml', 'benchmark/view.slim'
|
48
|
+
end
|
49
|
+
end
|
33
50
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'benchmark/ips'
|
3
|
+
require 'haml'
|
4
|
+
require 'faml'
|
5
|
+
require 'slim'
|
6
|
+
require 'escape_utils/html/haml'
|
7
|
+
|
8
|
+
unless ARGV[0]
|
9
|
+
$stderr.puts "Usage: #{$0} template.haml [template.slim]"
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
|
13
|
+
haml_code = File.read(ARGV[0])
|
14
|
+
slim_code = ARGV[1] ? File.read(ARGV[1]) : nil
|
15
|
+
|
16
|
+
Benchmark.ips do |x|
|
17
|
+
x.report('Haml') { Haml::Engine.new(haml_code, ugly: true, escape_html: true) }
|
18
|
+
x.report('Faml') { Faml::Engine.new.call(haml_code) }
|
19
|
+
if slim_code
|
20
|
+
x.report('Slim') { Slim::Engine.new.call(slim_code) }
|
21
|
+
end
|
22
|
+
x.compare!
|
23
|
+
end
|
data/lib/faml/cli.rb
CHANGED
data/lib/faml/compiler.rb
CHANGED
@@ -228,7 +228,8 @@ module Faml
|
|
228
228
|
end
|
229
229
|
|
230
230
|
if attrs = try_optimize_attributes(text, static_id, static_class)
|
231
|
-
|
231
|
+
line_count = text.count("\n")
|
232
|
+
return [:multi, [:html, :attrs, *attrs]].concat([[:newline]] * line_count)
|
232
233
|
end
|
233
234
|
|
234
235
|
# Slow version
|
@@ -278,6 +279,12 @@ module Faml
|
|
278
279
|
return nil
|
279
280
|
end
|
280
281
|
|
282
|
+
if text.include?("\n") && !dynamic_attributes.empty?
|
283
|
+
# XXX: Quit optimization to keep newlines
|
284
|
+
# https://github.com/eagletmt/faml/issues/18
|
285
|
+
return nil
|
286
|
+
end
|
287
|
+
|
281
288
|
(static_attributes.keys + dynamic_attributes.keys).sort.flat_map do |k|
|
282
289
|
if static_attributes.has_key?(k)
|
283
290
|
compile_static_attribute(k, static_attributes[k])
|
data/lib/faml/element_parser.rb
CHANGED
@@ -99,7 +99,7 @@ module Faml
|
|
99
99
|
return [attr[1, attr.size-2], s.rest]
|
100
100
|
else
|
101
101
|
if /,\s*\z/ === text && @line_parser.has_next?
|
102
|
-
text << @line_parser.next_line
|
102
|
+
text << "\n" << @line_parser.next_line
|
103
103
|
else
|
104
104
|
syntax_error!('Unmatched brace')
|
105
105
|
end
|
@@ -122,7 +122,7 @@ module Faml
|
|
122
122
|
return [new_attributes, s.rest]
|
123
123
|
else
|
124
124
|
if @line_parser.has_next?
|
125
|
-
text <<
|
125
|
+
text << "\n" << @line_parser.next_line
|
126
126
|
else
|
127
127
|
syntax_error!('Unmatched paren')
|
128
128
|
end
|
data/lib/faml/line_parser.rb
CHANGED
@@ -8,9 +8,9 @@ module Faml
|
|
8
8
|
@lineno = 0
|
9
9
|
end
|
10
10
|
|
11
|
-
def next_line
|
11
|
+
def next_line(in_filter: false)
|
12
12
|
line = move_next
|
13
|
-
if is_multiline?(line)
|
13
|
+
if !in_filter && is_multiline?(line)
|
14
14
|
next_multiline(line)
|
15
15
|
else
|
16
16
|
line
|
@@ -61,7 +61,7 @@ module Faml
|
|
61
61
|
break
|
62
62
|
end
|
63
63
|
end
|
64
|
-
buf.join
|
64
|
+
buf.join("\n")
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
data/lib/faml/parser.rb
CHANGED
@@ -23,15 +23,21 @@ module Faml
|
|
23
23
|
@filter_parser = FilterParser.new(@indent_tracker)
|
24
24
|
|
25
25
|
while @line_parser.has_next?
|
26
|
-
|
27
|
-
|
26
|
+
in_filter = !@ast.is_a?(Ast::HamlComment) && @filter_parser.enabled?
|
27
|
+
line = @line_parser.next_line(in_filter: in_filter)
|
28
|
+
if in_filter
|
28
29
|
ast = @filter_parser.append(line)
|
29
30
|
if ast
|
30
31
|
@ast << ast
|
31
32
|
end
|
32
33
|
end
|
33
34
|
unless @filter_parser.enabled?
|
35
|
+
line_count = line.count("\n")
|
36
|
+
line.delete!("\n")
|
34
37
|
parse_line(line)
|
38
|
+
line_count.times do
|
39
|
+
@ast << create_node(Ast::Empty)
|
40
|
+
end
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
@@ -165,6 +171,12 @@ module Faml
|
|
165
171
|
end
|
166
172
|
@stack.push(@ast)
|
167
173
|
@ast = @ast.children.last
|
174
|
+
case @ast
|
175
|
+
when Ast::Text
|
176
|
+
syntax_error!('nesting within plain text is illegal')
|
177
|
+
when Ast::Doctype
|
178
|
+
syntax_error!('nesting within a header command is illegal')
|
179
|
+
end
|
168
180
|
@ast.children = empty_lines
|
169
181
|
if @ast.is_a?(Ast::Element) && @ast.self_closing
|
170
182
|
syntax_error!('Illegal nesting: nesting within a self-closing tag is illegal')
|
data/lib/faml/ruby_multiline.rb
CHANGED
@@ -14,7 +14,9 @@ module Faml
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def parse(text)
|
17
|
-
|
17
|
+
builder = ::Parser::Builders::Default.new
|
18
|
+
builder.emit_file_line_as_literals = false
|
19
|
+
parser = ::Parser::CurrentRuby.new(builder)
|
18
20
|
parser.diagnostics.consumer = nil
|
19
21
|
buffer = ::Parser::Source::Buffer.new('(faml)')
|
20
22
|
buffer.source = text
|
data/lib/faml/version.rb
CHANGED
@@ -155,6 +155,46 @@ HAML
|
|
155
155
|
}
|
156
156
|
|
157
157
|
%span= raise LineVerifier
|
158
|
+
HAML
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'with multiline' do
|
163
|
+
it 'keeps newlines in static attributes' do
|
164
|
+
expect { render_string(<<HAML) }.to raise_error(LineVerifier, raised_at(3))
|
165
|
+
%span{a: 1,
|
166
|
+
b: 2}
|
167
|
+
= raise LineVerifier
|
168
|
+
HAML
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'keeps newlines in dynamic attributes' do
|
172
|
+
expect { render_string(<<HAML) }.to raise_error(LineVerifier, raised_at(2))
|
173
|
+
%span{a: 1,
|
174
|
+
b: raise(LineVerifier)}
|
175
|
+
hello
|
176
|
+
HAML
|
177
|
+
expect { render_string(<<HAML) }.to raise_error(LineVerifier, raised_at(3))
|
178
|
+
%span{a: 1,
|
179
|
+
b: 2 + 3}
|
180
|
+
= raise LineVerifier
|
181
|
+
HAML
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'keeps newlines in ruby attributes' do
|
185
|
+
expect { render_string(<<HAML) }.to raise_error(LineVerifier, raised_at(2))
|
186
|
+
%span{[1,
|
187
|
+
raise(LineVerifier)]}
|
188
|
+
hello
|
189
|
+
HAML
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'keeps newlines in haml multiline' do
|
193
|
+
expect(render_string(<<HAML)).to eq("foo bar 1\n4\n")
|
194
|
+
= 'foo ' + |
|
195
|
+
'bar ' + |
|
196
|
+
__LINE__.to_s |
|
197
|
+
= __LINE__
|
158
198
|
HAML
|
159
199
|
end
|
160
200
|
end
|
@@ -175,6 +175,13 @@ HAML
|
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
+
it 'renders __LINE__ correctly' do
|
179
|
+
expect(render_string(<<HAML)).to eq("<span a='2' b='1'></span>\n")
|
180
|
+
%span{b: __LINE__,
|
181
|
+
a: __LINE__}
|
182
|
+
HAML
|
183
|
+
end
|
184
|
+
|
178
185
|
describe 'with HTML-style attributes' do
|
179
186
|
it 'parses simple values' do
|
180
187
|
expect(render_string('%span(foo=1 bar=3) hello')).to eq("<span bar='3' foo='1'>hello</span>\n")
|
data/spec/render/doctype_spec.rb
CHANGED
@@ -54,4 +54,11 @@ RSpec.describe 'Doctype rendering', type: :render do
|
|
54
54
|
expect(render_string('!!! 5', format: :xhtml)).to eq(%Q|<!DOCTYPE html>\n|)
|
55
55
|
end
|
56
56
|
end
|
57
|
+
|
58
|
+
it 'raises error when doctype has children' do
|
59
|
+
expect { render_string(<<HAML) }.to raise_error(Faml::SyntaxError, /nesting within a header command/)
|
60
|
+
!!!
|
61
|
+
hello
|
62
|
+
HAML
|
63
|
+
end
|
57
64
|
end
|
@@ -41,6 +41,15 @@ HAML
|
|
41
41
|
expect(render_string(<<HAML)).to eq("<div bar='2' foo='1'></div>\n")
|
42
42
|
%div{foo: 1, |
|
43
43
|
bar: 2}
|
44
|
+
HAML
|
45
|
+
end
|
46
|
+
|
47
|
+
it "isn't enabled in filter" do
|
48
|
+
expect(render_string(<<HAML)).to eq("<script>\n hello |\n world |\n</script>\n4\n")
|
49
|
+
:javascript
|
50
|
+
hello |
|
51
|
+
world |
|
52
|
+
= __LINE__
|
44
53
|
HAML
|
45
54
|
end
|
46
55
|
end
|
data/spec/render/plain_spec.rb
CHANGED
@@ -17,4 +17,11 @@ HAML
|
|
17
17
|
it 'raises error when interpolation is unterminated' do
|
18
18
|
expect { render_string('%span foo#{1 + 2') }.to raise_error(Faml::TextCompiler::InvalidInterpolation)
|
19
19
|
end
|
20
|
+
|
21
|
+
it 'raises error when text has children' do
|
22
|
+
expect { render_string(<<HAML) }.to raise_error(Faml::SyntaxError, /nesting within plain text/)
|
23
|
+
hello
|
24
|
+
world
|
25
|
+
HAML
|
26
|
+
end
|
20
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Suzuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -269,6 +269,7 @@ files:
|
|
269
269
|
- Rakefile
|
270
270
|
- benchmark/attribute_builder.haml
|
271
271
|
- benchmark/attribute_builder.slim
|
272
|
+
- benchmark/compiling.rb
|
272
273
|
- benchmark/context.rb
|
273
274
|
- benchmark/rendering.rb
|
274
275
|
- benchmark/slim.rb
|
@@ -432,7 +433,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
432
433
|
version: '0'
|
433
434
|
requirements: []
|
434
435
|
rubyforge_project:
|
435
|
-
rubygems_version: 2.
|
436
|
+
rubygems_version: 2.4.5
|
436
437
|
signing_key:
|
437
438
|
specification_version: 4
|
438
439
|
summary: Faster implementation of Haml template language.
|