rblade 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/rblade/compiler/compiles_components.rb +48 -9
- data/lib/rblade/compiler/compiles_echos.rb +5 -4
- data/lib/rblade/compiler/compiles_statements.rb +2 -0
- data/lib/rblade/compiler/statements/compiles_props.rb +61 -0
- data/lib/rblade/compiler/tokenizes_components.rb +7 -7
- data/lib/rblade/compiler/tokenizes_statements.rb +2 -58
- data/lib/rblade/compiler.rb +2 -2
- data/lib/rblade/component_store.rb +8 -8
- data/lib/rblade/helpers/attributes_manager.rb +66 -0
- data/lib/rblade/helpers/class_manager.rb +23 -0
- data/lib/rblade/helpers/style_manager.rb +37 -0
- data/lib/rblade/helpers/tokenizer.rb +63 -0
- data/lib/rblade/rails_template.rb +4 -1
- data/rblade.gemspec +2 -2
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d55092cb6f64266006466fb9fcb1f6f9de30bb1a2df18e5ed123a7778f694c8
|
4
|
+
data.tar.gz: bd6ed6fca05f62d0cd606d53addbb27ecbabe1b32dcdd76f2a150d6227e3c6f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0821ffdde4f0e0ba9763c37e6f167a1e990aa7ef912b19561aa6f5f97ff90b0ddc4cbee7472bb73d2d31f0ef0d560ec81f47ab92a68a0280478a054d4c133bf4'
|
7
|
+
data.tar.gz: 450ae054965627db91899496ed5fefa3f34cb057710f7377941d196b0a6e753eea7c41ff8f5082174947f30a702ab8e346dea19f6de6e5ecdbf7e8492e1767db
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
## 0.2.1 [2024-07-23]
|
2
|
+
- Add support for attributes pass through in components
|
3
|
+
|
4
|
+
## 0.2.0 [2024-07-23]
|
5
|
+
- Fix slots being calculated without parent's context
|
6
|
+
- Add @props statement
|
7
|
+
- Add attributes, class and style manager
|
8
|
+
|
9
|
+
## 0.1.0 [2024-07-22]
|
10
|
+
- Initial release
|
@@ -2,6 +2,11 @@ require "rblade/component_store"
|
|
2
2
|
|
3
3
|
module RBlade
|
4
4
|
class CompilesComponents
|
5
|
+
def initialize
|
6
|
+
@component_count = 0
|
7
|
+
@component_stack = []
|
8
|
+
end
|
9
|
+
|
5
10
|
def compile!(tokens)
|
6
11
|
tokens.each do |token|
|
7
12
|
if [:component, :component_start, :component_end].none? token.type
|
@@ -21,25 +26,59 @@ module RBlade
|
|
21
26
|
private
|
22
27
|
|
23
28
|
def compile_token_start token
|
24
|
-
|
25
|
-
|
29
|
+
@component_count += 1
|
30
|
+
|
31
|
+
@component_stack << {
|
32
|
+
name: token.value[:name],
|
33
|
+
attributes: token.value[:attributes],
|
34
|
+
index: @component_count
|
35
|
+
}
|
36
|
+
|
37
|
+
"_comp_#{@component_count}_swap=_out;_out='';"
|
26
38
|
end
|
27
39
|
|
28
40
|
def compile_token_end token
|
29
|
-
|
41
|
+
component = @component_stack.pop
|
42
|
+
if component.nil?
|
43
|
+
raise StandardError.new "Unexpected closing tag (#{token.value[:name]})"
|
44
|
+
end
|
45
|
+
if token.value[:name] != component[:name]
|
46
|
+
raise StandardError.new "Unexpected closing tag (#{token.value[:name]}) expecting #{component[:name]}"
|
47
|
+
end
|
48
|
+
|
49
|
+
attributes = compile_attributes component[:attributes]
|
50
|
+
|
51
|
+
code = "def _component(slot,attributes);#{attributes[:assignments].join}_out='';"
|
52
|
+
code << "_stacks=[];"
|
53
|
+
code << "attributes=RBlade::AttributesManager.new(attributes);"
|
30
54
|
code << ComponentStore.fetchComponent(token.value[:name])
|
31
|
-
code << "RBlade::StackManager.get(_stacks) + _out;end;
|
55
|
+
code << "RBlade::StackManager.get(_stacks) + _out;end;"
|
56
|
+
code << "_slot=_out;_out=_comp_#{component[:index]}_swap;"
|
57
|
+
code << "_out<<_component(_slot,{#{attributes[:arguments].join(",")}});"
|
32
58
|
|
33
59
|
code
|
34
60
|
end
|
35
61
|
|
36
|
-
def compile_attributes
|
62
|
+
def compile_attributes attributes
|
37
63
|
attribute_arguments = []
|
38
64
|
attribute_assignments = []
|
39
65
|
|
40
|
-
|
41
|
-
if attribute[:type] == "class"
|
42
|
-
attribute_arguments.push "'
|
66
|
+
attributes.each do |attribute|
|
67
|
+
if attribute[:type] == "class"
|
68
|
+
attribute_arguments.push "'class': RBlade::ClassManager.new(#{attribute[:value]})"
|
69
|
+
attribute_assignments.push "_class = attributes[:class];"
|
70
|
+
|
71
|
+
next
|
72
|
+
end
|
73
|
+
if attribute[:type] == "style"
|
74
|
+
attribute_arguments.push "'style': RBlade::StyleManager.new(#{attribute[:value]})"
|
75
|
+
attribute_assignments.push "_style = attributes[:style];"
|
76
|
+
|
77
|
+
next
|
78
|
+
end
|
79
|
+
if attribute[:type] == "attributes"
|
80
|
+
attribute_arguments.push "**attributes.to_h"
|
81
|
+
attribute_assignments.push "_style = attributes[:style];"
|
43
82
|
|
44
83
|
next
|
45
84
|
end
|
@@ -49,7 +88,7 @@ module RBlade
|
|
49
88
|
end
|
50
89
|
|
51
90
|
if attribute[:type] == "ruby"
|
52
|
-
attribute_arguments.push "'#{attribute[:name]}': (#{attribute[:value]})
|
91
|
+
attribute_arguments.push "'#{attribute[:name]}': (#{attribute[:value]})"
|
53
92
|
end
|
54
93
|
|
55
94
|
if attribute[:type] == "pass_through"
|
@@ -35,11 +35,12 @@ module RBlade
|
|
35
35
|
segments.delete_at i
|
36
36
|
segments.delete_at i + 1
|
37
37
|
segment_value = "_out<<"
|
38
|
-
# Special case for slot - we want this to be able to output HTML
|
39
|
-
if !wrapper_function.nil? && segments[i] != "slot"
|
40
|
-
|
38
|
+
# Special case for slot and attributes - we want this to be able to output HTML
|
39
|
+
segment_value <<= if !wrapper_function.nil? && segments[i] != "slot" && !segments[i].start_with?("attributes")
|
40
|
+
wrapper_function + "(" + segments[i] + ");"
|
41
|
+
else
|
42
|
+
"(" + segments[i] + ").to_s;"
|
41
43
|
end
|
42
|
-
segment_value <<= "(" + segments[i] + ");"
|
43
44
|
segments[i] = Token.new(:echo, segment_value)
|
44
45
|
|
45
46
|
i += 1
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "rblade/compiler/statements/compiles_conditionals"
|
2
2
|
require "rblade/compiler/statements/compiles_inline_ruby"
|
3
3
|
require "rblade/compiler/statements/compiles_loops"
|
4
|
+
require "rblade/compiler/statements/compiles_props"
|
4
5
|
require "rblade/compiler/statements/compiles_stacks"
|
5
6
|
|
6
7
|
module RBlade
|
@@ -88,6 +89,7 @@ module RBlade
|
|
88
89
|
"next" => [CompilesLoops, :compileNext],
|
89
90
|
"nextif" => [CompilesLoops, :compileNextIf],
|
90
91
|
"prepend" => [CompilesStacks, :compilePrepend],
|
92
|
+
"props" => [CompilesProps, :compileProps],
|
91
93
|
"push" => [CompilesStacks, :compilePush],
|
92
94
|
"readonly" => [CompilesConditionals, :compileReadonly],
|
93
95
|
"required" => [CompilesConditionals, :compileRequired],
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "rblade/helpers/tokenizer"
|
2
|
+
|
3
|
+
module RBlade
|
4
|
+
class CompilesStatements
|
5
|
+
class CompilesProps
|
6
|
+
def compileProps args
|
7
|
+
if args.nil?
|
8
|
+
raise StandardError.new "Props statement: wrong number of arguments (given #{args&.count}, expecting 1)"
|
9
|
+
end
|
10
|
+
|
11
|
+
props = extractProps args[0]
|
12
|
+
props.map do |key, value|
|
13
|
+
if value == "_required"
|
14
|
+
"if !defined?(#{key});raise \"Props statement: #{key} is not defined\";end;"
|
15
|
+
else
|
16
|
+
"if !defined?(#{key});#{key}=#{value};end;"
|
17
|
+
end
|
18
|
+
end.join
|
19
|
+
end
|
20
|
+
|
21
|
+
def extractProps prop_string
|
22
|
+
if !prop_string.start_with?("{") || !prop_string.end_with?("}")
|
23
|
+
raise StandardError.new "Props statement: expecting hash as parameter"
|
24
|
+
end
|
25
|
+
|
26
|
+
props = {}
|
27
|
+
prop_strings = Tokenizer.extractCommaSeparatedValues prop_string[1..-2]
|
28
|
+
|
29
|
+
prop_strings.each do |prop|
|
30
|
+
prop.strip!
|
31
|
+
|
32
|
+
key, value = prop.split(/^
|
33
|
+
(?:
|
34
|
+
('.+'):
|
35
|
+
|
|
36
|
+
(".+"):
|
37
|
+
|
|
38
|
+
([^ :]+):
|
39
|
+
|
|
40
|
+
:(?:
|
41
|
+
'(.+?)'
|
42
|
+
|
|
43
|
+
"(.+?)"
|
44
|
+
|
|
45
|
+
([^"' ]+)
|
46
|
+
)\s*=>
|
47
|
+
)
|
48
|
+
\s*(.+?)$
|
49
|
+
/x).reject(&:empty?)
|
50
|
+
|
51
|
+
if key.nil? || value.nil?
|
52
|
+
raise StandardError.new "Props statement: invalid property hash"
|
53
|
+
end
|
54
|
+
props[key] = value
|
55
|
+
end
|
56
|
+
|
57
|
+
props
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -57,9 +57,9 @@ module RBlade
|
|
57
57
|
if name == "@class" || name == "@style"
|
58
58
|
attributes.push({type: name[1..], value: raw_attributes[i + 1][1..-2]})
|
59
59
|
i += 2
|
60
|
-
elsif name
|
61
|
-
attributes.push({type: "attributes", value: raw_attributes[i + 1]
|
62
|
-
i +=
|
60
|
+
elsif name == "{{"
|
61
|
+
attributes.push({type: "attributes", value: raw_attributes[i + 1]})
|
62
|
+
i += 3
|
63
63
|
else
|
64
64
|
attribute = {name:}
|
65
65
|
|
@@ -116,7 +116,7 @@ module RBlade
|
|
116
116
|
)
|
117
117
|
|
|
118
118
|
(
|
119
|
-
\{\{\s*attributes
|
119
|
+
\{\{\s*attributes.*?\s*\}\}
|
120
120
|
)
|
121
121
|
|
|
122
122
|
(?:
|
@@ -128,7 +128,7 @@ module RBlade
|
|
128
128
|
|
|
129
129
|
'[^\']*'
|
130
130
|
|
|
131
|
-
[^'"=<>\s]+
|
131
|
+
[^'"=<>\s\/]+
|
132
132
|
)
|
133
133
|
)?
|
134
134
|
)
|
@@ -163,7 +163,7 @@ module RBlade
|
|
163
163
|
)
|
164
164
|
|
|
165
165
|
(?:
|
166
|
-
(\{\{)\s*attributes
|
166
|
+
(\{\{)\s*(attributes.*?)\s*(\}\})
|
167
167
|
)
|
168
168
|
|
|
169
169
|
(?:
|
@@ -175,7 +175,7 @@ module RBlade
|
|
175
175
|
|
|
176
176
|
'([^\']*)'
|
177
177
|
|
|
178
|
-
([^'"=<>\s]+)
|
178
|
+
([^'"=<>\s\/]+)
|
179
179
|
)
|
180
180
|
)?
|
181
181
|
)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require "rblade/helpers/tokenizer"
|
1
2
|
require "ripper"
|
2
3
|
|
3
4
|
module RBlade
|
@@ -80,7 +81,7 @@ module RBlade
|
|
80
81
|
return nil
|
81
82
|
end
|
82
83
|
|
83
|
-
arguments =
|
84
|
+
arguments = Tokenizer.extractCommaSeparatedValues segments[segment_index][1..-2]
|
84
85
|
segments.delete_at segment_index
|
85
86
|
|
86
87
|
arguments
|
@@ -110,62 +111,5 @@ module RBlade
|
|
110
111
|
|
111
112
|
parentheses_difference.zero?
|
112
113
|
end
|
113
|
-
|
114
|
-
def extractArguments(segment)
|
115
|
-
# Add a comma to the end to delimit the end of the last argument
|
116
|
-
segment = segment[1..-2] + ","
|
117
|
-
segment_lines = segment.lines
|
118
|
-
|
119
|
-
tokens = Ripper.lex segment
|
120
|
-
arguments = []
|
121
|
-
|
122
|
-
current_line = 1
|
123
|
-
current_index = 0
|
124
|
-
bracket_count = {
|
125
|
-
"[]": 0,
|
126
|
-
"{}": 0,
|
127
|
-
"()": 0
|
128
|
-
}
|
129
|
-
tokens.each do |token|
|
130
|
-
case token[1]
|
131
|
-
when :on_lbracket
|
132
|
-
bracket_count[:[]] += 1
|
133
|
-
when :on_rbracket
|
134
|
-
bracket_count[:[]] -= 1
|
135
|
-
when :on_lbrace
|
136
|
-
bracket_count[:"{}"] += 1
|
137
|
-
when :on_rbrace
|
138
|
-
bracket_count[:"{}"] -= 1
|
139
|
-
when :on_lparen
|
140
|
-
bracket_count[:"()"] += 1
|
141
|
-
when :on_rparen
|
142
|
-
bracket_count[:"()"] -= 1
|
143
|
-
when :on_comma
|
144
|
-
if bracket_count[:[]] != 0 || bracket_count[:"{}"] != 0 || bracket_count[:"()"] != 0
|
145
|
-
next
|
146
|
-
end
|
147
|
-
|
148
|
-
argument = ""
|
149
|
-
|
150
|
-
# Concatenate all lines up to this token's line, including the tail end of the current line
|
151
|
-
if token[0][0] != current_line
|
152
|
-
(current_line...token[0][0]).each do |i|
|
153
|
-
argument << (segment_lines[i - 1].slice(current_index..-1) || "")
|
154
|
-
current_index = 0
|
155
|
-
end
|
156
|
-
current_line = token[0][0]
|
157
|
-
end
|
158
|
-
argument <<= segment_lines[current_line - 1].slice(current_index...token[0][1])
|
159
|
-
|
160
|
-
arguments.push argument.strip
|
161
|
-
|
162
|
-
current_index = token[0][1] + 1
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
return nil if arguments.count == 1 && arguments.first == ""
|
167
|
-
|
168
|
-
arguments
|
169
|
-
end
|
170
114
|
end
|
171
115
|
end
|
data/lib/rblade/compiler.rb
CHANGED
@@ -22,11 +22,11 @@ module RBlade
|
|
22
22
|
def self.compileString(string_template)
|
23
23
|
tokens = [Token.new(:unprocessed, string_template)]
|
24
24
|
|
25
|
-
CompilesComments.new.compile! tokens
|
26
|
-
CompilesEchos.new.compile! tokens
|
27
25
|
CompilesRuby.new.compile! tokens
|
28
26
|
TokenizesComponents.new.tokenize! tokens
|
29
27
|
TokenizesStatements.new.tokenize! tokens
|
28
|
+
CompilesComments.new.compile! tokens
|
29
|
+
CompilesEchos.new.compile! tokens
|
30
30
|
CompilesStatements.new.compile! tokens
|
31
31
|
CompilesComponents.new.compile! tokens
|
32
32
|
|
@@ -8,13 +8,13 @@ module RBlade
|
|
8
8
|
namespace = nil
|
9
9
|
path = name
|
10
10
|
|
11
|
-
if name.match
|
12
|
-
namespace, path = name.split(
|
11
|
+
if name.match? "::"
|
12
|
+
namespace, path = name.split("::")
|
13
13
|
end
|
14
14
|
|
15
|
-
path.
|
15
|
+
path.tr! ".", "/"
|
16
16
|
|
17
|
-
@@
|
17
|
+
@@template_paths[namespace]&.each do |base_path|
|
18
18
|
FILE_EXTENSIONS.each do |extension|
|
19
19
|
if File.exist? base_path + path + extension
|
20
20
|
return RBlade::Compiler.compileString File.read(base_path + path + extension)
|
@@ -28,15 +28,15 @@ module RBlade
|
|
28
28
|
def self.add_path path, namespace = nil
|
29
29
|
path = path.to_s
|
30
30
|
if !path.end_with? "/"
|
31
|
-
path
|
31
|
+
path += "/"
|
32
32
|
end
|
33
33
|
|
34
|
-
@@
|
35
|
-
@@
|
34
|
+
@@template_paths[namespace] ||= []
|
35
|
+
@@template_paths[namespace] << path
|
36
36
|
end
|
37
37
|
|
38
38
|
private
|
39
39
|
|
40
|
-
@@
|
40
|
+
@@template_paths = {}
|
41
41
|
end
|
42
42
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module RBlade
|
2
|
+
class AttributesManager
|
3
|
+
@attributes = {}
|
4
|
+
def initialize attributes
|
5
|
+
@attributes = attributes
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_h
|
9
|
+
@attributes
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s attributes = nil
|
13
|
+
attributes ||= @attributes
|
14
|
+
|
15
|
+
attributes.map do |key, value|
|
16
|
+
"#{key}=\"#{h(value)}\""
|
17
|
+
end.join " "
|
18
|
+
end
|
19
|
+
|
20
|
+
def only(keys)
|
21
|
+
keys = if keys.is_a? Array
|
22
|
+
keys.map(&:to_sym)
|
23
|
+
else
|
24
|
+
[keys.to_sym]
|
25
|
+
end
|
26
|
+
|
27
|
+
self.class.new @attributes.slice(*keys)
|
28
|
+
end
|
29
|
+
|
30
|
+
def except(keys)
|
31
|
+
keys = if keys.is_a? Array
|
32
|
+
keys.map(&:to_sym)
|
33
|
+
else
|
34
|
+
[keys.to_sym]
|
35
|
+
end
|
36
|
+
|
37
|
+
self.class.new @attributes.except(*keys)
|
38
|
+
end
|
39
|
+
|
40
|
+
def merge(default_attributes)
|
41
|
+
new_attributes = default_attributes
|
42
|
+
|
43
|
+
@attributes.each do |key, value|
|
44
|
+
if key == :class && !new_attributes[key].nil?
|
45
|
+
unless new_attributes[key].end_with? " "
|
46
|
+
new_attributes[key] << " "
|
47
|
+
end
|
48
|
+
new_attributes[key] << value.to_s
|
49
|
+
next
|
50
|
+
end
|
51
|
+
|
52
|
+
if key == :style && !new_attributes[key].nil?
|
53
|
+
unless new_attributes[key].end_with? ";"
|
54
|
+
new_attributes[key] << ";"
|
55
|
+
end
|
56
|
+
new_attributes[key] << value.to_s
|
57
|
+
next
|
58
|
+
end
|
59
|
+
|
60
|
+
new_attributes[key] = value
|
61
|
+
end
|
62
|
+
|
63
|
+
self.class.new new_attributes
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module RBlade
|
2
|
+
class ClassManager
|
3
|
+
def initialize classes
|
4
|
+
if classes.is_a? String
|
5
|
+
@classes = classes
|
6
|
+
elsif classes.is_a? Array
|
7
|
+
@classes = classes.join " "
|
8
|
+
elsif classes.is_a? Hash
|
9
|
+
@classes = ""
|
10
|
+
classes.map do |value, predicate|
|
11
|
+
if predicate
|
12
|
+
@classes << "#{value} "
|
13
|
+
end
|
14
|
+
end
|
15
|
+
@classes.rstrip!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
@classes
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module RBlade
|
2
|
+
class StyleManager
|
3
|
+
def initialize styles
|
4
|
+
if styles.is_a? String
|
5
|
+
@styles = styles.strip
|
6
|
+
unless @styles == "" || @styles.end_with?(";")
|
7
|
+
@styles << ";"
|
8
|
+
end
|
9
|
+
elsif styles.is_a? Array
|
10
|
+
@styles = styles.map do |style|
|
11
|
+
style = style.strip
|
12
|
+
unless style.end_with? ";"
|
13
|
+
style << ";"
|
14
|
+
end
|
15
|
+
|
16
|
+
style
|
17
|
+
end.join
|
18
|
+
elsif styles.is_a? Hash
|
19
|
+
@styles = ""
|
20
|
+
styles.each do |value, predicate|
|
21
|
+
if predicate
|
22
|
+
value = value.to_s.strip
|
23
|
+
unless value.end_with? ";"
|
24
|
+
value << ";"
|
25
|
+
end
|
26
|
+
|
27
|
+
@styles << value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
@styles
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module RBlade
|
2
|
+
class Tokenizer
|
3
|
+
def self.extractCommaSeparatedValues segment
|
4
|
+
unless segment.match?(/,\s*\z/)
|
5
|
+
# Add a comma to the end to delimit the end of the last argument
|
6
|
+
segment += ","
|
7
|
+
end
|
8
|
+
segment_lines = segment.lines
|
9
|
+
|
10
|
+
tokens = Ripper.lex segment
|
11
|
+
arguments = []
|
12
|
+
|
13
|
+
current_line = 1
|
14
|
+
current_index = 0
|
15
|
+
bracket_count = {
|
16
|
+
"[]": 0,
|
17
|
+
"{}": 0,
|
18
|
+
"()": 0
|
19
|
+
}
|
20
|
+
tokens.each do |token|
|
21
|
+
case token[1]
|
22
|
+
when :on_lbracket
|
23
|
+
bracket_count[:[]] += 1
|
24
|
+
when :on_rbracket
|
25
|
+
bracket_count[:[]] -= 1
|
26
|
+
when :on_lbrace
|
27
|
+
bracket_count[:"{}"] += 1
|
28
|
+
when :on_rbrace
|
29
|
+
bracket_count[:"{}"] -= 1
|
30
|
+
when :on_lparen
|
31
|
+
bracket_count[:"()"] += 1
|
32
|
+
when :on_rparen
|
33
|
+
bracket_count[:"()"] -= 1
|
34
|
+
when :on_comma
|
35
|
+
if bracket_count[:[]] != 0 || bracket_count[:"{}"] != 0 || bracket_count[:"()"] != 0
|
36
|
+
next
|
37
|
+
end
|
38
|
+
|
39
|
+
argument = ""
|
40
|
+
|
41
|
+
# Concatenate all lines up to this token's line, including the tail end of the current line
|
42
|
+
if token[0][0] != current_line
|
43
|
+
(current_line...token[0][0]).each do |i|
|
44
|
+
argument << (segment_lines[i - 1].slice(current_index..-1) || "")
|
45
|
+
current_index = 0
|
46
|
+
end
|
47
|
+
current_line = token[0][0]
|
48
|
+
end
|
49
|
+
argument <<= segment_lines[current_line - 1].slice(current_index...token[0][1])
|
50
|
+
argument.strip!
|
51
|
+
|
52
|
+
arguments.push argument
|
53
|
+
|
54
|
+
current_index = token[0][1] + 1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
return nil if arguments.count == 1 && arguments.first == ""
|
59
|
+
|
60
|
+
arguments
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -1,12 +1,15 @@
|
|
1
1
|
require "rails"
|
2
2
|
require "rblade/compiler"
|
3
|
+
require "rblade/helpers/attributes_manager"
|
4
|
+
require "rblade/helpers/class_manager"
|
3
5
|
require "rblade/helpers/stack_manager"
|
6
|
+
require "rblade/helpers/style_manager"
|
4
7
|
|
5
8
|
module RBlade
|
6
9
|
class RailsTemplate
|
7
10
|
def call(template, source = nil)
|
8
11
|
RBlade::StackManager.clear
|
9
|
-
setup = "
|
12
|
+
setup = "_out='';_stacks=[];"
|
10
13
|
setdown = "RBlade::StackManager.get(_stacks) + _out"
|
11
14
|
setup + RBlade::Compiler.compileString(source || template.source) + setdown
|
12
15
|
end
|
data/rblade.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "rblade"
|
3
|
-
s.version = "0.1
|
3
|
+
s.version = "0.2.1"
|
4
4
|
s.summary = "Blade templates for ruby"
|
5
5
|
s.description = "A port of the Laravel blade templating engine to ruby"
|
6
6
|
s.authors = ["Simon J"]
|
7
7
|
s.email = "2857218+mwnciau@users.noreply.github.com"
|
8
8
|
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|storage)/}) }
|
9
|
-
s.require_paths = [
|
9
|
+
s.require_paths = ["lib"]
|
10
10
|
s.homepage = "https://rubygems.org/gems/rblade"
|
11
11
|
s.license = "MIT"
|
12
12
|
s.required_ruby_version = ">= 3.0.0"
|
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.1
|
4
|
+
version: 0.2.1
|
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-07-
|
11
|
+
date: 2024-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -74,6 +74,7 @@ extra_rdoc_files: []
|
|
74
74
|
files:
|
75
75
|
- ".gitignore"
|
76
76
|
- ".standard.yml"
|
77
|
+
- CHANGELOG.md
|
77
78
|
- Gemfile
|
78
79
|
- Rakefile
|
79
80
|
- do
|
@@ -88,11 +89,16 @@ files:
|
|
88
89
|
- lib/rblade/compiler/statements/compiles_conditionals.rb
|
89
90
|
- lib/rblade/compiler/statements/compiles_inline_ruby.rb
|
90
91
|
- lib/rblade/compiler/statements/compiles_loops.rb
|
92
|
+
- lib/rblade/compiler/statements/compiles_props.rb
|
91
93
|
- lib/rblade/compiler/statements/compiles_stacks.rb
|
92
94
|
- lib/rblade/compiler/tokenizes_components.rb
|
93
95
|
- lib/rblade/compiler/tokenizes_statements.rb
|
94
96
|
- lib/rblade/component_store.rb
|
97
|
+
- lib/rblade/helpers/attributes_manager.rb
|
98
|
+
- lib/rblade/helpers/class_manager.rb
|
95
99
|
- lib/rblade/helpers/stack_manager.rb
|
100
|
+
- lib/rblade/helpers/style_manager.rb
|
101
|
+
- lib/rblade/helpers/tokenizer.rb
|
96
102
|
- lib/rblade/rails_template.rb
|
97
103
|
- lib/rblade/railtie.rb
|
98
104
|
- rblade.gemspec
|