hamli 0.3.0 → 0.5.1
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 +27 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -0
- data/lib/hamli/filters/base.rb +2 -3
- data/lib/hamli/parser.rb +52 -10
- data/lib/hamli/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9eacc83b48fa8d222c61141db82359b6ca0ab26d0920af27ec2aa23f62737a77
|
4
|
+
data.tar.gz: ce7a4299a5b7159d8bf710c56d209c8befca34e69e8f9283026708fd29fdc1e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed57274d0f03e3cead46b164436245c3d20d1d8c162f96db507f6b6277b18d6f984f97ae03277a83696e5b9779021da712e90ae27646a1767b629d9e38b7bcc1
|
7
|
+
data.tar.gz: 699de4de959019ac943f2b15f151f196253b045f2781519ba645175b66a0b4b8b8dbbdfe7c8098bd652dbaf890282c15697954fd345a7346082516496a3458e7
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,33 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 0.5.1 - 2022-06-29
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
|
9
|
+
- Fix Ruby blocks parsing.
|
10
|
+
|
11
|
+
## 0.5.0 - 2022-01-30
|
12
|
+
|
13
|
+
### Added
|
14
|
+
|
15
|
+
- Support escaped output line.
|
16
|
+
- Support non-escaped output line.
|
17
|
+
|
18
|
+
## 0.4.0 - 2022-01-26
|
19
|
+
|
20
|
+
### Added
|
21
|
+
|
22
|
+
- Add :file option for better error report.
|
23
|
+
|
24
|
+
### Fixed
|
25
|
+
|
26
|
+
- Fix error from parse_text_block on some case.
|
27
|
+
- Fix filter bug on :text node.
|
28
|
+
- Fix parse_interpolate_line bug.
|
29
|
+
- Fix haml comment parser bug.
|
30
|
+
- Fix pipe multi-line handling.
|
31
|
+
|
5
32
|
## 0.3.0 - 2022-01-26
|
6
33
|
|
7
34
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/hamli/filters/base.rb
CHANGED
@@ -14,11 +14,10 @@ module Hamli
|
|
14
14
|
[:hamli, :position, begin_, end_, compile(expression)]
|
15
15
|
end
|
16
16
|
|
17
|
-
# @param [String] type
|
18
17
|
# @param [Array] expression
|
19
18
|
# @return [Array]
|
20
|
-
def on_hamli_text(
|
21
|
-
[:hamli, :text,
|
19
|
+
def on_hamli_text(expression)
|
20
|
+
[:hamli, :text, compile(expression)]
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
data/lib/hamli/parser.rb
CHANGED
@@ -4,6 +4,15 @@ require 'temple'
|
|
4
4
|
|
5
5
|
module Hamli
|
6
6
|
class Parser < ::Temple::Parser
|
7
|
+
define_options(
|
8
|
+
:file
|
9
|
+
)
|
10
|
+
|
11
|
+
def initialize(_options = {})
|
12
|
+
super
|
13
|
+
@file_path = options[:file] || '(__TEMPLATE__)'
|
14
|
+
end
|
15
|
+
|
7
16
|
# @param [String] source Haml template source.
|
8
17
|
# @return [Array]
|
9
18
|
def call(source)
|
@@ -35,6 +44,10 @@ module Hamli
|
|
35
44
|
parse_control_line
|
36
45
|
elsif @scanner.match?(/=/)
|
37
46
|
parse_output_line
|
47
|
+
elsif @scanner.match?(/&=/)
|
48
|
+
parse_escaped_output_line
|
49
|
+
elsif @scanner.match?(/!=/)
|
50
|
+
parse_non_escaped_output_line
|
38
51
|
else
|
39
52
|
parse_text_line
|
40
53
|
end
|
@@ -129,7 +142,7 @@ module Hamli
|
|
129
142
|
content = parse_broken_lines
|
130
143
|
end_ = @scanner.charpos
|
131
144
|
block = [:multi]
|
132
|
-
tag << [:hamli, :position, begin_, end_, [:hamli, :output, content, block]]
|
145
|
+
tag << [:hamli, :position, begin_, end_, [:hamli, :output, false, content, block]]
|
133
146
|
@stacks << block
|
134
147
|
elsif @scanner.scan(%r{[ \t]*/[ \t]*})
|
135
148
|
# Does nothing.
|
@@ -351,8 +364,9 @@ module Hamli
|
|
351
364
|
# ^^^^^^
|
352
365
|
def parse_haml_comment_line
|
353
366
|
@scanner.pos += 2
|
367
|
+
@scanner.scan(/[^\r\n]*/)
|
354
368
|
while !@scanner.eos? && (@scanner.match?(/[ \t]*(?=\r|$)/) || peek_indent > @indents.last)
|
355
|
-
@scanner.
|
369
|
+
@scanner.scan(/[^\r\n]*/)
|
356
370
|
parse_line_ending
|
357
371
|
end
|
358
372
|
end
|
@@ -387,7 +401,7 @@ module Hamli
|
|
387
401
|
|
388
402
|
# @return [Array, nil]
|
389
403
|
def parse_interpolate_line
|
390
|
-
return unless @scanner.match?(/[^\r\n]
|
404
|
+
return unless @scanner.match?(/[^\r\n]+/)
|
391
405
|
|
392
406
|
begin_ = @scanner.charpos
|
393
407
|
value = @scanner.matched
|
@@ -396,24 +410,51 @@ module Hamli
|
|
396
410
|
[:hamli, :interpolate, begin_, end_, value]
|
397
411
|
end
|
398
412
|
|
413
|
+
# Parse escaped output line part.
|
414
|
+
# e.g. != abc
|
415
|
+
# ^^^^^^
|
416
|
+
# @todo Support :escape_html option on this parser, then rethink about escaping.
|
417
|
+
def parse_non_escaped_output_line
|
418
|
+
@scanner.pos += 1
|
419
|
+
parse_output_line
|
420
|
+
end
|
421
|
+
|
422
|
+
# Parse escaped output line part.
|
423
|
+
# e.g. &= abc
|
424
|
+
# ^^^^^^
|
425
|
+
def parse_escaped_output_line
|
426
|
+
@scanner.pos += 2
|
427
|
+
@scanner.scan(/[ \t]*/)
|
428
|
+
parse_ruby_line(escaped: true, name: :output)
|
429
|
+
end
|
430
|
+
|
399
431
|
# Parse output line part.
|
400
432
|
# e.g. = abc
|
401
433
|
# ^^^^^
|
402
434
|
def parse_output_line
|
403
|
-
|
435
|
+
@scanner.pos += 1
|
436
|
+
@scanner.scan(/[ \t]*/)
|
437
|
+
parse_ruby_line(escaped: false, name: :output)
|
404
438
|
end
|
405
439
|
|
406
440
|
# Parse control line part.
|
407
441
|
# e.g. - abc
|
408
442
|
# ^^^^^
|
409
|
-
def parse_control_line
|
443
|
+
def parse_control_line
|
410
444
|
@scanner.pos += 1
|
445
|
+
@scanner.scan(/[ \t]*/)
|
446
|
+
parse_ruby_line(escaped: false, name: :control)
|
447
|
+
end
|
448
|
+
|
449
|
+
# @param [Boolean] escaped
|
450
|
+
# @param [Symbol] name
|
451
|
+
def parse_ruby_line(escaped:, name:)
|
411
452
|
@scanner.scan(/[ \t]*/)
|
412
453
|
block = [:multi]
|
413
454
|
begin_ = @scanner.charpos
|
414
455
|
content = parse_broken_lines
|
415
456
|
end_ = @scanner.charpos
|
416
|
-
@stacks.last << [:hamli, :position, begin_, end_, [:hamli, name, content, block]]
|
457
|
+
@stacks.last << [:hamli, :position, begin_, end_, [:hamli, name, escaped, content, block]]
|
417
458
|
@stacks << block
|
418
459
|
end
|
419
460
|
|
@@ -422,14 +463,15 @@ module Hamli
|
|
422
463
|
def parse_broken_lines
|
423
464
|
result = +''
|
424
465
|
result << @scanner.scan(/[^\r\n]*/)
|
425
|
-
while result.end_with?(',') || result.end_with?('|')
|
466
|
+
while result.end_with?(',') || (result.end_with?('|') && (result !~ /\bdo\s*\|[^|]*\|\z/))
|
426
467
|
syntax_error!(Errors::UnexpectedEosError) unless @scanner.scan(/\r?\n/)
|
427
468
|
|
428
|
-
result.delete_suffix('|')
|
429
469
|
result << "\n"
|
430
470
|
result << @scanner.scan(/[^\r\n]*/)
|
431
471
|
end
|
432
|
-
result
|
472
|
+
lines = result.lines
|
473
|
+
result.gsub!(/\|$/, '') if lines.length >= 2 && lines.all? { |line| line.end_with?("|\n") }
|
474
|
+
result.delete_suffix("\n")
|
433
475
|
end
|
434
476
|
|
435
477
|
# @param [Class] syntax_error_class A child class of Hamli::Errors::HamlSyntaxError.
|
@@ -446,7 +488,7 @@ module Hamli
|
|
446
488
|
|
447
489
|
# @return [Integer]
|
448
490
|
def indent_from_last_match
|
449
|
-
@scanner.matched.chars.map do |char|
|
491
|
+
(@scanner.matched || '').chars.map do |char|
|
450
492
|
case char
|
451
493
|
when "\t"
|
452
494
|
4
|
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.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: temple
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
29
|
- r7kamura@gmail.com
|
30
30
|
executables: []
|
@@ -57,7 +57,7 @@ metadata:
|
|
57
57
|
source_code_uri: https://github.com/r7kamura/hamli
|
58
58
|
changelog_uri: https://github.com/r7kamura/hamli/blob/main/CHANGELOG.md
|
59
59
|
rubygems_mfa_required: 'true'
|
60
|
-
post_install_message:
|
60
|
+
post_install_message:
|
61
61
|
rdoc_options: []
|
62
62
|
require_paths:
|
63
63
|
- lib
|
@@ -72,8 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
74
|
requirements: []
|
75
|
-
rubygems_version: 3.
|
76
|
-
signing_key:
|
75
|
+
rubygems_version: 3.3.7
|
76
|
+
signing_key:
|
77
77
|
specification_version: 4
|
78
78
|
summary: Yet another implementation for Haml template language.
|
79
79
|
test_files: []
|