evc_rails 0.2.2 → 0.2.3

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: fb8d4d59a3526f01f08e3c152ff5abe083e1a2bf1e66ab929db733356b56c822
4
- data.tar.gz: 07c8c5688a9ad4ddb78f34ca174f478e9103b656c09223c86aed522746b0b299
3
+ metadata.gz: '0083734e9b8f16100d769aa08c7393c7e60105a5c9bcbc3774c5955cc3c71def'
4
+ data.tar.gz: 9099d7be89c3b5c6805fbd0b7b9316409c53a89ff62b1460391265c4a18fa97b
5
5
  SHA512:
6
- metadata.gz: 6e429ae91cf3b0e3ac7b47001e164e65f6c4c6bd45f6c11f4258bb0a3c7cf77fa04594a4f493b887f434809ff11174996b09099273ac1bfac50897b002489158
7
- data.tar.gz: 57c5fb478a987d55dd24e22afda9198f9af0b11056ac3ab2bbf66a52ec420251cae33cfa596caa5074015e241cd5d6754b2f95a04c46ba1951c0190694f92e64
6
+ metadata.gz: 742227dddbef882cf3a085bfd2c8642e4decc61a76bb83f858b55bb900d1064d09b9507beb3cbfbb62d5472a644793f4457057d23962cce134a6d75aa018bfca
7
+ data.tar.gz: 13948d925ffc1419337d7d6a104be86bdae102577a133393978cb8c00eab2f7ee63bc627c6e15667c34671534f020588cf5e97297cbc82f6e0d79e800c9b416e
data/CHANGELOG.md ADDED
@@ -0,0 +1,87 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.2.2] - 2024-12-19
11
+
12
+ ### Added
13
+
14
+ - **Boolean attribute shorthand**: Support for HTML-style boolean attributes without values
15
+ - `<Button disabled required />` now converts to `disabled: true, required: true`
16
+ - Makes templates more concise and readable for boolean parameters
17
+ - Works with any boolean parameter your component defines
18
+
19
+ ### Changed
20
+
21
+ - Updated test suite to use new snake_case variable naming convention
22
+ - Improved block variable syntax consistency across all examples
23
+
24
+ ## [0.2.1] - 2024-12-19
25
+
26
+ ### Added
27
+
28
+ - **Custom block variable naming**: Support for `as` attribute to customize yielded variable names
29
+ - `<Card as="my_card">` yields `|my_card|` instead of `|card|`
30
+ - Helps avoid variable name collisions in nested components
31
+ - Useful for accessing parent component context from nested components
32
+
33
+ ### Changed
34
+
35
+ - **Block variable naming**: Components now yield snake_case variable names by default
36
+ - `<Card>` now yields `|card|` instead of `|c|`
37
+ - More descriptive and consistent with Ruby naming conventions
38
+ - Only yields variables when slots are present in the component
39
+
40
+ ### Fixed
41
+
42
+ - Improved slot method naming to match ViewComponent conventions
43
+ - `<WithHeader>` maps to `with_header` method (not `header`)
44
+ - `<WithItem>` maps to `with_item` method for both `renders_one` and `renders_many`
45
+ - Ensures compatibility with ViewComponent's generated method names
46
+
47
+ ## [0.2.0] - 2024-12-19
48
+
49
+ ### Added
50
+
51
+ - **Slot support**: Full support for ViewComponent slots with `<With...>` syntax
52
+ - `<WithHeader>` for `renders_one :header`
53
+ - `<WithItem>` for `renders_many :items` (uses singular method name)
54
+ - Support for slot attributes and Ruby expressions
55
+ - Automatic block variable yielding when slots are present
56
+ - **Namespaced component support**: Components in subdirectories
57
+ - `<UI::Button />` maps to `app/components/ui/button_component.rb`
58
+ - `<Forms::Fields::TextField />` for deeply nested components
59
+ - **Enhanced error messages**: Line numbers and column positions for better debugging
60
+ - **Production caching**: Automatic template caching using Rails.cache
61
+ - **Cache management**: Methods to clear and inspect template cache
62
+
63
+ ### Changed
64
+
65
+ - **Template handler architecture**: Improved performance and reliability
66
+ - **Error handling**: More descriptive error messages with context
67
+
68
+ ## [0.1.0] - 2024-12-19
69
+
70
+ ### Added
71
+
72
+ - **Initial release**: Basic JSX-like syntax for ViewComponent
73
+ - **Self-closing components**: `<Button />` syntax
74
+ - **Block components**: `<Card>content</Card>` syntax
75
+ - **Attribute support**: String, Ruby expressions, and multiple attributes
76
+ - **ERB integration**: Full support for ERB tags and Ruby expressions
77
+ - **Drop-in replacement**: Works as a replacement for `.erb` files
78
+ - **Basic caching**: Template compilation caching for performance
79
+
80
+ ---
81
+
82
+ ## Version History Notes
83
+
84
+ - **0.1.0**: Initial release with core functionality
85
+ - **0.2.0**: Major feature addition with slots and namespaced components
86
+ - **0.2.1**: Improved variable naming and slot method compatibility
87
+ - **0.2.2**: Added boolean attribute shorthand for cleaner templates
data/README.md CHANGED
@@ -298,6 +298,34 @@ end
298
298
 
