Class: RBlade::CompilesStatements
- Inherits:
-
Object
- Object
- RBlade::CompilesStatements
show all
- Defined in:
- lib/rblade/compiler/compiles_statements.rb,
lib/rblade/compiler/statements/compiles_form.rb,
lib/rblade/compiler/statements/compiles_once.rb,
lib/rblade/compiler/statements/compiles_loops.rb,
lib/rblade/compiler/statements/compiles_stacks.rb,
lib/rblade/compiler/statements/compiles_inline_ruby.rb,
lib/rblade/compiler/statements/compiles_conditionals.rb,
lib/rblade/compiler/statements/compiles_html_attributes.rb,
lib/rblade/compiler/statements/compiles_component_helpers.rb
Defined Under Namespace
Classes: CompilesComponentHelpers, CompilesConditionals, CompilesForm, CompilesHtmlAttributes, CompilesInlineRuby, CompilesLoops, CompilesOnce, CompilesStacks
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.has_handler(name) ⇒ Object
55
56
57
|
# File 'lib/rblade/compiler/compiles_statements.rb', line 55
def self.has_handler(name)
statement_handlers[name].present? || (name.start_with?("end") && name != "endruby")
end
|
.register_handler(name, &block) ⇒ Object
59
60
61
|
# File 'lib/rblade/compiler/compiles_statements.rb', line 59
def self.register_handler(name, &block)
statement_handlers[name.tr("_", "").downcase] = ["proc", block]
end
|
.register_raw_handler(name, &block) ⇒ Object
63
64
65
|
# File 'lib/rblade/compiler/compiles_statements.rb', line 63
def self.register_raw_handler(name, &block)
statement_handlers[name.tr("_", "").downcase] = ["raw_proc", block]
end
|
Instance Method Details
#compile!(tokens) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/rblade/compiler/compiles_statements.rb', line 14
def compile!(tokens)
token_index = 0
while token_index < tokens.count
token = tokens[token_index]
if token.type != :statement
token_index += 1
next
end
name = token.value[:name]
arguments = token.value[:arguments]
handler_class, handler = get_handler(name)
handler_arguments = []
handler.parameters.each do |parameter|
case parameter.last
when :args
handler_arguments.push arguments
when :tokens
handler_arguments.push tokens
when :token_index
handler_arguments.push token_index
else
handler_arguments.push nil
end
end
token.value = if handler_class == "proc"
"@output_buffer.raw_buffer<<-'#{RBlade.escape_quotes(handler.call(*handler_arguments).to_s)}';"
else
handler.call(*handler_arguments)
end
token_index += 1
end
end
|
#compile_end ⇒ Object
51
52
53
|
# File 'lib/rblade/compiler/compiles_statements.rb', line 51
def compile_end
"end;"
end
|