hamli 0.4.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f1faa1d3b9fa40c999ab475131a1cdf13a0cf97ad348b57a4d3fcbd2028e915
4
- data.tar.gz: 33b020dd8ee73741bc3e262e48c0cab0e7d7be24eb1df90deecd322c6ae4237f
3
+ metadata.gz: ff0371e95f3c87b4519036500b8ff6b5a7de3a91f9509f05240a9a23d53105ff
4
+ data.tar.gz: f96c2b0b84ad2d546433934ebe40e6973effe559896e0bacda88a0d769e462fc
5
5
  SHA512:
6
- metadata.gz: 6ad5489d23376861eecd2b6de81ef2c9e9fd97cd57a81cc0679a59ae7e7500a4c4ddeba8831281f02c2e110657aaccf7751c89f5497f2dfc8c153daf86e17082
7
- data.tar.gz: eceab6eadc445020e237eaa39f8b34a4b9007cc261327dc011ec97e00420532d51fd237c1614bc830874aad87cad520a3642dda41cb518dc1f1cc7f8303d9d9a
6
+ metadata.gz: 60c15036fe01fc5c4716cf49f8969dca86055628c42ba7c299a66de3102f08b7520d1c296f58b032840bfd925b5fcefaae068add96cc9f7d9370a68667d27c1e
7
+ data.tar.gz: a6c1a3d3b777ef1fd46f4928d2c045f57051169d84d2643050e1b917cb49cc0db0b9a20f9dee049a9fed8a1ad172ed74bae20fa4b94ab6616405d66d814970b2
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.5.0 - 2022-01-30
6
+
7
+ ### Added
8
+
9
+ - Support escaped output line.
10
+ - Support non-escaped output line.
11
+
5
12
  ## 0.4.0 - 2022-01-26
6
13
 
7
14
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hamli (0.4.0)
4
+ hamli (0.5.0)
5
5
  temple
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -5,6 +5,8 @@
5
5
 
6
6
  Yet another implementation for [Haml](https://github.com/haml/haml) template language.
7
7
 
8
+ Hamli is used by [Hamlcop](https://github.com/r7kamura/hamlcop).
9
+
8
10
  ## Installation
9
11
 
10
12
  Add this line to your application's Gemfile:
data/lib/hamli/parser.rb CHANGED
@@ -44,6 +44,10 @@ module Hamli
44
44
  parse_control_line
45
45
  elsif @scanner.match?(/=/)
46
46
  parse_output_line
47
+ elsif @scanner.match?(/&=/)
48
+ parse_escaped_output_line
49
+ elsif @scanner.match?(/!=/)
50
+ parse_non_escaped_output_line
47
51
  else
48
52
  parse_text_line
49
53
  end
@@ -138,7 +142,7 @@ module Hamli
138
142
  content = parse_broken_lines
139
143
  end_ = @scanner.charpos
140
144
  block = [:multi]
141
- tag << [:hamli, :position, begin_, end_, [:hamli, :output, content, block]]
145
+ tag << [:hamli, :position, begin_, end_, [:hamli, :output, false, content, block]]
142
146
  @stacks << block
143
147
  elsif @scanner.scan(%r{[ \t]*/[ \t]*})
144
148
  # Does nothing.
@@ -406,24 +410,51 @@ module Hamli
406
410
  [:hamli, :interpolate, begin_, end_, value]
407
411
  end
408
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
+
409
431
  # Parse output line part.
410
432
  # e.g. = abc
411
433
  # ^^^^^
412
434
  def parse_output_line
413
- parse_control_line(name: :output)
435
+ @scanner.pos += 1
436
+ @scanner.scan(/[ \t]*/)
437
+ parse_ruby_line(escaped: false, name: :output)
414
438
  end
415
439
 
416
440
  # Parse control line part.
417
441
  # e.g. - abc
418
442
  # ^^^^^
419
- def parse_control_line(name: :control)
443
+ def parse_control_line
420
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:)
421
452
  @scanner.scan(/[ \t]*/)
422
453
  block = [:multi]
423
454
  begin_ = @scanner.charpos
424
455
  content = parse_broken_lines
425
456
  end_ = @scanner.charpos
426
- @stacks.last << [:hamli, :position, begin_, end_, [:hamli, name, content, block]]
457
+ @stacks.last << [:hamli, :position, begin_, end_, [:hamli, name, escaped, content, block]]
427
458
  @stacks << block
428
459
  end
429
460
 
@@ -439,9 +470,7 @@ module Hamli
439
470
  result << @scanner.scan(/[^\r\n]*/)
440
471
  end
441
472
  lines = result.lines
442
- if lines.length >= 2 && lines.all? { |line| line.end_with?("|\n") }
443
- result.gsub!(/\|$/, '')
444
- end
473
+ result.gsub!(/\|$/, '') if lines.length >= 2 && lines.all? { |line| line.end_with?("|\n") }
445
474
  result.delete_suffix("\n")
446
475
  end
447
476
 
data/lib/hamli/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hamli
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
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.0
4
+ version: 0.5.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-26 00:00:00.000000000 Z
11
+ date: 2022-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: temple