evc_rails 0.2.1 → 0.2.2
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/README.md +16 -0
- data/lib/evc_rails/template_handler.rb +11 -8
- data/lib/evc_rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb8d4d59a3526f01f08e3c152ff5abe083e1a2bf1e66ab929db733356b56c822
|
4
|
+
data.tar.gz: 07c8c5688a9ad4ddb78f34ca174f478e9103b656c09223c86aed522746b0b299
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e429ae91cf3b0e3ac7b47001e164e65f6c4c6bd45f6c11f4258bb0a3c7cf77fa04594a4f493b887f434809ff11174996b09099273ac1bfac50897b002489158
|
7
|
+
data.tar.gz: 57c5fb478a987d55dd24e22afda9198f9af0b11056ac3ab2bbf66a52ec420251cae33cfa596caa5074015e241cd5d6754b2f95a04c46ba1951c0190694f92e64
|
data/README.md
CHANGED
@@ -176,6 +176,22 @@ There are two ways to pass information to a component:
|
|
176
176
|
- **As attributes:** Data passed as attributes on the main component tag (e.g. `<Card title="...">`) is sent to its `initialize` method.
|
177
177
|
- **As slot content:** Rich content passed via `<With...>` tags is used to populate the component's named slots.
|
178
178
|
|
179
|
+
#### Boolean Attribute Shorthand
|
180
|
+
|
181
|
+
You can use HTML-style boolean attributes in EVC. If you specify an attribute with no value, it will be passed as `true` to your component initializer. This makes templates more concise and readable:
|
182
|
+
|
183
|
+
```erb
|
184
|
+
<Button disabled required />
|
185
|
+
```
|
186
|
+
|
187
|
+
is equivalent to:
|
188
|
+
|
189
|
+
```erb
|
190
|
+
<%= render ButtonComponent.new(disabled: true, required: true) %>
|
191
|
+
```
|
192
|
+
|
193
|
+
This works for any boolean parameter your component defines.
|
194
|
+
|
179
195
|
#### When a Block Variable is Yielded
|
180
196
|
|
181
197
|
The contextual variable (e.g., `|card|`) is only yielded if one or more `<With...>` slot tags are present inside the component block. If you render a component like `<Card></Card>` with no slots inside, `evc_rails` is smart enough to render it without the `do |card|` part.
|
@@ -13,7 +13,7 @@ module EvcRails
|
|
13
13
|
CLOSE_TAG_REGEX = %r{</([A-Z][a-zA-Z0-9_]*(?:::[A-Z][a-zA-Z0-9_]*)*)>}
|
14
14
|
|
15
15
|
# Regex for attributes
|
16
|
-
ATTRIBUTE_REGEX = /(\w+)
|
16
|
+
ATTRIBUTE_REGEX = /(\w+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|\{([^}]*)\}))?/
|
17
17
|
|
18
18
|
# Cache for compiled templates
|
19
19
|
@template_cache = {}
|
@@ -254,13 +254,16 @@ module EvcRails
|
|
254
254
|
|
255
255
|
params = []
|
256
256
|
attributes_str.scan(attribute_regex) do |key, quoted_value, single_quoted_value, ruby_expression|
|
257
|
-
if ruby_expression
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
257
|
+
params << if ruby_expression
|
258
|
+
"#{key}: #{ruby_expression}"
|
259
|
+
elsif quoted_value
|
260
|
+
"#{key}: \"#{quoted_value.gsub('"', '\\"')}\""
|
261
|
+
elsif single_quoted_value
|
262
|
+
"#{key}: \"#{single_quoted_value.gsub("'", "\\'")}\""
|
263
|
+
else
|
264
|
+
# Standalone attribute (no value) - treat as boolean true
|
265
|
+
"#{key}: true"
|
266
|
+
end
|
264
267
|
end
|
265
268
|
[params, as_variable]
|
266
269
|
end
|
data/lib/evc_rails/version.rb
CHANGED