rblade 1.2.1 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e633d7cbf716d70b0f9353e8d29990da0379f30171da143077c303e9557cdab8
4
- data.tar.gz: ad29e9a1b4cbb0f493a7fa6dbe6fcb82ec64c822fe1c7351de65ab8d268cd1aa
3
+ metadata.gz: fb23406b9206cc5eb7d20f10d700375c1b49c588c2805ae77710aff217ab39f1
4
+ data.tar.gz: '0330179c0e5113c74d0678c54fa08a489820f0d72ea21eb179caa372c7e54a42'
5
5
  SHA512:
6
- metadata.gz: 261023b42b8ad6d163c3ac24fcc5d844a5d85c2915af94f26c40254f7ff3cd03b847e2107c97219f32967c402df09594583856c327ee071d9ac56f992a4fd1e2
7
- data.tar.gz: 94e955703c7f041f6fc7e2dd5c40e143cb7779437ded8c4acbb5f7e81c0bc9cf424385093607c11a236560c83c389e201f1d1aa8a3f3e95de8aff3323921adf5
6
+ metadata.gz: c592ebfb01c89d56e996c1e0c7815e50ab2363a2d9badb41a8573067b230796807392789418b81593eecbacfa1160b34843ba6bce102f600acd5ea08ca9a2521
7
+ data.tar.gz: dcb59ca067167dbbe63a4ea86b2fce0d04e25beb4fe728826abc1e19f33613a6d3a472a36896f55bbc0c97979d1c265fa4be8b20e8c0ec62569218099bb62d1a
@@ -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
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
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,20 @@
1
+ ## 2.0.2 [2025-03-10]
2
+ - Fix issue with empty component attributes
3
+
4
+ ## 2.0.1 [2025-03-10]
5
+ - Fix broken gem build
6
+
7
+ ## 2.0.0 [2025-03-09]
8
+ - Add check for unclosed tags
9
+ - Add string interpolation for component attributes
10
+ - Improve runtime performance
11
+ - Switch to using @output_buffer for full ERB compatibility
12
+ - Update dependencies
13
+ - Fix issue with "end" inside multi-line print blocks
14
+ - Fix frozen string literal warnings
15
+ - Fix redundant unfreezing of interpolated string
16
+ - Fix whitespace being removed for non-statements
17
+
1
18
  ## 1.2.1 [2024-10-31]
2
19
  - Fix issue with @props directive when defining multiple properties without braces
3
20
 
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
@@ -1,6 +1,6 @@
1
1
  services:
2
2
  blade:
3
- image: ruby:3.3.4
3
+ image: ruby:3.4.2
4
4
  working_dir: /var/source
5
5
  volumes:
6
6
  - .:/var/source
@@ -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
- code = +"_c#{component[:index]}_swap=_out;_out=+'';"
40
- code << "_c#{component[:index]}_attr={#{attributes.join(",")}};"
41
-
42
- code
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 StandardError.new "Unexpected closing tag (#{token.value[:name]})"
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
- namespace = nil
55
- name = component[:name]
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
- code = +"_c#{parent[:index]}_attr[:'#{RBlade.escape_quotes(name)}']=RBlade::SlotManager.new(_out,_c#{component[:index]}_attr);"
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]}': '#{RBlade.escape_quotes(attribute[:value])}'"
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,21 @@ module RBlade
99
80
  when "empty"
100
81
  "'#{attribute[:name]}': true"
101
82
  else
102
- raise StandardError.new "Component compiler: unexpected attribute type (#{attribute[:type]})"
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
+ result = string.split(/((?<!@)\{\{.*?\}\})/).map do |substring|
90
+ if substring.start_with?("{{") && substring.end_with?("}}")
91
+ "(#{substring[2..-3]}).to_s"
92
+ elsif !substring.empty?
93
+ "'#{RBlade.escape_quotes(substring.gsub(/@\{\{/, "{{"))}'"
94
+ end
95
+ end.compact.join("<<")
96
+
97
+ result.empty? ? "+''" : result.prepend("+")
98
+ end
106
99
  end
107
100
  end
@@ -10,8 +10,8 @@ module RBlade
10
10
  private
11
11
 
12
12
  def compile_regular_prints!(tokens)
13
- compile_prints! tokens, "{{", "}}", +"RBlade.e"
14
- compile_prints! tokens, "<%=", "%>", +"RBlade.e"
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, wrapper_function = nil)
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], wrapper_function)
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 expression, wrapper_function
58
- if expression.match?(/
59
- do\s*
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
- $/x)
67
- return Token.new(:print, "_out+=#{expression};_out=+'';")
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
- "_out<<(#{expression}).to_s;"
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
- # Ensure _out is returned at the end of any blocks
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
- "_out<<'#{RBlade.escape_quotes(handler.call(*handler_arguments).to_s)}';"
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 StandardError.new "Unhandled statement: @#{name}"
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 StandardError.new "Should render statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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 StandardError.new "Props statement: invalid property hash"
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?(/^[a-zA-Z_][a-zA-Z0-9_]*$/)
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 StandardError.new "If statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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 StandardError.new "Blank? statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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 StandardError.new "Defined? statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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 StandardError.new "Empty? statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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 StandardError.new "Nil? statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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 StandardError.new "Present? statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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 StandardError.new "Elsif statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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 StandardError.new "Else statement: wrong number of arguments (given #{args.count}, expecting 0)"
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 StandardError.new "Unless statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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 StandardError.new "Case statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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 StandardError.new "When statement: wrong number of arguments (given 0, expecting at least 1)"
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 StandardError.new "Checked statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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]};_out<<'checked';end;"
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 StandardError.new "Disabled statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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]};_out<<'disabled';end;"
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 StandardError.new "Readonly statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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]};_out<<'readonly';end;"
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 StandardError.new "Required statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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]};_out<<'required';end;"
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 StandardError.new "Selected statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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]};_out<<'selected';end;"
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 StandardError.new "Env statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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 StandardError.new "Production statement: wrong number of arguments (given #{args.count}, expecting 0)"
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 StandardError.new "Method statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
8
+ raise RBladeTemplateError.new "Method statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
9
9
  end
10
10
 
11
- %(_out<<'<input type="hidden" name="_method" value="'<<#{args[0]}<<'">';)
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 StandardError.new "Delete statement: wrong number of arguments (given #{args.count}, expecting 0)"
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 StandardError.new "Patch statement: wrong number of arguments (given #{args.count}, expecting 0)"
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 StandardError.new "Put statement: wrong number of arguments (given #{args.count}, expecting 0)"
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 StandardError.new "Old statement: wrong number of arguments (given #{args&.count || 0}, expecting 1 or 2)"
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
- "_out<<params.fetch(#{args[0]},#{default_value});"
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 StandardError.new "Class statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
8
+ raise RBladeTemplateError.new "Class statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
9
9
  end
10
10
 
11
- "_out<<'class=\"'<<RBlade::ClassManager.new(#{args[0]})<<'\"';"
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 StandardError.new "Style statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
16
+ raise RBladeTemplateError.new "Style statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
17
17
  end
18
18
 
19
- "_out<<'style=\"'<<RBlade::StyleManager.new(#{args[0]})<<'\"';"
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 StandardError.new "Ruby statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
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