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 +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +2 -0
- data/lib/rux/debug_lexer.rb +23 -0
- data/lib/rux/parser.rb +11 -4
- data/lib/rux/version.rb +1 -1
- data/spec/render_spec.rb +18 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2418beae606c99c851a3000546d6fffe20fb30e02049b41a2c2cbd8ecae427dc
|
|
4
|
+
data.tar.gz: 974fc8d3502737b5737f30b07c818e04918eb55b9693ea8b3d5ef629a71a1dc6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b6ba53663a7d8fb7195962d37586beee45a9ea97f1fcbc73b0366f68c640e54ae8f11a0daafee299500c84c06526d9683ad0bb09a065f929b43096eaaae77c9d
|
|
7
|
+
data.tar.gz: d25ada54406d57355e85d6824ab2ac2141771e613aa9a7dabfc24f7e2732124a4e369bca0fd61025248b0661c8e80183f0016c04480253870cc3fe2f94afcb9c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
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
|
-
|
|
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
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.
|
|
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
|