haml_parser 0.4.0 → 0.4.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 +11 -1
- data/.travis.yml +3 -3
- data/CHANGELOG.md +3 -0
- data/Gemfile +1 -0
- data/Rakefile +1 -0
- data/bin/console +1 -0
- data/exe/haml_parser +1 -0
- data/haml_parser.gemspec +1 -0
- data/lib/haml_parser.rb +1 -0
- data/lib/haml_parser/ast.rb +1 -0
- data/lib/haml_parser/cli.rb +1 -0
- data/lib/haml_parser/element_parser.rb +7 -10
- data/lib/haml_parser/error.rb +1 -0
- data/lib/haml_parser/filter_parser.rb +7 -8
- data/lib/haml_parser/indent_tracker.rb +2 -1
- data/lib/haml_parser/line_parser.rb +1 -0
- data/lib/haml_parser/parser.rb +6 -3
- data/lib/haml_parser/ruby_multiline.rb +1 -0
- data/lib/haml_parser/script_parser.rb +5 -6
- data/lib/haml_parser/utils.rb +1 -0
- data/lib/haml_parser/version.rb +2 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7419fb3e0cafc26ec4b25af1bbc614a22befe953
|
4
|
+
data.tar.gz: 8446c4f6c9535169f187f482ed012af5c324ce4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b59ff50da183f5ca981d745d38d2224c438374fc9e99acfd8d7e231541056292c54648e5d4682781c6bfa5bdbf0464227a4969c96ca130f6f872a809dbf52de
|
7
|
+
data.tar.gz: ec69c79bbdca9b31d33350e662562e1fa7ad8362fe3a0e077500aa600cbe7782fd8f4be11df655b562b14906e4cdbf7d73ac6de325b0e9adc3ee9c58cc01a559
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
inherit_from: .rubocop_todo.yml
|
2
2
|
|
3
|
+
AllCops:
|
4
|
+
DisplayCopNames: true
|
5
|
+
TargetRubyVersion: 2.3
|
6
|
+
|
3
7
|
Style/BarePercentLiterals:
|
4
8
|
EnforcedStyle: percent_q
|
5
9
|
|
@@ -35,7 +39,10 @@ Style/Tab:
|
|
35
39
|
Exclude:
|
36
40
|
- 'spec/indent_spec.rb'
|
37
41
|
|
38
|
-
Style/
|
42
|
+
Style/TrailingCommaInLiteral:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Style/TrailingCommaInArguments:
|
39
46
|
Enabled: false
|
40
47
|
|
41
48
|
Style/TrailingWhitespace:
|
@@ -44,3 +51,6 @@ Style/TrailingWhitespace:
|
|
44
51
|
|
45
52
|
Style/UnneededPercentQ:
|
46
53
|
Enabled: false # buggy
|
54
|
+
|
55
|
+
Performance/RedundantBlockCall:
|
56
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/exe/haml_parser
CHANGED
data/haml_parser.gemspec
CHANGED
data/lib/haml_parser.rb
CHANGED
data/lib/haml_parser/ast.rb
CHANGED
data/lib/haml_parser/cli.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'strscan'
|
2
3
|
require_relative 'ast'
|
3
4
|
require_relative 'error'
|
@@ -99,12 +100,10 @@ module HamlParser
|
|
99
100
|
if depth == 0
|
100
101
|
attr = s.pre_match + s.matched
|
101
102
|
return [attr[1, attr.size - 2], s.rest]
|
103
|
+
elsif /,\s*\z/ === text && @line_parser.has_next?
|
104
|
+
text << "\n" << @line_parser.next_line
|
102
105
|
else
|
103
|
-
|
104
|
-
text << "\n" << @line_parser.next_line
|
105
|
-
else
|
106
|
-
syntax_error!('Unmatched brace')
|
107
|
-
end
|
106
|
+
syntax_error!('Unmatched brace')
|
108
107
|
end
|
109
108
|
end
|
110
109
|
end
|
@@ -120,12 +119,10 @@ module HamlParser
|
|
120
119
|
if depth == 0
|
121
120
|
t = s.string.byteslice(pre_pos...s.pos - 1)
|
122
121
|
return [parse_new_attribute_list(t), s.rest]
|
122
|
+
elsif @line_parser.has_next?
|
123
|
+
text << "\n" << @line_parser.next_line
|
123
124
|
else
|
124
|
-
|
125
|
-
text << "\n" << @line_parser.next_line
|
126
|
-
else
|
127
|
-
syntax_error!('Unmatched paren')
|
128
|
-
end
|
125
|
+
syntax_error!('Unmatched paren')
|
129
126
|
end
|
130
127
|
end
|
131
128
|
end
|
data/lib/haml_parser/error.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative 'ast'
|
2
3
|
|
3
4
|
module HamlParser
|
@@ -35,15 +36,13 @@ module HamlParser
|
|
35
36
|
@ast = nil
|
36
37
|
return ast
|
37
38
|
end
|
39
|
+
elsif indent_level > @indent_tracker.current_level
|
40
|
+
# Start filter
|
41
|
+
@indent_level = indent_level
|
38
42
|
else
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
else
|
43
|
-
# Empty filter
|
44
|
-
@ast = nil
|
45
|
-
return nil
|
46
|
-
end
|
43
|
+
# Empty filter
|
44
|
+
@ast = nil
|
45
|
+
return nil
|
47
46
|
end
|
48
47
|
|
49
48
|
text = line[@indent_level..-1]
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative 'error'
|
2
3
|
|
3
4
|
module HamlParser
|
@@ -36,7 +37,7 @@ module HamlParser
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def process(line, lineno)
|
39
|
-
if line
|
40
|
+
if line.start_with?("\t")
|
40
41
|
raise HardTabNotAllowed.new(lineno)
|
41
42
|
end
|
42
43
|
indent, text = split(line)
|
data/lib/haml_parser/parser.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative 'ast'
|
2
3
|
require_relative 'element_parser'
|
3
4
|
require_relative 'error'
|
@@ -180,6 +181,8 @@ module HamlParser
|
|
180
181
|
syntax_error!('nesting within plain text is illegal')
|
181
182
|
when Ast::Doctype
|
182
183
|
syntax_error!('nesting within a header command is illegal')
|
184
|
+
when nil
|
185
|
+
syntax_error!('Indenting at the beginning of the document is illegal')
|
183
186
|
end
|
184
187
|
@ast.children = empty_lines
|
185
188
|
if @ast.is_a?(Ast::Element) && @ast.self_closing
|
@@ -202,8 +205,8 @@ module HamlParser
|
|
202
205
|
nil
|
203
206
|
end
|
204
207
|
|
205
|
-
MID_BLOCK_KEYWORDS = %w[else elsif rescue ensure end when]
|
206
|
-
START_BLOCK_KEYWORDS = %w[if begin case unless]
|
208
|
+
MID_BLOCK_KEYWORDS = %w[else elsif rescue ensure end when].freeze
|
209
|
+
START_BLOCK_KEYWORDS = %w[if begin case unless].freeze
|
207
210
|
# Try to parse assignments to block starters as best as possible
|
208
211
|
START_BLOCK_KEYWORD_REGEX = /(?:\w+(?:,\s*\w+)*\s*=\s*)?(#{Regexp.union(START_BLOCK_KEYWORDS)})/
|
209
212
|
BLOCK_KEYWORD_REGEX = /^-?\s*(?:(#{Regexp.union(MID_BLOCK_KEYWORDS)})|#{START_BLOCK_KEYWORD_REGEX.source})\b/
|
@@ -224,7 +227,7 @@ module HamlParser
|
|
224
227
|
node.filename = @line_parser.filename
|
225
228
|
node.lineno = @line_parser.lineno
|
226
229
|
if block
|
227
|
-
|
230
|
+
yield(node)
|
228
231
|
end
|
229
232
|
end
|
230
233
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative 'ast'
|
2
3
|
require_relative 'error'
|
3
4
|
require_relative 'ruby_multiline'
|
@@ -39,10 +40,9 @@ module HamlParser
|
|
39
40
|
end
|
40
41
|
|
41
42
|
def parse_sanitized(text)
|
42
|
-
|
43
|
-
when text.start_with?('&==')
|
43
|
+
if text.start_with?('&==')
|
44
44
|
create_node(Ast::Text) { |t| t.text = text[3..-1].lstrip }
|
45
|
-
|
45
|
+
elsif text[1] == '=' || text[1] == '~'
|
46
46
|
node = create_node(Ast::Script)
|
47
47
|
script = text[2..-1].lstrip
|
48
48
|
if script.empty?
|
@@ -57,13 +57,12 @@ module HamlParser
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def parse_unescape(text)
|
60
|
-
|
61
|
-
when text.start_with?('!==')
|
60
|
+
if text.start_with?('!==')
|
62
61
|
create_node(Ast::Text) do |t|
|
63
62
|
t.text = text[3..-1].lstrip
|
64
63
|
t.escape_html = false
|
65
64
|
end
|
66
|
-
|
65
|
+
elsif text[1] == '=' || text[1] == '~'
|
67
66
|
node = create_node(Ast::Script)
|
68
67
|
node.escape_html = false
|
69
68
|
script = text[2..-1].lstrip
|
data/lib/haml_parser/utils.rb
CHANGED
data/lib/haml_parser/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.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:
|
11
|
+
date: 2016-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
requirements: []
|
193
193
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.
|
194
|
+
rubygems_version: 2.6.6
|
195
195
|
signing_key:
|
196
196
|
specification_version: 4
|
197
197
|
summary: Parser of Haml template language
|