rux 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile +1 -1
- data/README.md +91 -1
- data/bin/ruxc +21 -4
- data/lib/rux/ast/attr_node.rb +22 -0
- data/lib/rux/ast/attrs_node.rb +30 -0
- data/lib/rux/ast/fragment_node.rb +15 -0
- data/lib/rux/ast/root_node.rb +19 -0
- data/lib/rux/ast/ruby_attr_node.rb +28 -0
- data/lib/rux/ast/string_node.rb +4 -2
- data/lib/rux/ast/tag_node.rb +10 -1
- data/lib/rux/ast/text_node.rb +2 -1
- data/lib/rux/ast.rb +10 -5
- data/lib/rux/buffer.rb +21 -3
- data/lib/rux/default_tag_builder.rb +15 -6
- data/lib/rux/default_visitor.rb +93 -19
- data/lib/rux/lex/states.csv +22 -11
- data/lib/rux/parser.rb +102 -24
- data/lib/rux/ruby_lexer.rb +1 -0
- data/lib/rux/rux_lexer.rb +15 -3
- data/lib/rux/version.rb +1 -1
- data/lib/rux/visitor.rb +16 -0
- data/spec/parser/attributes_spec.rb +97 -0
- data/spec/parser/fragment_spec.rb +47 -0
- data/spec/parser/html_safety_spec.rb +13 -0
- data/spec/parser/slot_spec.rb +40 -0
- data/spec/parser/tag_spec.rb +174 -0
- data/spec/parser_spec.rb +17 -242
- data/spec/render_spec.rb +89 -6
- data/spec/spec_helper.rb +19 -22
- data/spec/support/components/args_component.rb +14 -0
- data/spec/support/components/data_component.rb +11 -0
- data/spec/support/components/table_component.rb +23 -0
- data/spec/support/components/test_component.rb +7 -0
- data/spec/support/view_component/base.rb +59 -0
- metadata +17 -2
@@ -0,0 +1,59 @@
|
|
1
|
+
# a very basic implementation of the view_component lib
|
2
|
+
module ViewComponent
|
3
|
+
class Slot
|
4
|
+
def initialize(component_instance, content_block)
|
5
|
+
@component_instance = component_instance
|
6
|
+
@content_block = content_block
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
@component_instance.content = @content_block.call(@component_instance) if @content_block
|
11
|
+
@component_instance.call
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Base
|
16
|
+
class << self
|
17
|
+
def renders_many(name, component)
|
18
|
+
singular_name = name.to_s.chomp("s")
|
19
|
+
|
20
|
+
registered_slots[name] = {
|
21
|
+
renderable: component,
|
22
|
+
collection: true
|
23
|
+
}
|
24
|
+
|
25
|
+
define_method(:"with_#{singular_name}") do |*args, **kwargs, &block|
|
26
|
+
slots[name] ||= []
|
27
|
+
slots[name] << Slot.new(component.new(*args, **kwargs), block)
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
31
|
+
define_method(name) do
|
32
|
+
slots[name] || []
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def registered_slots
|
39
|
+
@registered_slots ||= {}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
attr_accessor :content
|
44
|
+
|
45
|
+
def render(component, &block)
|
46
|
+
if block
|
47
|
+
component.content = block.call(component)
|
48
|
+
end
|
49
|
+
|
50
|
+
component.call
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def slots
|
56
|
+
@slots ||= {}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -54,7 +54,12 @@ files:
|
|
54
54
|
- bin/ruxc
|
55
55
|
- lib/rux.rb
|
56
56
|
- lib/rux/ast.rb
|
57
|
+
- lib/rux/ast/attr_node.rb
|
58
|
+
- lib/rux/ast/attrs_node.rb
|
59
|
+
- lib/rux/ast/fragment_node.rb
|
57
60
|
- lib/rux/ast/list_node.rb
|
61
|
+
- lib/rux/ast/root_node.rb
|
62
|
+
- lib/rux/ast/ruby_attr_node.rb
|
58
63
|
- lib/rux/ast/ruby_node.rb
|
59
64
|
- lib/rux/ast/string_node.rb
|
60
65
|
- lib/rux/ast/tag_node.rb
|
@@ -76,9 +81,19 @@ files:
|
|
76
81
|
- lib/rux/version.rb
|
77
82
|
- lib/rux/visitor.rb
|
78
83
|
- rux.gemspec
|
84
|
+
- spec/parser/attributes_spec.rb
|
85
|
+
- spec/parser/fragment_spec.rb
|
86
|
+
- spec/parser/html_safety_spec.rb
|
87
|
+
- spec/parser/slot_spec.rb
|
88
|
+
- spec/parser/tag_spec.rb
|
79
89
|
- spec/parser_spec.rb
|
80
90
|
- spec/render_spec.rb
|
81
91
|
- spec/spec_helper.rb
|
92
|
+
- spec/support/components/args_component.rb
|
93
|
+
- spec/support/components/data_component.rb
|
94
|
+
- spec/support/components/table_component.rb
|
95
|
+
- spec/support/components/test_component.rb
|
96
|
+
- spec/support/view_component/base.rb
|
82
97
|
homepage: http://github.com/camertron/rux
|
83
98
|
licenses: []
|
84
99
|
metadata: {}
|