Module: TXP
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *args, &block) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/txprails.rb', line 52
def method_missing(method_id, *args, &block)
method_name = method_id.to_s
super if method_name !~ /^mod_/ && method_name !~ /^var_/
tag = args.first
output = []
case method_name
when /^mod_/
if @_current_models.empty? || @_current_var.nil?
variables = @view.controller.instance_variable_names
variables -= @view.controller.protected_instance_variables if @view.controller.respond_to?(:protected_instance_variables)
raise "Model not found" unless variables.include?("@#{tag.name}")
@_current_models.push(@view.controller.instance_variable_get("@#{tag.name}"))
else
raise "Model not found in current model" unless @_current_var.respond_to?(tag.name.to_sym)
@_current_models.push(@_current_var.send(tag.name.to_sym))
end
output << iterate_current_model(tag)
@_current_models.pop
when /^var/
unless @_current_var.nil?
output << @_current_var.send(tag.name.to_sym).to_s
else
output << "[UNDEFINED]"
end
else
raise "Invalid domain for tag"
end
output.join
end
|
Instance Method Details
#txp_content(tag) ⇒ Object
33
34
35
36
37
|
# File 'lib/txprails.rb', line 33
def txp_content(tag)
if content_for_layout = @view.instance_variable_get("@content_for_layout")
parse(content_for_layout)
end
end
|
#txp_controller(tag) ⇒ Object
47
48
49
|
# File 'lib/txprails.rb', line 47
def txp_controller(tag)
@view.controller.instance_variable_names.to_s
end
|
#txp_doc(tag) ⇒ Object
29
30
31
|
# File 'lib/txprails.rb', line 29
def txp_doc(tag)
"<!DOCTYPE html>"
end
|
#txp_eval(tag) ⇒ Object
39
40
41
|
# File 'lib/txprails.rb', line 39
def txp_eval(tag)
eval(tag.attr["code"])
end
|
#txp_include(tag) ⇒ Object
43
44
45
|
# File 'lib/txprails.rb', line 43
def txp_include(tag)
@view.render :partial => tag.attr["name"]
end
|