Class: Reactive::View::Wx::Template

Inherits:
ActionView::Base
  • Object
show all
Defined in:
lib/template.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load_helpersObject

:nodoc:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/template.rb', line 16

def self.load_helpers #:nodoc:
  # First load classes (all hosted under the Helper module)
  Dir.entries("#{File.dirname(__FILE__)}/helpers").sort.each do |file|
    next unless file =~ /^([a-z][a-z_]*_class|_classes).rb$/
    require "helpers/#{$1}"
  end
  include Helpers
  ActionView::Base::CompiledTemplates.send(:include, Helpers)
  # Then helper modules
  Dir.entries("#{File.dirname(__FILE__)}/helpers").sort.each do |file|
    next unless file =~ /^([a-z][a-z_]*_helper).rb$/
    require "helpers/#{$1}"
    helper_module_name = $1.camelize
    if Helpers.const_defined?(helper_module_name)
      include Helpers.const_get(helper_module_name)
      ActionView::Base::CompiledTemplates.send(:include, Helpers.const_get(helper_module_name))
    end
  end
end

Instance Method Details

#do_request(hash) ⇒ Object



41
42
43
# File 'lib/template.rb', line 41

def do_request(hash)
  Base.do_request(hash)
end

#extend(*modules) ⇒ Object

The controller may extend this object, especially with helpers Because we have compiled templates, when rendering such templates they are hosted in the ActionView::Base::CompiledTemplates module. This becomes a problem when a compiled template wants to access helper constants, they are hosted under XXXHelper and also in the controller master_helper_module. This method will also include the passed module into CompiledTemplates, so that everything is accessable. Note that this may break the class unloading feature for development mode.



91
92
93
94
# File 'lib/template.rb', line 91

def extend(*modules)
  ActionView::Base::CompiledTemplates.send(:include, *modules)
  super
end

#render(options = {}, old_local_assigns = {}, &block) ⇒ Object

We accept the rendering of a plain file (not a partial) that lies in the current view directory For this, simply pass the name of the view like: render “create.xrc”



47
48
49
50
51
52
53
# File 'lib/template.rb', line 47

def render(options = {}, old_local_assigns = {}, &block)
  if options.is_a?(String) && !options.include?('/')
    super(File.join(controller.class.controller_path, options), old_local_assigns, &block)
  else
    super
  end
end

#render_file(template_path, use_full_path = true, local_assigns = {}) ⇒ Object

handles format specification in the template_path. So it is possible to say: render “show.xrc”, meaning XRC is the format and any available handler will be used. So the file may either be “show.xrc.erb” or “show.src.builder” or any custum registered handler.



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/template.rb', line 58

def render_file(template_path, use_full_path = true, local_assigns = {}) #:nodoc:
  if controller && controller.request.respond_to?(:local_assigns) && controller.request.local_assigns
    local_assigns.merge!(controller.request.local_assigns) 
  end
  
  template_path_without_format, template_format = path_and_extension(template_path)
  if template_format && !File.basename(template_path_without_format).include?('.')
    @template_format = template_format.to_sym 
    super(template_path_without_format, use_full_path, local_assigns)
  else
    super
  end
end

#render_template(template_extension, template, file_path = nil, local_assigns = {}) ⇒ Object

The result of the rendering is used to create a Wx object (except when the format is :rb which means it is code)



73
74
75
76
77
78
79
80
81
82
# File 'lib/template.rb', line 73

def render_template(template_extension, template, file_path = nil, local_assigns = {}) #:nodoc:
  output = super
  if template_format == :xrc
    template_key = file_path || template
    parent = local_assigns[:parent_window]
    load_xrc(template_key, output, parent)
  else
    output
  end
end

#template_formatObject

ActionView returns :html by default, we don’t have any



37
38
39
# File 'lib/template.rb', line 37

def template_format
  @template_format ||= :rb
end