hamli 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a825c4ad1a1e140b7c8020a0137a278c2844356c0f5ab166fcca716c0f21a88
4
- data.tar.gz: e603ee2dd8d1698447bf4eb20729b0087b174f679171d2a4d94efd4f2117e580
3
+ metadata.gz: b8051356e999f363969f3ccd7c937b17e70ea6e58c283e5836e5ccc0f3163e2a
4
+ data.tar.gz: 6d08f7c25aa75ebd8fc5e64e009533bf02154521329e2de01789eee469462e86
5
5
  SHA512:
6
- metadata.gz: 759e52536c4111473a6a46d22a44a027db0e96590d2367e9bbd64395bf91cd72c5984cc4341e457f493c99c27f878d5f2142a42f4a26c77175a245c1e242b269
7
- data.tar.gz: 914d1aa219cba92b697455223ba65bd140336bb7e20fdc5378eaadf6825630d9d392f56e797b84b160a0d96ad84296042e74468b2a6c1b093c4898f05165ce7e
6
+ metadata.gz: e4c6d223febbf5aec1aaccaa30ef9599aebf32903a8de3afe9fe62ffd8b1b928bfb5eef519551952c6a41d43c0be8b325af4436ad95d69a429949950772cf454
7
+ data.tar.gz: a78ba804bc6b81fce03df6a85ea885ec809dba8f4c09ea5aed0d80007941149798dda64037ca3f68dbb3ea6d339fe362706ddfb530ada457b53a98a0a14dd6b5
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.2.0 - 2022-01-25
6
+
7
+ ### Added
8
+
9
+ - Add Interpolation Filter.
10
+
11
+ ### Changed
12
+
13
+ - Use :position node.
14
+
5
15
  ## 0.1.0 - 2022-01-25
6
16
 
7
17
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hamli (0.1.0)
4
+ hamli (0.2.0)
5
5
  temple
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Hamli
2
2
 
3
3
  [![test](https://github.com/r7kamura/hamli/actions/workflows/test.yml/badge.svg)](https://github.com/r7kamura/hamli/actions/workflows/test.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/hamli.svg)](https://rubygems.org/gems/hamli)
4
5
 
5
6
  Yet another implementation for [Haml](https://github.com/haml/haml) template language.
6
7
 
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'temple'
4
+
5
+ module Hamli
6
+ module Filters
7
+ # Pass-through some expressions which are unknown for Temple.
8
+ class Base < ::Temple::HTML::Filter
9
+ # @param [Integer] begin_
10
+ # @param [Integer] end_
11
+ # @param [Array] expression
12
+ # @return [Array]
13
+ def on_hamli_position(begin_, end_, expression)
14
+ [:hamli, :position, begin_, end_, compile(expression)]
15
+ end
16
+
17
+ # @param [String] type
18
+ # @param [Array] expression
19
+ # @return [Array]
20
+ def on_hamli_text(type, expression)
21
+ [:hamli, :text, type, compile(expression)]
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'strscan'
4
+
5
+ module Hamli
6
+ module Filters
7
+ class Interpolation < Base
8
+ # @param [Integer] begin_
9
+ # @param [Integer] end_
10
+ # @return [Array] S-expression.
11
+ def on_hamli_interpolate(begin_, _end_, string)
12
+ block = [:multi]
13
+ scanner = ::StringScanner.new(string)
14
+ until scanner.eos?
15
+ charpos = scanner.charpos
16
+ if (value = scanner.scan(/\\#\{/))
17
+ block << [:static, value]
18
+ elsif scanner.scan(/#\{((?>[^{}]|(\{(?>[^{}]|\g<1>)*\}))*)\}/)
19
+ code = scanner[1]
20
+ begin2 = begin_ + charpos + 2
21
+ if code.start_with?('{') && code.end_with?('}')
22
+ escape = true
23
+ code = code[1..-2]
24
+ begin2 -= 1
25
+ else
26
+ escape = false
27
+ end
28
+ block << [:hamli, :position, begin2, begin2 + code.length, [:hamli, :output, escape, code, [:multi]]]
29
+ elsif (value = scanner.scan(/([#\\]?[^#\\]*([#\\][^\\\#{][^#\\]*)*)/)) # rubocop:disable Lint/DuplicateBranch
30
+ block << [:static, value]
31
+ end
32
+ end
33
+ block
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hamli
4
+ module Filters
5
+ autoload :Base, 'hamli/filters/base'
6
+ autoload :Interpolation, 'hamli/filters/interpolation'
7
+ end
8
+ end
data/lib/hamli/parser.rb CHANGED
@@ -274,7 +274,7 @@ module Hamli
274
274
  )
275
275
  /x
276
276
  )
277
- [:hamli, :object_reference, begin_, @scanner.charpos, value]
277
+ [:hamli, :object_reference, [:hamli, :position, begin_, @scanner.charpos, value]]
278
278
  end
279
279
 
280
280
  # Parse ruby attributes part.
@@ -292,7 +292,7 @@ module Hamli
292
292
  )
293
293
  /x
294
294
  )
295
- [:hamli, :ruby_attributes, begin_, @scanner.charpos, value]
295
+ [:hamli, :ruby_attributes, [:hamli, :position, begin_, @scanner.charpos, value]]
296
296
  end
297
297
 
298
298
  # Parse text block part.
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.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/hamli.rb CHANGED
@@ -4,6 +4,7 @@ require_relative 'hamli/version'
4
4
 
5
5
  module Hamli
6
6
  autoload :Errors, 'hamli/errors'
7
+ autoload :Filters, 'hamli/filters'
7
8
  autoload :Parser, 'hamli/parser'
8
9
  autoload :Range, 'hamli/range'
9
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
@@ -43,6 +43,9 @@ files:
43
43
  - hamli.gemspec
44
44
  - lib/hamli.rb
45
45
  - lib/hamli/errors.rb
46
+ - lib/hamli/filters.rb
47
+ - lib/hamli/filters/base.rb
48
+ - lib/hamli/filters/interpolation.rb
46
49
  - lib/hamli/parser.rb
47
50
  - lib/hamli/range.rb
48
51
  - lib/hamli/version.rb