rblade 1.2.1 → 2.0.1
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/.github/workflows/ruby.yml +2 -5
- data/CHANGELOG.md +14 -0
- data/README.md +1 -1
- data/docker-compose.yml +1 -1
- data/lib/rblade/compiler/compiles_components.rb +30 -39
- data/lib/rblade/compiler/compiles_prints.rb +18 -16
- data/lib/rblade/compiler/compiles_ruby.rb +1 -7
- data/lib/rblade/compiler/compiles_statements.rb +2 -8
- data/lib/rblade/compiler/statements/compiles_component_helpers.rb +5 -5
- data/lib/rblade/compiler/statements/compiles_conditionals.rb +23 -23
- data/lib/rblade/compiler/statements/compiles_form.rb +7 -7
- data/lib/rblade/compiler/statements/compiles_html_attributes.rb +4 -4
- data/lib/rblade/compiler/statements/compiles_inline_ruby.rb +1 -1
- data/lib/rblade/compiler/statements/compiles_loops.rb +15 -15
- data/lib/rblade/compiler/statements/compiles_once.rb +6 -24
- data/lib/rblade/compiler/statements/compiles_stacks.rb +10 -54
- data/lib/rblade/compiler/tokenizes_components.rb +21 -11
- data/lib/rblade/compiler/tokenizes_statements.rb +10 -4
- data/lib/rblade/compiler.rb +23 -14
- data/lib/rblade/component_store.rb +35 -35
- data/lib/rblade/helpers/attributes_manager.rb +11 -9
- data/lib/rblade/helpers/slot_manager.rb +7 -4
- data/lib/rblade/helpers/stack_manager.rb +18 -18
- data/lib/rblade/rails_template.rb +4 -9
- data/rblade.gemspec +3 -3
- metadata +6 -7
- data/lib/rblade/helpers/html_string.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b9e312234e0d768294bf551d6b25f78799140484ab8d48ec5ef2f44114665ca
|
4
|
+
data.tar.gz: 86d2bc460163f6e3dd15bd67856b73d2e75c61f6da1725d14bdc6e6342b83304
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9df38b9f1bfdceaba790fd422c0a3bd84d687616723f8907ef19a1631f9d241444830090480790d402d929f52edd9274ea6169ddad6119ae4cee570a8a16776b
|
7
|
+
data.tar.gz: fd351ab727e76e5ee20bccd7b8335966c9ca26f2bcb7fe60a26be5f618b1e12cbfb5588d0904113e05bed677c5abfa6dee70f7775610c0b6e30c9956783fc008
|
data/.github/workflows/ruby.yml
CHANGED
@@ -22,15 +22,12 @@ jobs:
|
|
22
22
|
runs-on: ubuntu-latest
|
23
23
|
strategy:
|
24
24
|
matrix:
|
25
|
-
ruby-version: ['3.2']
|
25
|
+
ruby-version: ['3.2.2']
|
26
26
|
|
27
27
|
steps:
|
28
28
|
- uses: actions/checkout@v4
|
29
29
|
- name: Set up Ruby
|
30
|
-
|
31
|
-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
32
|
-
# uses: ruby/setup-ruby@v1
|
33
|
-
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
|
30
|
+
uses: ruby/setup-ruby@v1
|
34
31
|
with:
|
35
32
|
ruby-version: ${{ matrix.ruby-version }}
|
36
33
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## 2.0.1 [2025-03-10]
|
2
|
+
- Fix broken gem build
|
3
|
+
|
4
|
+
## 2.0.0 [2025-03-09]
|
5
|
+
- Add check for unclosed tags
|
6
|
+
- Add string interpolation for component attributes
|
7
|
+
- Improve runtime performance
|
8
|
+
- Switch to using @output_buffer for full ERB compatibility
|
9
|
+
- Update dependencies
|
10
|
+
- Fix issue with "end" inside multi-line print blocks
|
11
|
+
- Fix frozen string literal warnings
|
12
|
+
- Fix redundant unfreezing of interpolated string
|
13
|
+
- Fix whitespace being removed for non-statements
|
14
|
+
|
1
15
|
## 1.2.1 [2024-10-31]
|
2
16
|
- Fix issue with @props directive when defining multiple properties without braces
|
3
17
|
|
data/README.md
CHANGED
@@ -105,7 +105,7 @@ Hello, {!! @name !!}.
|
|
105
105
|
|
106
106
|
For the most part, RBlade templates are backwards compatible with the built in ERB templates. Anything that works in an ERB template should also work in an RBlade template.
|
107
107
|
|
108
|
-
This includes helper methods, path helpers and methods from third party gems such as `simple_forms` or `vite-ruby`. It additionally includes the ERB syntax for outputting data, `<%= ... %>`, and running ruby code,
|
108
|
+
This includes helper methods, path helpers and methods from third party gems such as `simple_forms` or `vite-ruby`. It additionally includes the ERB syntax for outputting data, `<%= ... %>`, and running ruby code, `<% ... %>`.
|
109
109
|
|
110
110
|
<a name="rblade-and-javascript-frameworks"></a>
|
111
111
|
### RBlade and JavaScript Frameworks
|
data/docker-compose.yml
CHANGED
@@ -4,9 +4,10 @@ require "rblade/component_store"
|
|
4
4
|
|
5
5
|
module RBlade
|
6
6
|
class CompilesComponents
|
7
|
-
def initialize
|
7
|
+
def initialize(component_store)
|
8
8
|
@component_count = 0
|
9
9
|
@component_stack = []
|
10
|
+
@component_store = component_store
|
10
11
|
end
|
11
12
|
|
12
13
|
def compile!(tokens)
|
@@ -25,60 +26,40 @@ module RBlade
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
29
|
+
def ensure_all_tags_closed
|
30
|
+
unless @component_stack.empty?
|
31
|
+
raise RBladeTemplateError.new("Unexpected end of document. Expecting </x-#{@component_stack.last[:name]}>")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
28
35
|
private
|
29
36
|
|
30
37
|
def compile_token_start token
|
31
38
|
component = {
|
32
|
-
name: token.value[:name]
|
33
|
-
index: @component_stack.count
|
39
|
+
name: token.value[:name]
|
34
40
|
}
|
35
41
|
@component_stack << component
|
36
42
|
|
37
43
|
attributes = compile_attributes token.value[:attributes]
|
38
44
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
if component[:name].start_with? "slot::"
|
46
|
+
"_slot.call(:'#{RBlade.escape_quotes(component[:name].delete_prefix("slot::"))}', {#{attributes.join(",")}}) do;"
|
47
|
+
else
|
48
|
+
"#{@component_store.component(component[:name])}(RBlade::AttributesManager.new({#{attributes.join(",")}})) do |_slot|;"
|
49
|
+
end
|
43
50
|
end
|
44
51
|
|
45
52
|
def compile_token_end token
|
46
53
|
component = @component_stack.pop
|
47
54
|
if component.nil?
|
48
|
-
raise
|
49
|
-
end
|
50
|
-
if token.type == :component_end && token.value[:name] != component[:name]
|
51
|
-
raise StandardError.new "Unexpected closing tag (#{token.value[:name]}) expecting #{component[:name]}"
|
55
|
+
raise RBladeTemplateError.new "Unexpected closing tag </x-#{token.value[:name]}>"
|
52
56
|
end
|
53
57
|
|
54
|
-
|
55
|
-
|
56
|
-
if name.match? "::"
|
57
|
-
namespace, name = component[:name].split("::")
|
58
|
-
end
|
59
|
-
|
60
|
-
if namespace == "slot"
|
61
|
-
compile_slot_end name, component
|
62
|
-
else
|
63
|
-
compile_component_end component
|
58
|
+
if token.type == :component_end && token.value[:name] != component[:name]
|
59
|
+
raise RBladeTemplateError.new "Unexpected closing tag </x-#{token.value[:name]}>, expecting </x-#{component[:name]}>"
|
64
60
|
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def compile_slot_end name, component
|
68
|
-
parent = @component_stack.last
|
69
61
|
|
70
|
-
|
71
|
-
code << "_out=_c#{component[:index]}_swap;_c#{component[:index]}_swap=nil;_c#{component[:index]}_attr=nil;"
|
72
|
-
|
73
|
-
code
|
74
|
-
end
|
75
|
-
|
76
|
-
def compile_component_end component
|
77
|
-
code = +"_slot=RBlade::SlotManager.new(_out);_out=_c#{component[:index]}_swap;"
|
78
|
-
code << "_out<<#{ComponentStore.component(component[:name])}(_slot,_c#{component[:index]}_attr,params,session,flash,cookies);"
|
79
|
-
code << "_slot=nil;_c#{component[:index]}_swap=nil;_c#{component[:index]}_attr=nil;"
|
80
|
-
|
81
|
-
code
|
62
|
+
"end;"
|
82
63
|
end
|
83
64
|
|
84
65
|
def compile_attributes attributes
|
@@ -91,7 +72,7 @@ module RBlade
|
|
91
72
|
when "attributes"
|
92
73
|
"**(#{attribute[:value]})"
|
93
74
|
when "string"
|
94
|
-
"'#{attribute[:name]}':
|
75
|
+
"'#{attribute[:name]}': #{process_string_attribute(attribute[:value])}"
|
95
76
|
when "ruby"
|
96
77
|
"'#{attribute[:name]}': (#{attribute[:value]})"
|
97
78
|
when "pass_through"
|
@@ -99,9 +80,19 @@ module RBlade
|
|
99
80
|
when "empty"
|
100
81
|
"'#{attribute[:name]}': true"
|
101
82
|
else
|
102
|
-
raise
|
83
|
+
raise RBladeTemplateError.new "Component compiler: unexpected attribute type (#{attribute[:type]})"
|
103
84
|
end
|
104
85
|
end
|
105
86
|
end
|
87
|
+
|
88
|
+
def process_string_attribute(string)
|
89
|
+
string.split(/((?<!@)\{\{.*?\}\})/).map do |substring|
|
90
|
+
if substring.start_with?("{{") && substring.end_with?("}}")
|
91
|
+
"(#{substring[2..-3]}).to_s"
|
92
|
+
else
|
93
|
+
"'#{RBlade.escape_quotes(substring.gsub(/@\{\{/, "{{"))}'"
|
94
|
+
end
|
95
|
+
end.join("<<").prepend("+")
|
96
|
+
end
|
106
97
|
end
|
107
98
|
end
|
@@ -10,8 +10,8 @@ module RBlade
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def compile_regular_prints!(tokens)
|
13
|
-
compile_prints! tokens, "{{", "}}",
|
14
|
-
compile_prints! tokens, "<%=", "%>",
|
13
|
+
compile_prints! tokens, "{{", "}}", true
|
14
|
+
compile_prints! tokens, "<%=", "%>", true
|
15
15
|
end
|
16
16
|
|
17
17
|
def compile_unsafe_prints!(tokens)
|
@@ -19,7 +19,7 @@ module RBlade
|
|
19
19
|
compile_prints! tokens, "<%==", "%>"
|
20
20
|
end
|
21
21
|
|
22
|
-
def compile_prints!(tokens, start_token, end_token,
|
22
|
+
def compile_prints!(tokens, start_token, end_token, escape_html = false)
|
23
23
|
tokens.map! do |token|
|
24
24
|
next(token) if token.type != :unprocessed
|
25
25
|
|
@@ -38,7 +38,7 @@ module RBlade
|
|
38
38
|
segments.delete_at i
|
39
39
|
segments.delete_at i + 1
|
40
40
|
|
41
|
-
segments[i] = create_token(segments[i],
|
41
|
+
segments[i] = create_token(segments[i], escape_html)
|
42
42
|
|
43
43
|
i += 1
|
44
44
|
elsif !segments[i].nil? && segments[i] != ""
|
@@ -54,25 +54,27 @@ module RBlade
|
|
54
54
|
end.flatten!
|
55
55
|
end
|
56
56
|
|
57
|
-
def create_token
|
58
|
-
|
59
|
-
|
57
|
+
def create_token(expression, escape_html)
|
58
|
+
# Don't try to print ends
|
59
|
+
if expression.match?(/\A\s*(?:}|end(?![[:alnum:]_]|[^\0-\177]))/i)
|
60
|
+
return Token.new(:print, "#{expression};")
|
61
|
+
end
|
62
|
+
|
63
|
+
segment_value = if escape_html
|
64
|
+
"@output_buffer.append=#{expression};"
|
65
|
+
# If this is a block, don't wrap in parentheses
|
66
|
+
elsif expression.match?(/
|
67
|
+
(?:\{|do)\s*
|
60
68
|
(
|
61
69
|
\|\s*
|
62
70
|
[a-zA-Z0-9_]+\s*
|
63
71
|
(,\s*[a-zA-Z0-9_]+)?\s*
|
64
72
|
\|\s*
|
65
73
|
)?
|
66
|
-
|
67
|
-
|
68
|
-
elsif expression.match?(/^\s*end(?![a-zA-Z0-9_])/i)
|
69
|
-
return Token.new(:print, "_out;#{expression};")
|
70
|
-
end
|
71
|
-
|
72
|
-
segment_value = if !wrapper_function.nil?
|
73
|
-
"_out<<#{wrapper_function}(#{expression});"
|
74
|
+
\Z/x)
|
75
|
+
"@output_buffer.safe_expr_append=#{expression};"
|
74
76
|
else
|
75
|
-
"
|
77
|
+
"@output_buffer.raw_buffer<<(#{expression}).to_s;"
|
76
78
|
end
|
77
79
|
|
78
80
|
Token.new(:print, segment_value)
|
@@ -40,13 +40,7 @@ module RBlade
|
|
40
40
|
segments[i] << ";"
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
# See also ./compiles_prints.rb
|
45
|
-
segments[i] = if segments[i].match?(/^end(?![a-zA-Z0-9_])/i)
|
46
|
-
Token.new(type: :ruby, value: "_out;#{segments[i]}")
|
47
|
-
else
|
48
|
-
Token.new(type: :ruby, value: segments[i])
|
49
|
-
end
|
43
|
+
segments[i] = Token.new(type: :ruby, value: segments[i])
|
50
44
|
|
51
45
|
i += 1
|
52
46
|
elsif !segments[i].nil? && segments[i] != ""
|
@@ -38,7 +38,7 @@ module RBlade
|
|
38
38
|
end
|
39
39
|
|
40
40
|
token.value = if handler.is_a? Proc
|
41
|
-
"
|
41
|
+
"@output_buffer.raw_buffer<<-'#{RBlade.escape_quotes(handler.call(*handler_arguments).to_s)}';"
|
42
42
|
else
|
43
43
|
handler.call(*handler_arguments)
|
44
44
|
end
|
@@ -73,7 +73,7 @@ module RBlade
|
|
73
73
|
## Fallback to the default end handler
|
74
74
|
handler_class, handler_method = @@statement_handlers["end"]
|
75
75
|
else
|
76
|
-
raise
|
76
|
+
raise RBladeTemplateError.new "Unhandled statement: @#{name}"
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -106,12 +106,6 @@ module RBlade
|
|
106
106
|
"empty" => [CompilesLoops, :compileEmpty],
|
107
107
|
"empty?" => [CompilesConditionals, :compileEmpty],
|
108
108
|
"end" => [CompilesStatements, :compileEnd],
|
109
|
-
"endprepend" => [CompilesStacks, :compileEndPrepend],
|
110
|
-
"endprependif" => [CompilesStacks, :compileEndPrependIf],
|
111
|
-
"endprependonce" => [CompilesOnce, :compileEndPrependOnce],
|
112
|
-
"endpush" => [CompilesStacks, :compileEndPush],
|
113
|
-
"endpushif" => [CompilesStacks, :compileEndPushIf],
|
114
|
-
"endpushonce" => [CompilesOnce, :compileEndPushOnce],
|
115
109
|
"env" => [CompilesConditionals, :compileEnv],
|
116
110
|
"for" => [CompilesLoops, :compileFor],
|
117
111
|
"forelse" => [CompilesLoops, :compileForElse],
|
@@ -7,7 +7,7 @@ module RBlade
|
|
7
7
|
class CompilesComponentHelpers
|
8
8
|
def compileShouldRender args
|
9
9
|
if args&.count != 1
|
10
|
-
raise
|
10
|
+
raise RBladeTemplateError.new "Should render statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
11
11
|
end
|
12
12
|
|
13
13
|
"unless(#{args[0]});return'';end;"
|
@@ -43,7 +43,7 @@ module RBlade
|
|
43
43
|
prop_strings.each do |prop|
|
44
44
|
prop.strip!
|
45
45
|
|
46
|
-
key, value = prop.split(
|
46
|
+
key, value = prop.split(/\A
|
47
47
|
(?:
|
48
48
|
'(.+)':
|
49
49
|
|
|
@@ -63,7 +63,7 @@ module RBlade
|
|
63
63
|
/x).reject(&:empty?)
|
64
64
|
|
65
65
|
if key.nil? || value.nil?
|
66
|
-
raise
|
66
|
+
raise RBladeTemplateError.new "Props statement: invalid property hash"
|
67
67
|
end
|
68
68
|
props[key] = value
|
69
69
|
end
|
@@ -74,7 +74,7 @@ module RBlade
|
|
74
74
|
RUBY_RESERVED_KEYWORDS = %w[__FILE__ __LINE__ alias and begin BEGIN break case class def defined? do else elsif end END ensure false for if in module next nil not or redo rescue retry return self super then true undef unless until when while yield].freeze
|
75
75
|
|
76
76
|
def isValidVariableName key
|
77
|
-
return false unless key.match?(
|
77
|
+
return false unless key.match?(/\A[a-zA-Z_][a-zA-Z0-9_]*\Z/)
|
78
78
|
|
79
79
|
return false if RUBY_RESERVED_KEYWORDS.include? key
|
80
80
|
|
@@ -83,7 +83,7 @@ module RBlade
|
|
83
83
|
|
84
84
|
# Automatically detect if a variable is a slot by looking for "<var>.attributes"
|
85
85
|
def variableIsSlot name, tokens
|
86
|
-
tokens.any? { |token| token.value.to_s.match "#{name}.attributes" }
|
86
|
+
tokens.any? { |token| token.value.to_s.match? "#{name}.attributes" }
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
@@ -5,7 +5,7 @@ module RBlade
|
|
5
5
|
class CompilesConditionals
|
6
6
|
def compileIf args
|
7
7
|
if args&.count != 1
|
8
|
-
raise
|
8
|
+
raise RBladeTemplateError.new "If statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
9
9
|
end
|
10
10
|
|
11
11
|
"if #{args[0]};"
|
@@ -13,7 +13,7 @@ module RBlade
|
|
13
13
|
|
14
14
|
def compileBlank args
|
15
15
|
if args&.count != 1
|
16
|
-
raise
|
16
|
+
raise RBladeTemplateError.new "Blank? statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
17
17
|
end
|
18
18
|
|
19
19
|
"if (#{args[0]}).blank?;"
|
@@ -21,7 +21,7 @@ module RBlade
|
|
21
21
|
|
22
22
|
def compileDefined args
|
23
23
|
if args&.count != 1
|
24
|
-
raise
|
24
|
+
raise RBladeTemplateError.new "Defined? statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
25
25
|
end
|
26
26
|
|
27
27
|
"if defined? #{args[0]};"
|
@@ -29,7 +29,7 @@ module RBlade
|
|
29
29
|
|
30
30
|
def compileEmpty args
|
31
31
|
if args&.count != 1
|
32
|
-
raise
|
32
|
+
raise RBladeTemplateError.new "Empty? statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
33
33
|
end
|
34
34
|
|
35
35
|
"if (#{args[0]}).empty?;"
|
@@ -37,7 +37,7 @@ module RBlade
|
|
37
37
|
|
38
38
|
def compileNil args
|
39
39
|
if args&.count != 1
|
40
|
-
raise
|
40
|
+
raise RBladeTemplateError.new "Nil? statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
41
41
|
end
|
42
42
|
|
43
43
|
"if (#{args[0]}).nil?;"
|
@@ -45,7 +45,7 @@ module RBlade
|
|
45
45
|
|
46
46
|
def compilePresent args
|
47
47
|
if args&.count != 1
|
48
|
-
raise
|
48
|
+
raise RBladeTemplateError.new "Present? statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
49
49
|
end
|
50
50
|
|
51
51
|
"if (#{args[0]}).present?;"
|
@@ -53,7 +53,7 @@ module RBlade
|
|
53
53
|
|
54
54
|
def compileElsif args
|
55
55
|
if args&.count != 1
|
56
|
-
raise
|
56
|
+
raise RBladeTemplateError.new "Elsif statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
57
57
|
end
|
58
58
|
|
59
59
|
"elsif #{args[0]};"
|
@@ -61,7 +61,7 @@ module RBlade
|
|
61
61
|
|
62
62
|
def compileElse args
|
63
63
|
unless args.nil?
|
64
|
-
raise
|
64
|
+
raise RBladeTemplateError.new "Else statement: wrong number of arguments (given #{args.count}, expecting 0)"
|
65
65
|
end
|
66
66
|
|
67
67
|
"else;"
|
@@ -69,7 +69,7 @@ module RBlade
|
|
69
69
|
|
70
70
|
def compileUnless args
|
71
71
|
if args&.count != 1
|
72
|
-
raise
|
72
|
+
raise RBladeTemplateError.new "Unless statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
73
73
|
end
|
74
74
|
|
75
75
|
"unless #{args[0]};"
|
@@ -77,7 +77,7 @@ module RBlade
|
|
77
77
|
|
78
78
|
def compileCase args
|
79
79
|
if args&.count != 1
|
80
|
-
raise
|
80
|
+
raise RBladeTemplateError.new "Case statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
81
81
|
end
|
82
82
|
|
83
83
|
"case #{args[0]};"
|
@@ -85,7 +85,7 @@ module RBlade
|
|
85
85
|
|
86
86
|
def compileWhen args
|
87
87
|
if args.nil?
|
88
|
-
raise
|
88
|
+
raise RBladeTemplateError.new "When statement: wrong number of arguments (given 0, expecting at least 1)"
|
89
89
|
end
|
90
90
|
|
91
91
|
"when #{args.join ","};"
|
@@ -93,47 +93,47 @@ module RBlade
|
|
93
93
|
|
94
94
|
def compileChecked args
|
95
95
|
if args&.count != 1
|
96
|
-
raise
|
96
|
+
raise RBladeTemplateError.new "Checked statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
97
97
|
end
|
98
98
|
|
99
|
-
"if #{args[0]}
|
99
|
+
"if #{args[0]};@output_buffer.raw_buffer<<-'checked';end;"
|
100
100
|
end
|
101
101
|
|
102
102
|
def compileDisabled args
|
103
103
|
if args&.count != 1
|
104
|
-
raise
|
104
|
+
raise RBladeTemplateError.new "Disabled statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
105
105
|
end
|
106
106
|
|
107
|
-
"if #{args[0]}
|
107
|
+
"if #{args[0]};@output_buffer.raw_buffer<<-'disabled';end;"
|
108
108
|
end
|
109
109
|
|
110
110
|
def compileReadonly args
|
111
111
|
if args&.count != 1
|
112
|
-
raise
|
112
|
+
raise RBladeTemplateError.new "Readonly statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
113
113
|
end
|
114
114
|
|
115
|
-
"if #{args[0]}
|
115
|
+
"if #{args[0]};@output_buffer.raw_buffer<<-'readonly';end;"
|
116
116
|
end
|
117
117
|
|
118
118
|
def compileRequired args
|
119
119
|
if args&.count != 1
|
120
|
-
raise
|
120
|
+
raise RBladeTemplateError.new "Required statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
121
121
|
end
|
122
122
|
|
123
|
-
"if #{args[0]}
|
123
|
+
"if #{args[0]};@output_buffer.raw_buffer<<-'required';end;"
|
124
124
|
end
|
125
125
|
|
126
126
|
def compileSelected args
|
127
127
|
if args&.count != 1
|
128
|
-
raise
|
128
|
+
raise RBladeTemplateError.new "Selected statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
129
129
|
end
|
130
130
|
|
131
|
-
"if #{args[0]}
|
131
|
+
"if #{args[0]};@output_buffer.raw_buffer<<-'selected';end;"
|
132
132
|
end
|
133
133
|
|
134
134
|
def compileEnv args
|
135
135
|
if args&.count != 1
|
136
|
-
raise
|
136
|
+
raise RBladeTemplateError.new "Env statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
137
137
|
end
|
138
138
|
|
139
139
|
environments = args[0].strip
|
@@ -143,7 +143,7 @@ module RBlade
|
|
143
143
|
|
144
144
|
def compileProduction args
|
145
145
|
unless args.nil?
|
146
|
-
raise
|
146
|
+
raise RBladeTemplateError.new "Production statement: wrong number of arguments (given #{args.count}, expecting 0)"
|
147
147
|
end
|
148
148
|
|
149
149
|
"if Rails.env.production?;"
|
@@ -5,15 +5,15 @@ module RBlade
|
|
5
5
|
class CompilesForm
|
6
6
|
def compileMethod args
|
7
7
|
if args&.count != 1
|
8
|
-
raise
|
8
|
+
raise RBladeTemplateError.new "Method statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
9
9
|
end
|
10
10
|
|
11
|
-
%(
|
11
|
+
%(@output_buffer.raw_buffer<<-"<input type=\\"hidden\\" name=\\"_method\\" value=\\"\#{#{args[0]}}\\">";)
|
12
12
|
end
|
13
13
|
|
14
14
|
def compileDelete args
|
15
15
|
unless args.nil?
|
16
|
-
raise
|
16
|
+
raise RBladeTemplateError.new "Delete statement: wrong number of arguments (given #{args.count}, expecting 0)"
|
17
17
|
end
|
18
18
|
|
19
19
|
compileMethod(["'DELETE'"])
|
@@ -21,7 +21,7 @@ module RBlade
|
|
21
21
|
|
22
22
|
def compilePatch args
|
23
23
|
unless args.nil?
|
24
|
-
raise
|
24
|
+
raise RBladeTemplateError.new "Patch statement: wrong number of arguments (given #{args.count}, expecting 0)"
|
25
25
|
end
|
26
26
|
|
27
27
|
compileMethod(["'PATCH'"])
|
@@ -29,7 +29,7 @@ module RBlade
|
|
29
29
|
|
30
30
|
def compilePut args
|
31
31
|
unless args.nil?
|
32
|
-
raise
|
32
|
+
raise RBladeTemplateError.new "Put statement: wrong number of arguments (given #{args.count}, expecting 0)"
|
33
33
|
end
|
34
34
|
|
35
35
|
compileMethod(["'PUT'"])
|
@@ -37,12 +37,12 @@ module RBlade
|
|
37
37
|
|
38
38
|
def compileOld args
|
39
39
|
if args.nil? || args.count > 2
|
40
|
-
raise
|
40
|
+
raise RBladeTemplateError.new "Old statement: wrong number of arguments (given #{args&.count || 0}, expecting 1 or 2)"
|
41
41
|
end
|
42
42
|
|
43
43
|
default_value = args[1] || "''"
|
44
44
|
|
45
|
-
"
|
45
|
+
"@output_buffer.raw_buffer<<params.fetch(#{args[0]},#{default_value});"
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -5,18 +5,18 @@ module RBlade
|
|
5
5
|
class CompilesHtmlAttributes
|
6
6
|
def compileClass args
|
7
7
|
if args&.count != 1
|
8
|
-
raise
|
8
|
+
raise RBladeTemplateError.new "Class statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
9
9
|
end
|
10
10
|
|
11
|
-
"
|
11
|
+
%`@output_buffer.raw_buffer<<-"class=\\"\#{RBlade::ClassManager.new(#{args[0]})}\\"";`
|
12
12
|
end
|
13
13
|
|
14
14
|
def compileStyle args
|
15
15
|
if args&.count != 1
|
16
|
-
raise
|
16
|
+
raise RBladeTemplateError.new "Style statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
17
17
|
end
|
18
18
|
|
19
|
-
"
|
19
|
+
%`@output_buffer.raw_buffer<<-"style=\\"\#{RBlade::StyleManager.new(#{args[0]})}\\"";`
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -5,7 +5,7 @@ module RBlade
|
|
5
5
|
class CompilesInlineRuby
|
6
6
|
def compile args
|
7
7
|
if args&.count != 1
|
8
|
-
raise
|
8
|
+
raise RBladeTemplateError.new "Ruby statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
|
9
9
|
end
|
10
10
|
|
11
11
|
arg = args[0].strip
|