rblade 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/README.md +22 -22
- data/REFERENCE.md +1 -1
- data/examples/components/content/alert.rblade +1 -1
- data/examples/layouts/app.rblade +1 -1
- data/lib/rblade/compiler/statements/compiles_component_helpers.rb +19 -8
- data/lib/rblade/helpers/slot_manager.rb +5 -0
- data/rblade.gemspec +2 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80db67de9379396f85ba9450898e55f81b563cb1ca1ace73080719ad555455da
|
4
|
+
data.tar.gz: 9cc81c55f3893fbe1628dbe29c0d1dae16bdd65a789451e7f79ca6221e857488
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50092cc06cf7104210d23a47044f9ce7de728812e2c561120d59434480f6fb7cc5ca4e1ef299d3a7bf7368af45ffe8b113299c744eb14679e9a2572d4923610c
|
7
|
+
data.tar.gz: fa8797d09d7621f8122b8460c634e94e6db39ae6940a909e516ee20ef7d2ef1ab9963c2f549aff2a0a002a76899fc79fd5ff8e9b2bceb862364417c3a01af05f
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
## 1.0.
|
1
|
+
## 1.0.2 [2024-08-09]
|
2
|
+
- Fix non-string `@props` defaults being converted to slots
|
3
|
+
|
4
|
+
## 1.0.1 [2024-08-09]
|
5
|
+
- Automatically detect when properties are used as slots
|
6
|
+
- Change `_required` to `required` in @props
|
7
|
+
|
8
|
+
## 1.0.0 [2024-08-06]
|
2
9
|
- Add quick reference and examples
|
3
10
|
- Add @shouldRender directive
|
4
11
|
- Add support for ERB style `<%==` unsafe prints
|
data/README.md
CHANGED
@@ -5,11 +5,25 @@ RBlade is a simple, yet powerful templating engine for Ruby on Rails, inspired b
|
|
5
5
|
|
6
6
|
RBlade template files use the `.rblade` file extension and are typically stored in the `app/views` directory.
|
7
7
|
|
8
|
-
|
8
|
+
|
9
|
+
<a name="getting-started"></a>
|
10
|
+
## Getting Started
|
11
|
+
|
12
|
+
Add RBlade to your Rails project by adding it to your Gemfile:
|
13
|
+
|
14
|
+
```
|
15
|
+
bundle add rblade
|
16
|
+
```
|
17
|
+
|
18
|
+
RBlade will automatically be detected and start parsing templates ending in `.rblade`.
|
19
|
+
|
20
|
+
For a quick overview of RBlade's capabilities, refer to the [reference file](REFERENCE.md) or take a look at the [examples](examples/).
|
21
|
+
|
22
|
+
<a name="table-of-contents"></a>
|
9
23
|
## Table of Contents
|
10
24
|
- [RBlade Templates](#rblade-templates)
|
11
|
-
* [Table of Contents](#table-of-contents)
|
12
25
|
* [Getting Started](#getting-started)
|
26
|
+
* [Table of Contents](#table-of-contents)
|
13
27
|
* [Displaying Data](#displaying-data)
|
14
28
|
+ [HTML Entity Encoding](#html-entity-encoding)
|
15
29
|
+ [RBlade and JavaScript Frameworks](#rblade-and-javascript-frameworks)
|
@@ -45,20 +59,6 @@ RBlade template files use the `.rblade` file extension and are typically stored
|
|
45
59
|
+ [Method Field](#method-field)
|
46
60
|
* [Stacks](#stacks)
|
47
61
|
|
48
|
-
<a name="getting-started"></a>
|
49
|
-
## Getting Started
|
50
|
-
|
51
|
-
Add RBlade to your Rails project by adding it to your Gemfile:
|
52
|
-
|
53
|
-
```
|
54
|
-
bundle add rblade
|
55
|
-
```
|
56
|
-
|
57
|
-
RBlade will automatically be detected and start parsing templates ending in `.rblade`.
|
58
|
-
|
59
|
-
For a quick overview of RBlade's capabilities, refer to the [reference file](REFERENCE.md) or take a look at the [examples](examples/README.md).
|
60
|
-
|
61
|
-
|
62
62
|
<a name="displaying-data"></a>
|
63
63
|
## Displaying Data
|
64
64
|
|
@@ -475,11 +475,11 @@ You can define a component's data properties using a `@props` directive at the t
|
|
475
475
|
|
476
476
|
```rblade
|
477
477
|
{{-- alert.rblade --}}
|
478
|
-
@props({type: "warning", message:
|
478
|
+
@props({type: "warning", message: required})
|
479
479
|
<div class="{{ type }}">{{ message }}</div>
|
480
480
|
```
|
481
481
|
|
482
|
-
The `@props` directive accepts a Hash where the key is the name of the attribute, and the value is the default value for the property. You can use the special `
|
482
|
+
The `@props` directive accepts a Hash where the key is the name of the attribute, and the value is the default value for the property. You can use the special `required` value to represent a property with no default that must always be defined:
|
483
483
|
|
484
484
|
```rblade
|
485
485
|
{{-- This will give an error because the alert component requires a message propery --}}
|
@@ -489,7 +489,7 @@ The `@props` directive accepts a Hash where the key is the name of the attribute
|
|
489
489
|
All properties in the `@props` directive are automatically removed from `attributes`. Properties with names that aren't valid Ruby variable names or are Ruby reserved keywords are not created as local variables. However, you can reference them via the `attributes` local variable:
|
490
490
|
|
491
491
|
```rblade
|
492
|
-
@props({"for":
|
492
|
+
@props({"for": required, "data-value": nil})
|
493
493
|
<div>{{ attributes[:for] }} {{ attributes[:'data-value'] }}</div>
|
494
494
|
```
|
495
495
|
|
@@ -681,7 +681,7 @@ Sometimes a component may need to render multiple different slots in different l
|
|
681
681
|
|
682
682
|
```rblade
|
683
683
|
{{-- /app/views/components/alert.rblade --}}
|
684
|
-
@props({title:
|
684
|
+
@props({title: required})
|
685
685
|
<span class="alert-title">{{ title }}</span>
|
686
686
|
<div class="alert alert-danger">
|
687
687
|
{{ slot }}
|
@@ -737,8 +737,8 @@ To interact with slot attributes, you can access the `attributes` property of th
|
|
737
737
|
|
738
738
|
```rblade
|
739
739
|
@props({
|
740
|
-
"heading":
|
741
|
-
"footer":
|
740
|
+
"heading": required,
|
741
|
+
"footer": required,
|
742
742
|
})
|
743
743
|
|
744
744
|
<div {{ attributes.class('border') }}>
|
data/REFERENCE.md
CHANGED
@@ -31,7 +31,7 @@ By default, RBlade will look for components in the `app/views/components` folder
|
|
31
31
|
| `<x-name attribute/>` | Pass an attribute to a component with value `true` |
|
32
32
|
| `<x-name {{ attributes }}/>` | Pass attributes to a child component |
|
33
33
|
| `@props({header: "Header"})` | Remove `header` from the attributes Hash and introduce it as a local variable, using the specified value as a default |
|
34
|
-
| `@props({header:
|
34
|
+
| `@props({header: required})` | Remove `header` from the attributes Hash and introduce it as a local variable, raising an error if it is not set |
|
35
35
|
| `{{ slot }}` | Output the block content passed into the current component |
|
36
36
|
| `<x-name><x-slot::header><h1>Header</h1><//>Content<//>` | Pass a named block to a component |
|
37
37
|
| `{{ header }}` | Output the contents of a named block |
|
data/examples/layouts/app.rblade
CHANGED
@@ -11,7 +11,7 @@ module RBlade
|
|
11
11
|
"unless(#{args[0]});return'';end;"
|
12
12
|
end
|
13
13
|
|
14
|
-
def compileProps args
|
14
|
+
def compileProps args, tokens
|
15
15
|
if args&.count != 1
|
16
16
|
raise StandardError.new "Props statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
17
17
|
end
|
@@ -19,14 +19,20 @@ module RBlade
|
|
19
19
|
props = extractProps args[0]
|
20
20
|
props.map do |key, value|
|
21
21
|
compiled_code = ""
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
compiled_code << "#{key}=attributes[:'#{RBlade.escape_quotes(key)}'].nil? ? #{value} : attributes[:'#{RBlade.escape_quotes(key)}'];"
|
27
|
-
compiled_code << "attributes.delete :'#{RBlade.escape_quotes(key)}';"
|
22
|
+
|
23
|
+
# `_required` is deprecated. Use `required`. To be removed in 2.0.0
|
24
|
+
compiled_code << if value == "_required" || value == "required"
|
25
|
+
"if !attributes.has?(:'#{RBlade.escape_quotes(key)}');raise \"Props statement: #{key} is not defined\";end;"
|
28
26
|
else
|
29
|
-
|
27
|
+
"attributes.default(:'#{RBlade.escape_quotes(key)}', #{value});"
|
28
|
+
end
|
29
|
+
|
30
|
+
if isValidVariableName key
|
31
|
+
compiled_code << if variableIsSlot key, tokens
|
32
|
+
"#{key}=RBlade::SlotManager.wrap(attributes.delete :'#{RBlade.escape_quotes(key)}');"
|
33
|
+
else
|
34
|
+
"#{key}=attributes.delete :'#{RBlade.escape_quotes(key)}';"
|
35
|
+
end
|
30
36
|
end
|
31
37
|
|
32
38
|
compiled_code
|
@@ -83,6 +89,11 @@ module RBlade
|
|
83
89
|
|
84
90
|
true
|
85
91
|
end
|
92
|
+
|
93
|
+
# Automatically detect if a variable is a slot by looking for "<var>.attributes"
|
94
|
+
def variableIsSlot name, tokens
|
95
|
+
tokens.any? { |token| token.value.to_s.match "#{name}.attributes" }
|
96
|
+
end
|
86
97
|
end
|
87
98
|
end
|
88
99
|
end
|
data/rblade.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "rblade"
|
3
|
-
s.version = "1.0.
|
3
|
+
s.version = "1.0.2"
|
4
4
|
s.summary = "A component-first templating engine for Rails"
|
5
5
|
s.description = "RBlade is a simple, yet powerful templating engine for Ruby on Rails, inspired by Laravel Blade."
|
6
6
|
s.authors = ["Simon J"]
|
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|storage)/}) }
|
9
9
|
s.require_paths = ["lib"]
|
10
10
|
s.homepage = "https://rubygems.org/gems/rblade"
|
11
|
+
s.metadata = { "source_code_uri" => "https://github.com/mwnciau/rblade" }
|
11
12
|
s.license = "MIT"
|
12
13
|
s.required_ruby_version = ">= 3.0.0"
|
13
14
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rblade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon J
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -122,7 +122,8 @@ files:
|
|
122
122
|
homepage: https://rubygems.org/gems/rblade
|
123
123
|
licenses:
|
124
124
|
- MIT
|
125
|
-
metadata:
|
125
|
+
metadata:
|
126
|
+
source_code_uri: https://github.com/mwnciau/rblade
|
126
127
|
post_install_message:
|
127
128
|
rdoc_options: []
|
128
129
|
require_paths:
|