299
299
  This generates distinct variables, `outer_card` and `inner_card`, allowing you to access the context of each component without collision.
300
300
 
301
+ #### Passing a Collection to a Plural Slot (Array Notation)
302
+
303
+ You can also pass an array directly to a plural slot method using embedded Ruby inside your EVC template. For this advanced use case, block variables are not inferred automatically and it is necessary to define block variables with the `as` attribute.
304
+
305
+ ```erb
306
+ <Navigation as="navigation">
307
+ <% navigation.with_links([
308
+ { name: "Home", href: "/" },
309
+ { name: "Pricing", href: "/pricing" },
310
+ { name: "Sign Up", href: "/sign-up" }
311
+ ]) %>
312
+ </Navigation>
313
+ ```
314
+
315
+ This is equivalent to the ERB version:
316
+
317
+ ```erb
318
+ <%= render NavigationComponent.new do |navigation| %>
319
+ <% navigation.with_links([
320
+ { name: "Home", href: "/" },
321
+ { name: "Pricing", href: "/pricing" },
322
+ { name: "Sign Up", href: "/sign-up" }
323
+ ]) %>
324
+ <% end %>
325
+ ```
326
+
327
+ You can use this approach for any plural slot method generated by `renders_many`. The block variable (e.g., `navigation`) is always available inside the component block when you use the `as` attribute, even if there are no `<With...>` slot tags present.
328
+
301
329
  ### Mixed Content
302
330
 
303
331
  You can mix regular HTML, ERB, and component tags:
@@ -150,8 +150,10 @@ module EvcRails
150
150
  else
151
151
  component_class = "#{tag_name}Component"
152
152
  variable_name = as_variable || component_variable_name(tag_name)
153
+ # If as_variable is present, force block variable to be yielded
154
+ force_block_variable = !as_variable.nil?
153
155
  stack << [tag_name, component_class, param_str, result.length, :component, nil, false, match.begin(0),
154
- variable_name]
156
+ variable_name, force_block_variable]
155
157
  result << if param_str.empty?
156
158
  "<%= render #{component_class}.new do %>"
157
159
  else
@@ -188,10 +190,10 @@ module EvcRails
188
190
  tag_type = open_tag_data[4]
189
191
 
190
192
  if tag_type == :component
191
- _tag_name, component_class, param_str, start_pos, _type, _slot_name, slot_used, _open_pos, variable_name = open_tag_data
193
+ _tag_name, component_class, param_str, start_pos, _type, _slot_name, slot_used, _open_pos, variable_name, force_block_variable = open_tag_data
192
194
 
193
- # Patch in |variable_name| for component if a slot was used
194
- if slot_used
195
+ # Patch in |variable_name| for component if a slot was used or as_variable was present
196
+ if slot_used || force_block_variable
195
197
  # More robustly find the end of the `do` block to insert the variable.
196
198
  # This avoids faulty regex matching on complex parameters.
197
199
  relevant_part = result[start_pos..-1]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EvcRails
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evc_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - scttymn
@@ -77,6 +77,7 @@ extensions: []
77
77
  extra_rdoc_files: []
78
78
  files:
79
79
  - ".rubocop.yml"
80
+ - CHANGELOG.md
80
81
  - LICENSE.txt
81
82
  - README.md
82
83
  - Rakefile