hamli 0.2.0 → 0.3.0
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/CHANGELOG.md +11 -0
- data/Gemfile.lock +1 -1
- data/lib/hamli/parser.rb +107 -3
- data/lib/hamli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfe5c703b08f1580b7b3bf603b45984d68c1ccaff5675b0243a838a190597366
|
4
|
+
data.tar.gz: b5af88cc968267fdbc9ae35806a0d6fef3fb749b1939ce42a19d635b00f0c767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a29fe320a9c23065a6d897eab4acaf1e97b2303c11e0ec28854eb37bd50507a95247edee7a315dfa8b1e91af0be39ec79a1e4ec996220905084e9efa051fc285
|
7
|
+
data.tar.gz: cfcee2c4310365319915007a790d2962a88913180f21baae95857db5493c911fb09da9d152ac0993e01de4f684e141c73646466d1b31181fde85a8dbcde5196e
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,17 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 0.3.0 - 2022-01-26
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- Support output block in tag line.
|
10
|
+
- Support HTML comment line.
|
11
|
+
- Support HTML conditional comment line.
|
12
|
+
- Support Haml comment line.
|
13
|
+
- Support output line.
|
14
|
+
- Support control line.
|
15
|
+
|
5
16
|
## 0.2.0 - 2022-01-25
|
6
17
|
|
7
18
|
### Added
|
data/Gemfile.lock
CHANGED
data/lib/hamli/parser.rb
CHANGED
@@ -25,6 +25,16 @@ module Hamli
|
|
25
25
|
parse_tag_line
|
26
26
|
elsif @scanner.match?(/[#.]/)
|
27
27
|
parse_div_line
|
28
|
+
elsif @scanner.match?(%r{/\[})
|
29
|
+
parse_html_conditional_comment_line
|
30
|
+
elsif @scanner.match?(%r{/})
|
31
|
+
parse_html_comment_line
|
32
|
+
elsif @scanner.match?(/-#/)
|
33
|
+
parse_haml_comment_line
|
34
|
+
elsif @scanner.match?(/-/)
|
35
|
+
parse_control_line
|
36
|
+
elsif @scanner.match?(/=/)
|
37
|
+
parse_output_line
|
28
38
|
else
|
29
39
|
parse_text_line
|
30
40
|
end
|
@@ -110,10 +120,19 @@ module Hamli
|
|
110
120
|
content = [:multi]
|
111
121
|
tag << content
|
112
122
|
@stacks << content
|
113
|
-
elsif @scanner.scan(/[ \t]
|
114
|
-
#
|
123
|
+
elsif @scanner.scan(/[ \t]*([<>]*)=/)
|
124
|
+
# white_space_marker = @scanner[1]
|
125
|
+
# without_outer_white_space = white_space_marker.include?('>') # TODO
|
126
|
+
# without_inner_white_space = white_space_marker.include?('<') # TODO
|
127
|
+
@scanner.skip(/[ \t]+/)
|
128
|
+
begin_ = @scanner.charpos
|
129
|
+
content = parse_broken_lines
|
130
|
+
end_ = @scanner.charpos
|
131
|
+
block = [:multi]
|
132
|
+
tag << [:hamli, :position, begin_, end_, [:hamli, :output, content, block]]
|
133
|
+
@stacks << block
|
115
134
|
elsif @scanner.scan(%r{[ \t]*/[ \t]*})
|
116
|
-
#
|
135
|
+
# Does nothing.
|
117
136
|
else
|
118
137
|
@scanner.scan(/[ \t]+/)
|
119
138
|
tag << [:hamli, :text, parse_text_block]
|
@@ -295,6 +314,49 @@ module Hamli
|
|
295
314
|
[:hamli, :ruby_attributes, [:hamli, :position, begin_, @scanner.charpos, value]]
|
296
315
|
end
|
297
316
|
|
317
|
+
# Parse HTML comment part.
|
318
|
+
# e.g. /[if IE]
|
319
|
+
# ^^^^^^^^
|
320
|
+
def parse_html_conditional_comment_line
|
321
|
+
@scanner.pos += 1
|
322
|
+
condition = @scanner.scan(
|
323
|
+
/
|
324
|
+
(?<brackets>
|
325
|
+
\[
|
326
|
+
(?:[^\[\]] | \g<brackets>)*
|
327
|
+
\]
|
328
|
+
)
|
329
|
+
/x
|
330
|
+
)
|
331
|
+
block = [:multi]
|
332
|
+
@stacks.last << [:html, :condcomment, condition, block]
|
333
|
+
@stacks << block
|
334
|
+
parse_line_ending
|
335
|
+
end
|
336
|
+
|
337
|
+
# Parse HTML comment part.
|
338
|
+
# e.g. / abc
|
339
|
+
# ^^^^^
|
340
|
+
def parse_html_comment_line
|
341
|
+
@scanner.pos += 1
|
342
|
+
block = [:multi]
|
343
|
+
block << [:static, @scanner.scan(/[^\r\n]*/)]
|
344
|
+
@stacks.last << [:html, :comment, block]
|
345
|
+
@stacks << block
|
346
|
+
parse_line_ending
|
347
|
+
end
|
348
|
+
|
349
|
+
# Parse Haml comment part.
|
350
|
+
# e.g. -# abc
|
351
|
+
# ^^^^^^
|
352
|
+
def parse_haml_comment_line
|
353
|
+
@scanner.pos += 2
|
354
|
+
while !@scanner.eos? && (@scanner.match?(/[ \t]*(?=\r|$)/) || peek_indent > @indents.last)
|
355
|
+
@scanner.skip(/[^\r\n]*/)
|
356
|
+
parse_line_ending
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
298
360
|
# Parse text block part.
|
299
361
|
# e.g. %div abc
|
300
362
|
# ^^^^
|
@@ -334,6 +396,42 @@ module Hamli
|
|
334
396
|
[:hamli, :interpolate, begin_, end_, value]
|
335
397
|
end
|
336
398
|
|
399
|
+
# Parse output line part.
|
400
|
+
# e.g. = abc
|
401
|
+
# ^^^^^
|
402
|
+
def parse_output_line
|
403
|
+
parse_control_line(name: :output)
|
404
|
+
end
|
405
|
+
|
406
|
+
# Parse control line part.
|
407
|
+
# e.g. - abc
|
408
|
+
# ^^^^^
|
409
|
+
def parse_control_line(name: :control)
|
410
|
+
@scanner.pos += 1
|
411
|
+
@scanner.scan(/[ \t]*/)
|
412
|
+
block = [:multi]
|
413
|
+
begin_ = @scanner.charpos
|
414
|
+
content = parse_broken_lines
|
415
|
+
end_ = @scanner.charpos
|
416
|
+
@stacks.last << [:hamli, :position, begin_, end_, [:hamli, name, content, block]]
|
417
|
+
@stacks << block
|
418
|
+
end
|
419
|
+
|
420
|
+
# @note Broken line means line-breaked lines, separated by trailing "," or "|".
|
421
|
+
# @return [String]
|
422
|
+
def parse_broken_lines
|
423
|
+
result = +''
|
424
|
+
result << @scanner.scan(/[^\r\n]*/)
|
425
|
+
while result.end_with?(',') || result.end_with?('|')
|
426
|
+
syntax_error!(Errors::UnexpectedEosError) unless @scanner.scan(/\r?\n/)
|
427
|
+
|
428
|
+
result.delete_suffix('|')
|
429
|
+
result << "\n"
|
430
|
+
result << @scanner.scan(/[^\r\n]*/)
|
431
|
+
end
|
432
|
+
result
|
433
|
+
end
|
434
|
+
|
337
435
|
# @param [Class] syntax_error_class A child class of Hamli::Errors::HamlSyntaxError.
|
338
436
|
# @raise [Hamli::Errors::HamlSyntaxError]
|
339
437
|
def syntax_error!(syntax_error_class)
|
@@ -364,5 +462,11 @@ module Hamli
|
|
364
462
|
def expecting_indentation?
|
365
463
|
@stacks.length > @indents.length
|
366
464
|
end
|
465
|
+
|
466
|
+
# @return [Integer] Indent level.
|
467
|
+
def peek_indent
|
468
|
+
@scanner.match?(/[ \t]*/)
|
469
|
+
indent_from_last_match
|
470
|
+
end
|
367
471
|
end
|
368
472
|
end
|
data/lib/hamli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: temple
|