rux 1.1.1 → 1.2.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.
@@ -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.1.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-05-28 00:00:00.000000000 Z
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: {}