haml_parser 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +46 -0
- data/.rubocop_todo.yml +28 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.md +8 -0
- data/Rakefile +23 -2
- data/bin/console +3 -3
- data/haml_parser.gemspec +20 -17
- data/lib/haml_parser.rb +1 -1
- data/lib/haml_parser/ast.rb +16 -16
- data/lib/haml_parser/cli.rb +2 -1
- data/lib/haml_parser/element_parser.rb +11 -10
- data/lib/haml_parser/filter_parser.rb +3 -3
- data/lib/haml_parser/indent_tracker.rb +4 -4
- data/lib/haml_parser/line_parser.rb +2 -2
- data/lib/haml_parser/parser.rb +14 -16
- data/lib/haml_parser/ruby_multiline.rb +2 -2
- data/lib/haml_parser/script_parser.rb +11 -11
- data/lib/haml_parser/version.rb +1 -1
- metadata +48 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1ee2e978b5969cf7f28d4b58df013a97988d26e
|
4
|
+
data.tar.gz: 2c18d9f3232488d668794f0c920b2fd3fc58a989
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70f270214c9c7bf34807e4b30fe70bed2d6e67c21f1d94541257739b3cddc6c012dbacd6a41d9feba25e8647c3c7bb13cf79cb1f9f6b47a0d5de4cb737cee1b6
|
7
|
+
data.tar.gz: 77c69264173959110a1e28661c06c1694d5f73b5c37306d6f205d2e7a08187f4d37c94ac091c5c2edd9c8f04c9e203ba43e969d3fa1b4414f6de253d08ac0315
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
Style/BarePercentLiterals:
|
4
|
+
EnforcedStyle: percent_q
|
5
|
+
|
6
|
+
Style/CaseEquality:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Style/GuardClause:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Style/HashSyntax:
|
13
|
+
Exclude:
|
14
|
+
- 'Rakefile'
|
15
|
+
|
16
|
+
Style/IfUnlessModifier:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/Lambda:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/Next:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/PercentLiteralDelimiters:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/RaiseArgs:
|
29
|
+
EnforcedStyle: compact
|
30
|
+
|
31
|
+
Style/SignalException:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Style/Tab:
|
35
|
+
Exclude:
|
36
|
+
- 'spec/indent_spec.rb'
|
37
|
+
|
38
|
+
Style/TrailingComma:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Style/TrailingWhitespace:
|
42
|
+
Exclude:
|
43
|
+
- 'spec/multiline_spec.rb'
|
44
|
+
|
45
|
+
Style/UnneededPercentQ:
|
46
|
+
Enabled: false # buggy
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Metrics/AbcSize:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Metrics/ClassLength:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Metrics/CyclomaticComplexity:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/LineLength:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Metrics/MethodLength:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/ModuleLength:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/PerceivedComplexity:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/Documentation:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/PredicateName:
|
26
|
+
Exclude:
|
27
|
+
- 'lib/haml_parser/line_parser.rb'
|
28
|
+
- 'lib/haml_parser/ruby_multiline.rb'
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# 0.1.1 (2015-10-13)
|
2
|
+
- Fix missing require in CLI
|
3
|
+
|
4
|
+
# 0.1.0 (2015-09-13)
|
5
|
+
- Initial release. Extracted from faml v0.2.16.
|
6
|
+
- Fix preserve flag in `~ foobar` syntax
|
7
|
+
- Set filename correctly to `Ast::Filter`
|
8
|
+
- Remove `Ast::Script#mid_block_keyword` attribute
|
data/Rakefile
CHANGED
@@ -1,6 +1,27 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
2
|
|
3
|
-
task :default => :spec
|
3
|
+
task :default => [:spec, :rubocop]
|
4
4
|
|
5
5
|
require 'rspec/core/rake_task'
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
RuboCop::RakeTask.new(:rubocop)
|
10
|
+
|
11
|
+
desc 'Run all benchmarks'
|
12
|
+
task :benchmark => ['benchmark:sample', 'benchmark:haml']
|
13
|
+
|
14
|
+
namespace :benchmark do
|
15
|
+
desc "Run benchmark with haml_parser's sample"
|
16
|
+
task :sample do
|
17
|
+
sample_haml_path = File.join(__dir__, 'spec', 'fixtures', 'sample.haml')
|
18
|
+
sh 'ruby', 'benchmark/parse.rb', sample_haml_path
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Run benchmark with haml's sample"
|
22
|
+
task :haml do
|
23
|
+
haml_gem = Gem::Specification.find_by_name('haml')
|
24
|
+
standard_haml_path = File.join(haml_gem.gem_dir, 'test', 'templates', 'standard.haml')
|
25
|
+
sh 'ruby', 'benchmark/parse.rb', standard_haml_path
|
26
|
+
end
|
27
|
+
end
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'haml_parser'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "haml_parser"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/haml_parser.gemspec
CHANGED
@@ -4,26 +4,29 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'haml_parser/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'haml_parser'
|
8
8
|
spec.version = HamlParser::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Kohei Suzuki']
|
10
|
+
spec.email = ['eagletmt@gmail.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
12
|
+
spec.summary = 'Parser of Haml template language'
|
13
|
+
spec.description = 'Parser of Haml template language'
|
14
|
+
spec.homepage = 'https://github.com/eagletmt/haml_parser'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|benchmark)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
21
|
-
spec.required_ruby_version =
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
spec.required_ruby_version = '>= 2.0.0'
|
22
22
|
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
23
|
+
spec.add_development_dependency 'benchmark-ips'
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'coveralls'
|
26
|
+
spec.add_development_dependency 'haml'
|
27
|
+
spec.add_development_dependency 'pry'
|
28
|
+
spec.add_development_dependency 'rake'
|
29
|
+
spec.add_development_dependency 'rspec', '>= 3.3.0'
|
30
|
+
spec.add_development_dependency 'rubocop'
|
31
|
+
spec.add_development_dependency 'simplecov'
|
29
32
|
end
|
data/lib/haml_parser.rb
CHANGED
data/lib/haml_parser/ast.rb
CHANGED
@@ -15,7 +15,7 @@ module HamlParser
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
Root = Struct.new(:children) do
|
19
19
|
include HasChildren
|
20
20
|
|
21
21
|
def to_h
|
@@ -23,13 +23,13 @@ module HamlParser
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
Doctype = Struct.new(:doctype, :filename, :lineno) do
|
27
27
|
def to_h
|
28
28
|
super.merge(type: 'doctype')
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
Element = Struct.new(
|
33
33
|
:children,
|
34
34
|
:tag_name,
|
35
35
|
:static_class,
|
@@ -41,7 +41,7 @@ module HamlParser
|
|
41
41
|
:nuke_outer_whitespace,
|
42
42
|
:filename,
|
43
43
|
:lineno,
|
44
|
-
)
|
44
|
+
) do
|
45
45
|
include HasChildren
|
46
46
|
|
47
47
|
def initialize(*)
|
@@ -62,22 +62,22 @@ module HamlParser
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
Script = Struct.new(
|
66
66
|
:children,
|
67
67
|
:script,
|
68
68
|
:escape_html,
|
69
69
|
:preserve,
|
70
70
|
:filename,
|
71
71
|
:lineno,
|
72
|
-
)
|
72
|
+
) do
|
73
73
|
include HasChildren
|
74
74
|
|
75
75
|
def initialize(*)
|
76
76
|
super
|
77
|
-
if
|
77
|
+
if escape_html.nil?
|
78
78
|
self.escape_html = true
|
79
79
|
end
|
80
|
-
if
|
80
|
+
if preserve.nil?
|
81
81
|
self.preserve = false
|
82
82
|
end
|
83
83
|
end
|
@@ -87,12 +87,12 @@ module HamlParser
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
|
90
|
+
SilentScript = Struct.new(:children, :script, :mid_block_keyword, :filename, :lineno) do
|
91
91
|
include HasChildren
|
92
92
|
|
93
93
|
def initialize(*)
|
94
94
|
super
|
95
|
-
if
|
95
|
+
if mid_block_keyword.nil?
|
96
96
|
self.mid_block_keyword = false
|
97
97
|
end
|
98
98
|
end
|
@@ -102,7 +102,7 @@ module HamlParser
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
|
105
|
+
HtmlComment = Struct.new(:children, :comment, :conditional, :filename, :lineno) do
|
106
106
|
include HasChildren
|
107
107
|
|
108
108
|
def initialize(*)
|
@@ -116,7 +116,7 @@ module HamlParser
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
|
119
|
+
HamlComment = Struct.new(:children, :filename, :lineno) do
|
120
120
|
include HasChildren
|
121
121
|
|
122
122
|
def to_h
|
@@ -124,10 +124,10 @@ module HamlParser
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
-
|
127
|
+
Text = Struct.new(:text, :escape_html, :filename, :lineno) do
|
128
128
|
def initialize(*)
|
129
129
|
super
|
130
|
-
if
|
130
|
+
if escape_html.nil?
|
131
131
|
self.escape_html = true
|
132
132
|
end
|
133
133
|
end
|
@@ -137,7 +137,7 @@ module HamlParser
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
-
|
140
|
+
Filter = Struct.new(:name, :texts, :filename, :lineno) do
|
141
141
|
def initialize(*)
|
142
142
|
super
|
143
143
|
self.texts ||= []
|
@@ -148,7 +148,7 @@ module HamlParser
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
|
-
|
151
|
+
Empty = Struct.new(:filename, :lineno) do
|
152
152
|
def to_h
|
153
153
|
super.merge(type: 'empty')
|
154
154
|
end
|
data/lib/haml_parser/cli.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'optparse'
|
2
|
+
require_relative 'version'
|
2
3
|
|
3
4
|
module HamlParser
|
4
5
|
class CLI
|
@@ -13,7 +14,7 @@ module HamlParser
|
|
13
14
|
parser.on('-f FORMAT', '--format FORMAT', 'Select formatter') { |v| formatter = v }
|
14
15
|
end.parse!(argv)
|
15
16
|
|
16
|
-
|
17
|
+
require_relative 'parser'
|
17
18
|
argv.each do |file|
|
18
19
|
format(parse_file(file), formatter)
|
19
20
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'strscan'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
require_relative 'ast'
|
3
|
+
require_relative 'error'
|
4
|
+
require_relative 'ruby_multiline'
|
5
|
+
require_relative 'script_parser'
|
6
|
+
require_relative 'utils'
|
7
7
|
|
8
8
|
module HamlParser
|
9
9
|
class ElementParser
|
@@ -84,7 +84,7 @@ module HamlParser
|
|
84
84
|
if attributes.empty?
|
85
85
|
attributes = new_attributes
|
86
86
|
else
|
87
|
-
attributes <<
|
87
|
+
attributes << ', ' << new_attributes
|
88
88
|
end
|
89
89
|
end
|
90
90
|
[attributes, rest]
|
@@ -99,7 +99,7 @@ module HamlParser
|
|
99
99
|
depth = Utils.balance(s, '{', '}', depth)
|
100
100
|
if depth == 0
|
101
101
|
attr = s.pre_match + s.matched
|
102
|
-
return [attr[1, attr.size-2], s.rest]
|
102
|
+
return [attr[1, attr.size - 2], s.rest]
|
103
103
|
else
|
104
104
|
if /,\s*\z/ === text && @line_parser.has_next?
|
105
105
|
text << "\n" << @line_parser.next_line
|
@@ -119,7 +119,7 @@ module HamlParser
|
|
119
119
|
pre_pos = s.pos
|
120
120
|
depth = Utils.balance(s, '(', ')', depth)
|
121
121
|
if depth == 0
|
122
|
-
t = s.string.byteslice(pre_pos
|
122
|
+
t = s.string.byteslice(pre_pos...s.pos - 1)
|
123
123
|
return [parse_new_attribute_list(t), s.rest]
|
124
124
|
else
|
125
125
|
if @line_parser.has_next?
|
@@ -165,7 +165,8 @@ module HamlParser
|
|
165
165
|
end
|
166
166
|
|
167
167
|
def scan_value(scanner)
|
168
|
-
|
168
|
+
quote = scanner.scan(/["']/)
|
169
|
+
if quote
|
169
170
|
scan_quoted_value(scanner, quote)
|
170
171
|
else
|
171
172
|
scan_variable_value(scanner)
|
@@ -187,7 +188,7 @@ module HamlParser
|
|
187
188
|
syntax_error!('Invalid attribute list (mismatched interpolation)')
|
188
189
|
end
|
189
190
|
end
|
190
|
-
str = scanner.string.byteslice(pos-1
|
191
|
+
str = scanner.string.byteslice(pos - 1..scanner.pos - 1)
|
191
192
|
|
192
193
|
# Even if the quote is single, string interpolation is performed in Haml.
|
193
194
|
str[0] = '"'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'ast'
|
2
2
|
|
3
3
|
module HamlParser
|
4
4
|
class FilterParser
|
@@ -9,7 +9,7 @@ module HamlParser
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def enabled?
|
12
|
-
|
12
|
+
!@ast.nil?
|
13
13
|
end
|
14
14
|
|
15
15
|
def start(name, filename, lineno)
|
@@ -46,7 +46,7 @@ module HamlParser
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
text = line[@indent_level
|
49
|
+
text = line[@indent_level..-1]
|
50
50
|
@ast.texts << text
|
51
51
|
nil
|
52
52
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'error'
|
2
2
|
|
3
3
|
module HamlParser
|
4
4
|
class IndentTracker
|
@@ -30,8 +30,8 @@ module HamlParser
|
|
30
30
|
|
31
31
|
def initialize(on_enter: nil, on_leave: nil)
|
32
32
|
@indent_levels = [0]
|
33
|
-
@on_enter = on_enter || lambda { |
|
34
|
-
@on_leave = on_leave || lambda { |
|
33
|
+
@on_enter = on_enter || lambda { |_level, _text| }
|
34
|
+
@on_leave = on_leave || lambda { |_level, _text| }
|
35
35
|
@comment_level = nil
|
36
36
|
end
|
37
37
|
|
@@ -85,7 +85,7 @@ module HamlParser
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
def indent_enter(indent_level, text,
|
88
|
+
def indent_enter(indent_level, text, _lineno)
|
89
89
|
unless @comment_level
|
90
90
|
@indent_levels.push(indent_level)
|
91
91
|
@on_enter.call(indent_level, text)
|
@@ -49,12 +49,12 @@ module HamlParser
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def next_multiline(line)
|
52
|
-
buf = [line[0, line.size-1]]
|
52
|
+
buf = [line[0, line.size - 1]]
|
53
53
|
while @lineno < @lines.size
|
54
54
|
line = move_next
|
55
55
|
|
56
56
|
if is_multiline?(line)
|
57
|
-
line = line[0, line.size-1]
|
57
|
+
line = line[0, line.size - 1]
|
58
58
|
buf << line.lstrip
|
59
59
|
else
|
60
60
|
move_back
|
data/lib/haml_parser/parser.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
require_relative 'ast'
|
2
|
+
require_relative 'element_parser'
|
3
|
+
require_relative 'error'
|
4
|
+
require_relative 'filter_parser'
|
5
|
+
require_relative 'indent_tracker'
|
6
|
+
require_relative 'line_parser'
|
7
|
+
require_relative 'ruby_multiline'
|
8
|
+
require_relative 'script_parser'
|
9
|
+
require_relative 'utils'
|
10
10
|
|
11
11
|
module HamlParser
|
12
12
|
class Parser
|
@@ -79,7 +79,7 @@ module HamlParser
|
|
79
79
|
|
80
80
|
case text[0]
|
81
81
|
when ESCAPE_PREFIX
|
82
|
-
parse_plain(text[1
|
82
|
+
parse_plain(text[1..-1])
|
83
83
|
when ELEMENT_PREFIX
|
84
84
|
parse_element(text)
|
85
85
|
when DOCTYPE_PREFIX
|
@@ -106,11 +106,11 @@ module HamlParser
|
|
106
106
|
end
|
107
107
|
|
108
108
|
def parse_doctype(text)
|
109
|
-
@ast << create_node(Ast::Doctype) { |d| d.doctype = text[3
|
109
|
+
@ast << create_node(Ast::Doctype) { |d| d.doctype = text[3..-1].strip }
|
110
110
|
end
|
111
111
|
|
112
112
|
def parse_comment(text)
|
113
|
-
text = text[1, text.size-1].strip
|
113
|
+
text = text[1, text.size - 1].strip
|
114
114
|
comment = create_node(Ast::HtmlComment)
|
115
115
|
comment.comment = text
|
116
116
|
if text[0] == '['
|
@@ -123,7 +123,7 @@ module HamlParser
|
|
123
123
|
CONDITIONAL_COMMENT_REGEX = /[\[\]]/o
|
124
124
|
|
125
125
|
def parse_conditional_comment(text)
|
126
|
-
s = StringScanner.new(text[1
|
126
|
+
s = StringScanner.new(text[1..-1])
|
127
127
|
depth = Utils.balance(s, '[', ']')
|
128
128
|
if depth == 0
|
129
129
|
[s.pre_match, s.rest.lstrip]
|
@@ -163,7 +163,7 @@ module HamlParser
|
|
163
163
|
@filter_parser.start(filter_name, @line_parser.filename, @line_parser.lineno)
|
164
164
|
end
|
165
165
|
|
166
|
-
def indent_enter(_,
|
166
|
+
def indent_enter(_, _text)
|
167
167
|
empty_lines = []
|
168
168
|
while @ast.children.last.is_a?(Ast::Empty)
|
169
169
|
empty_lines << @ast.children.pop
|
@@ -213,8 +213,6 @@ module HamlParser
|
|
213
213
|
m = text.match(BLOCK_KEYWORD_REGEX)
|
214
214
|
if m
|
215
215
|
m[1] || m[2]
|
216
|
-
else
|
217
|
-
nil
|
218
216
|
end
|
219
217
|
end
|
220
218
|
|
@@ -15,8 +15,8 @@ module HamlParser
|
|
15
15
|
# (however, "x?," is a method call and not a literal)
|
16
16
|
# - and not "?\," which is a character literal
|
17
17
|
def self.is_ruby_multiline?(text)
|
18
|
-
text && text.length > 1 && text[-1] ==
|
19
|
-
!((text[-3, 2] =~ /\W\?/) || text[-3, 2] ==
|
18
|
+
text && text.length > 1 && text[-1] == ',' &&
|
19
|
+
!((text[-3, 2] =~ /\W\?/) || text[-3, 2] == '?\\')
|
20
20
|
end
|
21
21
|
private_class_method :is_ruby_multiline?
|
22
22
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative 'ast'
|
2
|
+
require_relative 'error'
|
3
|
+
require_relative 'ruby_multiline'
|
4
4
|
|
5
5
|
module HamlParser
|
6
6
|
class ScriptParser
|
@@ -25,10 +25,10 @@ module HamlParser
|
|
25
25
|
|
26
26
|
def parse_script(text)
|
27
27
|
if text[1] == '='
|
28
|
-
create_node(Ast::Text) { |t| t.text = text[2
|
28
|
+
create_node(Ast::Text) { |t| t.text = text[2..-1].strip }
|
29
29
|
else
|
30
30
|
node = create_node(Ast::Script)
|
31
|
-
script = text[1
|
31
|
+
script = text[1..-1].lstrip
|
32
32
|
if script.empty?
|
33
33
|
syntax_error!('No Ruby code to evaluate')
|
34
34
|
end
|
@@ -41,10 +41,10 @@ module HamlParser
|
|
41
41
|
def parse_sanitized(text)
|
42
42
|
case
|
43
43
|
when text.start_with?('&==')
|
44
|
-
create_node(Ast::Text) { |t| t.text = text[3
|
44
|
+
create_node(Ast::Text) { |t| t.text = text[3..-1].lstrip }
|
45
45
|
when text[1] == '=' || text[1] == '~'
|
46
46
|
node = create_node(Ast::Script)
|
47
|
-
script = text[2
|
47
|
+
script = text[2..-1].lstrip
|
48
48
|
if script.empty?
|
49
49
|
syntax_error!('No Ruby code to evaluate')
|
50
50
|
end
|
@@ -52,7 +52,7 @@ module HamlParser
|
|
52
52
|
node.preserve = text[1] == '~'
|
53
53
|
node
|
54
54
|
else
|
55
|
-
create_node(Ast::Text) { |t| t.text = text[1
|
55
|
+
create_node(Ast::Text) { |t| t.text = text[1..-1].strip }
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -60,13 +60,13 @@ module HamlParser
|
|
60
60
|
case
|
61
61
|
when text.start_with?('!==')
|
62
62
|
create_node(Ast::Text) do |t|
|
63
|
-
t.text = text[3
|
63
|
+
t.text = text[3..-1].lstrip
|
64
64
|
t.escape_html = false
|
65
65
|
end
|
66
66
|
when text[1] == '=' || text[1] == '~'
|
67
67
|
node = create_node(Ast::Script)
|
68
68
|
node.escape_html = false
|
69
|
-
script = text[2
|
69
|
+
script = text[2..-1].lstrip
|
70
70
|
if script.empty?
|
71
71
|
syntax_error!('No Ruby code to evaluate')
|
72
72
|
end
|
@@ -75,7 +75,7 @@ module HamlParser
|
|
75
75
|
node
|
76
76
|
else
|
77
77
|
create_node(Ast::Text) do |t|
|
78
|
-
t.text = text[1
|
78
|
+
t.text = text[1..-1].lstrip
|
79
79
|
t.escape_html = false
|
80
80
|
end
|
81
81
|
end
|
data/lib/haml_parser/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Suzuki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: benchmark-ips
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,20 @@ dependencies:
|
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: haml
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: pry
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +108,20 @@ dependencies:
|
|
80
108
|
- - ">="
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: 3.3.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
126
|
name: simplecov
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,7 +146,10 @@ extra_rdoc_files: []
|
|
104
146
|
files:
|
105
147
|
- ".gitignore"
|
106
148
|
- ".rspec"
|
149
|
+
- ".rubocop.yml"
|
150
|
+
- ".rubocop_todo.yml"
|
107
151
|
- ".travis.yml"
|
152
|
+
- CHANGELOG.md
|
108
153
|
- Gemfile
|
109
154
|
- LICENSE.txt
|
110
155
|
- README.md
|
@@ -146,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
191
|
version: '0'
|
147
192
|
requirements: []
|
148
193
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.
|
194
|
+
rubygems_version: 2.5.0
|
150
195
|
signing_key:
|
151
196
|
specification_version: 4
|
152
197
|
summary: Parser of Haml template language
|