rux 1.4.0 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1e472f55eed0269091c2f5efa3a1d27fb1d16ed1959c32a84633be8b192940d
4
- data.tar.gz: 46e848d6871ff5ea01638d6e50e24968ad3aa9867324580417151287ed932b3d
3
+ metadata.gz: 2418beae606c99c851a3000546d6fffe20fb30e02049b41a2c2cbd8ecae427dc
4
+ data.tar.gz: 974fc8d3502737b5737f30b07c818e04918eb55b9693ea8b3d5ef629a71a1dc6
5
5
  SHA512:
6
- metadata.gz: 1681c3f2cedc43ee87559663ada3f92d9061ed004cb4ea100a588d847b7de3cf2e4a490ec23f5d0cd653602d3f0fee1c97045c9c786e38249663a73534ab559c
7
- data.tar.gz: 94c7c21726d2b38750162fb36ceb1f8ff9321fe99425efb078b51a042568b5914e5821341bb45fa5b18f1f6df1040f2fa706edd7ce32b834207a0046e8ac0479
6
+ metadata.gz: b6ba53663a7d8fb7195962d37586beee45a9ea97f1fcbc73b0366f68c640e54ae8f11a0daafee299500c84c06526d9683ad0bb09a065f929b43096eaaae77c9d
7
+ data.tar.gz: d25ada54406d57355e85d6824ab2ac2141771e613aa9a7dabfc24f7e2732124a4e369bca0fd61025248b0661c8e80183f0016c04480253870cc3fe2f94afcb9c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 1.4.1
2
+ * Fix bug preventing use of curly brace-delimited block syntax, eg. `[1, 2].each { ... }`.
3
+
1
4
  # 1.4.0
2
5
  * Implement React-style contexts for passing arguments across arbitrary levels of component nesting.
3
6
  - Define a new context via `Rux.create_context`.
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ![Unit Tests](https://github.com/camertron/rux/actions/workflows/unit_tests.yml/badge.svg?branch=master)
4
4
 
5
+ /rʌks/, rhymes with "ducks" and "trucks"
6
+
5
7
  Rux is a JSX-inspired way to write HTML tags in your Ruby code. It can be used to render view components in Rails via the [rux-rails gem](https://github.com/camertron/rux-rails). This repo however contains only the rux parser itself.
6
8
 
7
9
  ## Introduction
@@ -0,0 +1,23 @@
1
+ module Rux
2
+ class DebugLexer
3
+ def initialize(...)
4
+ @lexer = Lexer.new(...)
5
+ @tokens = @lexer.to_a
6
+ @counter = -1
7
+ end
8
+
9
+ def source_buffer
10
+ @lexer.source_buffer
11
+ end
12
+
13
+ def advance
14
+ @counter += 1
15
+
16
+ if @counter >= @tokens.size
17
+ [nil, ['$eof']]
18
+ else
19
+ @tokens[@counter]
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/rux/parser.rb CHANGED
@@ -19,7 +19,12 @@ module Rux
19
19
  private
20
20
 
21
21
  def make_lexer(buffer)
22
- ::Rux::Lexer.new(buffer)
22
+ if ENV["RUX_DEBUG"]
23
+ require "rux/debug_lexer"
24
+ ::Rux::DebugLexer.new(buffer)
25
+ else
26
+ ::Rux::Lexer.new(buffer)
27
+ end
23
28
  end
24
29
  end
25
30
 
@@ -50,19 +55,21 @@ module Rux
50
55
  curlies -= 1
51
56
  end
52
57
 
53
- break if curlies == 0
54
-
55
58
  if rb = ruby
56
59
  children << rb
57
60
  elsif type_of(current) == :tRUX_TAG_OPEN_START
58
61
  children << tag
59
62
  elsif type_of(current) == :tRUX_FRAGMENT_OPEN
60
63
  children << fragment
64
+ elsif type_of(current) == :tRUX_LITERAL_RUBY_CODE_END
65
+ # do nothing - let #literal_ruby_code consume the end token
61
66
  else
62
67
  raise UnexpectedTokenError,
63
68
  'expected ruby code or the start of a rux tag but found '\
64
69
  "#{type_of(current)} instead"
65
70
  end
71
+
72
+ break if curlies == 0
66
73
  end
67
74
 
68
75
  AST::ListNode.new(children)
@@ -306,7 +313,7 @@ module Rux
306
313
  def consume(*types)
307
314
  if !types.include?(type_of(current))
308
315
  raise UnexpectedTokenError,
309
- "expected [#{types.map(&:to_s).join(', ')}], got '#{type_of(current)}'"
316
+ "expected [#{types.map(&:to_s).join(', ')}], got '#{type_of(current)}' at #{pos_of(current)}"
310
317
  end
311
318
 
312
319
  @current = get_next
data/lib/rux/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rux
2
- VERSION = '1.4.0'
2
+ VERSION = '1.4.1'
3
3
  end
data/spec/render_spec.rb CHANGED
@@ -25,6 +25,24 @@ describe 'rendering', type: :render do
25
25
  expect(result).to eq("<div><p>Welcome!</p><p>Welcome!</p><p>Welcome!</p></div>")
26
26
  end
27
27
 
28
+ it 'handles curly brace block syntax' do
29
+ result = render(<<~RUBY)
30
+ [1, 2, 3].map { |i| <div>{i}</div> }
31
+ RUBY
32
+
33
+ expect(result).to eq(["<div>1</div>", "<div>2</div>", "<div>3</div>"])
34
+ end
35
+
36
+ it 'handles curly brace block syntax with wrapping tag' do
37
+ result = render(<<~RUBY)
38
+ <span>
39
+ {[1, 2, 3].map { |i| <div>{i}</div> }}
40
+ </span>
41
+ RUBY
42
+
43
+ expect(result).to eq("<span><div>1</div><div>2</div><div>3</div></span>")
44
+ end
45
+
28
46
  it 'correctly handles keyword arguments (ruby 3)' do
29
47
  result = render(<<~RUBY)
30
48
  <ArgsComponent a="a" b="b" />
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rux
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
@@ -95,6 +95,7 @@ files:
95
95
  - lib/rux/ast/text_node.rb
96
96
  - lib/rux/buffer.rb
97
97
  - lib/rux/context.rb
98
+ - lib/rux/debug_lexer.rb
98
99
  - lib/rux/default_tag_builder.rb
99
100
  - lib/rux/default_visitor.rb
100
101
  - lib/rux/file.rb