rblade 0.5.0 → 1.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -2
- data/README.md +180 -543
- data/REFERENCE.md +138 -0
- data/examples/README.md +3 -0
- data/examples/application/home.rblade +23 -0
- data/examples/components/content/alert.rblade +6 -0
- data/examples/components/content/hero.rblade +14 -0
- data/examples/components/h1.rblade +6 -0
- data/examples/components/p.rblade +14 -0
- data/examples/layouts/app.rblade +16 -0
- data/lib/rblade/compiler/compiles_components.rb +3 -3
- data/lib/rblade/compiler/{compiles_echos.rb → compiles_prints.rb} +11 -10
- data/lib/rblade/compiler/compiles_ruby.rb +1 -1
- data/lib/rblade/compiler/compiles_statements.rb +24 -17
- data/lib/rblade/compiler/statements/{compiles_props.rb → compiles_component_helpers.rb} +13 -5
- data/lib/rblade/compiler/statements/compiles_conditionals.rb +45 -13
- data/lib/rblade/compiler/statements/compiles_form.rb +48 -0
- data/lib/rblade/compiler/statements/compiles_loops.rb +8 -4
- data/lib/rblade/compiler/statements/compiles_once.rb +6 -6
- data/lib/rblade/compiler/statements/compiles_stacks.rb +43 -19
- data/lib/rblade/compiler/tokenizes_statements.rb +13 -2
- data/lib/rblade/compiler.rb +3 -3
- data/lib/rblade/component_store.rb +1 -1
- data/lib/rblade/helpers/attributes_manager.rb +28 -8
- data/lib/rblade/helpers/slot_manager.rb +8 -2
- data/rblade.gemspec +1 -1
- metadata +17 -9
- data/TODO.md +0 -2
@@ -17,7 +17,7 @@ module RBlade
|
|
17
17
|
|
18
18
|
def compilePushOnce args
|
19
19
|
if args&.count != 1 && args&.count != 2
|
20
|
-
raise StandardError.new "Push once statement: wrong number of arguments (given #{args
|
20
|
+
raise StandardError.new "Push once statement: wrong number of arguments (given #{args&.count || 0}, expecting 1 or 2)"
|
21
21
|
end
|
22
22
|
@once_counter += 1
|
23
23
|
once_id = args[1].nil? ? ":_#{@once_counter}" : args[1]
|
@@ -27,8 +27,8 @@ module RBlade
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def compileEndPushOnce args
|
30
|
-
|
31
|
-
raise StandardError.new "End push once statement: wrong number of arguments (given #{args
|
30
|
+
unless args.nil?
|
31
|
+
raise StandardError.new "End push once statement: wrong number of arguments (given #{args.count}, expecting 0)"
|
32
32
|
end
|
33
33
|
|
34
34
|
"RBlade::StackManager.push(_p1_#{@once_counter}, _out);_out=_p1_#{@once_counter}_b;end;"
|
@@ -36,7 +36,7 @@ module RBlade
|
|
36
36
|
|
37
37
|
def compilePrependOnce args
|
38
38
|
if args&.count != 1 && args&.count != 2
|
39
|
-
raise StandardError.new "Prepend once statement: wrong number of arguments (given #{args
|
39
|
+
raise StandardError.new "Prepend once statement: wrong number of arguments (given #{args&.count || 0}, expecting 1 or 2)"
|
40
40
|
end
|
41
41
|
@once_counter += 1
|
42
42
|
once_id = args[1].nil? ? ":_#{@once_counter}" : args[1]
|
@@ -46,8 +46,8 @@ module RBlade
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def compileEndPrependOnce args
|
49
|
-
|
50
|
-
raise StandardError.new "End prepend once statement: wrong number of arguments (given #{args
|
49
|
+
unless args.nil?
|
50
|
+
raise StandardError.new "End prepend once statement: wrong number of arguments (given #{args.count}, expecting 0)"
|
51
51
|
end
|
52
52
|
|
53
53
|
"RBlade::StackManager.prepend(_p1_#{@once_counter}, _out);_out=_p1_#{@once_counter}_b;end;"
|
@@ -7,28 +7,24 @@ module RBlade
|
|
7
7
|
|
8
8
|
def compileStack args
|
9
9
|
if args&.count != 1
|
10
|
-
raise StandardError.new "Stack statement: wrong number of arguments (given #{args&.count}, expecting 1)"
|
10
|
+
raise StandardError.new "Stack statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
11
11
|
end
|
12
12
|
|
13
13
|
"RBlade::StackManager.initialize(#{args[0]}, _out);_stacks.push(#{args[0]});_out = '';"
|
14
14
|
end
|
15
15
|
|
16
16
|
def compilePrepend args
|
17
|
-
if args
|
18
|
-
raise StandardError.new "Prepend statement: wrong number of arguments (given #{args&.count}, expecting 1
|
17
|
+
if args&.count != 1
|
18
|
+
raise StandardError.new "Prepend statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
"RBlade::StackManager.prepend(#{args[0]}, #{args[1]});"
|
23
|
-
else
|
24
|
-
@push_counter += 1
|
21
|
+
@push_counter += 1
|
25
22
|
|
26
|
-
|
27
|
-
end
|
23
|
+
"_p_#{@push_counter}=#{args[0]};_p_#{@push_counter}_b=_out;_out='';"
|
28
24
|
end
|
29
25
|
|
30
26
|
def compileEndPrepend args
|
31
|
-
|
27
|
+
unless args.nil?
|
32
28
|
raise StandardError.new "End prepend statement: wrong number of arguments (given #{args&.count}, expecting 0)"
|
33
29
|
end
|
34
30
|
|
@@ -37,29 +33,57 @@ module RBlade
|
|
37
33
|
"RBlade::StackManager.prepend(_p_#{@push_counter + 1}, _out);_out=_p_#{@push_counter + 1}_b;"
|
38
34
|
end
|
39
35
|
|
36
|
+
def compilePrependIf args
|
37
|
+
if args&.count != 2
|
38
|
+
raise StandardError.new "Prepend if statement: wrong number of arguments (given #{args&.count}, expecting 2)"
|
39
|
+
end
|
40
|
+
|
41
|
+
"if #{args[0]};" + compilePrepend([args[1]])
|
42
|
+
end
|
43
|
+
|
44
|
+
def compileEndPrependIf args
|
45
|
+
unless args.nil?
|
46
|
+
raise StandardError.new "End prepend if statement: wrong number of arguments (given #{args.count}, expecting 0)"
|
47
|
+
end
|
48
|
+
|
49
|
+
"end;" + compileEndPush(nil)
|
50
|
+
end
|
51
|
+
|
40
52
|
def compilePush args
|
41
|
-
if args
|
42
|
-
raise StandardError.new "Push statement: wrong number of arguments (given #{args&.count}, expecting 1
|
53
|
+
if args&.count != 1
|
54
|
+
raise StandardError.new "Push statement: wrong number of arguments (given #{args&.count}, expecting 1)"
|
43
55
|
end
|
44
56
|
|
45
|
-
|
46
|
-
"RBlade::StackManager.push(#{args[0]}, #{args[1]});"
|
47
|
-
else
|
48
|
-
@push_counter += 1
|
57
|
+
@push_counter += 1
|
49
58
|
|
50
|
-
|
59
|
+
"_p_#{@push_counter}=#{args[0]};_p_#{@push_counter}_b=_out;_out='';"
|
60
|
+
end
|
61
|
+
|
62
|
+
def compilePushIf args
|
63
|
+
if args&.count != 2
|
64
|
+
raise StandardError.new "Push if statement: wrong number of arguments (given #{args&.count || 0}, expecting 2)"
|
51
65
|
end
|
66
|
+
|
67
|
+
"if #{args[0]};" + compilePush([args[1]])
|
52
68
|
end
|
53
69
|
|
54
70
|
def compileEndPush args
|
55
|
-
|
56
|
-
raise StandardError.new "End push statement: wrong number of arguments (given #{args
|
71
|
+
unless args.nil?
|
72
|
+
raise StandardError.new "End push statement: wrong number of arguments (given #{args.count}, expecting 0)"
|
57
73
|
end
|
58
74
|
|
59
75
|
@push_counter -= 1
|
60
76
|
|
61
77
|
"RBlade::StackManager.push(_p_#{@push_counter + 1}, _out);_out=_p_#{@push_counter + 1}_b;"
|
62
78
|
end
|
79
|
+
|
80
|
+
def compileEndPushIf args
|
81
|
+
unless args.nil?
|
82
|
+
raise StandardError.new "End push if statement: wrong number of arguments (given #{args.count}, expecting 0)"
|
83
|
+
end
|
84
|
+
|
85
|
+
"end;" + compileEndPush(nil)
|
86
|
+
end
|
63
87
|
end
|
64
88
|
end
|
65
89
|
end
|
@@ -12,12 +12,12 @@ module RBlade
|
|
12
12
|
(?:
|
13
13
|
(?:
|
14
14
|
(@@)
|
15
|
-
(\w+(?!\w))
|
15
|
+
(\w+(?!\w)[!\?]?)
|
16
16
|
)
|
17
17
|
|
|
18
18
|
(?:
|
19
19
|
(@)
|
20
|
-
(\w+(?!\w))
|
20
|
+
(\w+(?!\w)[!\?]?)
|
21
21
|
(?:[ \t]*
|
22
22
|
(\(.*?\))
|
23
23
|
)?
|
@@ -45,6 +45,7 @@ module RBlade
|
|
45
45
|
i += 1
|
46
46
|
elsif segment == "@"
|
47
47
|
tokenizeStatement! segments, i
|
48
|
+
handleSpecialCases! segments, i
|
48
49
|
|
49
50
|
i += 1
|
50
51
|
elsif !segments[i].nil? && segments[i] != ""
|
@@ -74,6 +75,16 @@ module RBlade
|
|
74
75
|
segments[i] = Token.new(type: :statement, value: statement_data)
|
75
76
|
end
|
76
77
|
|
78
|
+
def handleSpecialCases!(segments, i)
|
79
|
+
case segments[i][:value][:name]
|
80
|
+
when "case"
|
81
|
+
# Remove any whitespace before a when statement
|
82
|
+
until segments[i + 1].nil? || segments[i + 1] == "@"
|
83
|
+
segments.delete_at i + 1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
77
88
|
def tokenizeArguments!(segments, segment_index)
|
78
89
|
success = expandSegmentToEndParenthesis! segments, segment_index
|
79
90
|
|
data/lib/rblade/compiler.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "rblade/compiler/compiles_comments"
|
2
2
|
require "rblade/compiler/compiles_components"
|
3
|
-
require "rblade/compiler/
|
3
|
+
require "rblade/compiler/compiles_prints"
|
4
4
|
require "rblade/compiler/compiles_ruby"
|
5
5
|
require "rblade/compiler/compiles_verbatim"
|
6
6
|
require "rblade/compiler/compiles_statements"
|
@@ -37,7 +37,7 @@ module RBlade
|
|
37
37
|
CompilesRuby.new.compile! tokens
|
38
38
|
TokenizesComponents.new.tokenize! tokens
|
39
39
|
TokenizesStatements.new.tokenize! tokens
|
40
|
-
|
40
|
+
CompilesPrints.new.compile! tokens
|
41
41
|
CompilesStatements.new.compile! tokens
|
42
42
|
CompilesComponents.new.compile! tokens
|
43
43
|
|
@@ -49,7 +49,7 @@ module RBlade
|
|
49
49
|
|
50
50
|
CompilesComments.compile!(tokens)
|
51
51
|
CompilesRuby.compile! tokens
|
52
|
-
|
52
|
+
CompilesPrints.compile!(tokens)
|
53
53
|
|
54
54
|
compileTokens tokens
|
55
55
|
end
|
@@ -81,7 +81,7 @@ module RBlade
|
|
81
81
|
compiled_component = RBlade::Compiler.compileString(code)
|
82
82
|
|
83
83
|
@@component_definitions \
|
84
|
-
<< "def #{@@component_method_names[name]}(slot,attributes);_out='';" \
|
84
|
+
<< "def #{@@component_method_names[name]}(slot,attributes,params,session,flash,cookies);_out='';" \
|
85
85
|
<< "_stacks=[];" \
|
86
86
|
<< "attributes=RBlade::AttributesManager.new(attributes);" \
|
87
87
|
<< compiled_component \
|
@@ -15,16 +15,22 @@ module RBlade
|
|
15
15
|
@attributes[key]
|
16
16
|
end
|
17
17
|
|
18
|
-
def has?(
|
19
|
-
|
18
|
+
def has?(*keys)
|
19
|
+
keys.map!(&:to_sym)
|
20
|
+
|
21
|
+
keys.all? { |key| @attributes.has_key? key }
|
20
22
|
end
|
21
23
|
|
22
|
-
def method_missing(method,
|
23
|
-
|
24
|
+
def method_missing(method, *, &)
|
25
|
+
if [:select, :filter, :slice].include? method
|
26
|
+
AttributesManager.new @attributes.send(method, *, &)
|
27
|
+
else
|
28
|
+
@attributes.send(method, *, &)
|
29
|
+
end
|
24
30
|
end
|
25
31
|
|
26
32
|
def respond_to_missing?(method_name, *args)
|
27
|
-
@attributes.respond_to?(method_name)
|
33
|
+
@attributes.respond_to?(method_name)
|
28
34
|
end
|
29
35
|
|
30
36
|
def to_s attributes = nil
|
@@ -46,7 +52,7 @@ module RBlade
|
|
46
52
|
[keys.to_sym]
|
47
53
|
end
|
48
54
|
|
49
|
-
|
55
|
+
AttributesManager.new @attributes.slice(*keys)
|
50
56
|
end
|
51
57
|
|
52
58
|
def except(keys)
|
@@ -56,7 +62,15 @@ module RBlade
|
|
56
62
|
[keys.to_sym]
|
57
63
|
end
|
58
64
|
|
59
|
-
|
65
|
+
AttributesManager.new @attributes.except(*keys)
|
66
|
+
end
|
67
|
+
|
68
|
+
def class(new_classes)
|
69
|
+
new_classes = ClassManager.new(new_classes).to_s
|
70
|
+
attributes = @attributes.dup
|
71
|
+
attributes[:class] = mergeClasses attributes[:class], new_classes
|
72
|
+
|
73
|
+
AttributesManager.new attributes
|
60
74
|
end
|
61
75
|
|
62
76
|
def merge(default_attributes)
|
@@ -76,7 +90,13 @@ module RBlade
|
|
76
90
|
new_attributes[key] = value
|
77
91
|
end
|
78
92
|
|
79
|
-
|
93
|
+
AttributesManager.new new_attributes
|
94
|
+
end
|
95
|
+
|
96
|
+
def has_any?(*keys)
|
97
|
+
keys.map!(&:to_sym)
|
98
|
+
|
99
|
+
keys.any? { |key| @attributes.has_key? key }
|
80
100
|
end
|
81
101
|
|
82
102
|
private
|
@@ -16,8 +16,14 @@ module RBlade
|
|
16
16
|
to_s
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
@
|
19
|
+
def method_missing(method, *)
|
20
|
+
@content.send(method, *)
|
21
21
|
end
|
22
|
+
|
23
|
+
def respond_to_missing?(method_name, *args)
|
24
|
+
@content.respond_to?(method_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :attributes
|
22
28
|
end
|
23
29
|
end
|
data/rblade.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "rblade"
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "1.0.0"
|
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"]
|
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: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon J
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -79,24 +79,32 @@ files:
|
|
79
79
|
- Gemfile
|
80
80
|
- LICENSE.md
|
81
81
|
- README.md
|
82
|
+
- REFERENCE.md
|
82
83
|
- Rakefile
|
83
|
-
- TODO.md
|
84
84
|
- do
|
85
85
|
- docker-compose.yml
|
86
|
+
- examples/README.md
|
87
|
+
- examples/application/home.rblade
|
88
|
+
- examples/components/content/alert.rblade
|
89
|
+
- examples/components/content/hero.rblade
|
90
|
+
- examples/components/h1.rblade
|
91
|
+
- examples/components/p.rblade
|
92
|
+
- examples/layouts/app.rblade
|
86
93
|
- lib/rblade.rb
|
87
94
|
- lib/rblade/compiler.rb
|
88
95
|
- lib/rblade/compiler/compiles_comments.rb
|
89
96
|
- lib/rblade/compiler/compiles_components.rb
|
90
|
-
- lib/rblade/compiler/
|
97
|
+
- lib/rblade/compiler/compiles_prints.rb
|
91
98
|
- lib/rblade/compiler/compiles_ruby.rb
|
92
99
|
- lib/rblade/compiler/compiles_statements.rb
|
93
100
|
- lib/rblade/compiler/compiles_verbatim.rb
|
101
|
+
- lib/rblade/compiler/statements/compiles_component_helpers.rb
|
94
102
|
- lib/rblade/compiler/statements/compiles_conditionals.rb
|
103
|
+
- lib/rblade/compiler/statements/compiles_form.rb
|
95
104
|
- lib/rblade/compiler/statements/compiles_html_attributes.rb
|
96
105
|
- lib/rblade/compiler/statements/compiles_inline_ruby.rb
|
97
106
|
- lib/rblade/compiler/statements/compiles_loops.rb
|
98
107
|
- lib/rblade/compiler/statements/compiles_once.rb
|
99
|
-
- lib/rblade/compiler/statements/compiles_props.rb
|
100
108
|
- lib/rblade/compiler/statements/compiles_stacks.rb
|
101
109
|
- lib/rblade/compiler/tokenizes_components.rb
|
102
110
|
- lib/rblade/compiler/tokenizes_statements.rb
|
@@ -115,7 +123,7 @@ homepage: https://rubygems.org/gems/rblade
|
|
115
123
|
licenses:
|
116
124
|
- MIT
|
117
125
|
metadata: {}
|
118
|
-
post_install_message:
|
126
|
+
post_install_message:
|
119
127
|
rdoc_options: []
|
120
128
|
require_paths:
|
121
129
|
- lib
|
@@ -130,8 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
138
|
- !ruby/object:Gem::Version
|
131
139
|
version: '0'
|
132
140
|
requirements: []
|
133
|
-
rubygems_version: 3.5
|
134
|
-
signing_key:
|
141
|
+
rubygems_version: 3.3.5
|
142
|
+
signing_key:
|
135
143
|
specification_version: 4
|
136
144
|
summary: A component-first templating engine for Rails
|
137
145
|
test_files: []
|
data/TODO.md
DELETED