Module: Ramaze::Helper::Partial
- Included in:
- Ezamar::RenderPartial
- Defined in:
- lib/ramaze/helper/partial.rb
Overview
Helper::Partial
Example Usage
class MyController
def index
end
def list
plain = request['plain']
"Hello World from List! Plain List == #{plain}"
end
end
<html>
<head><title>Partial Render Index</title></head>
<body>
#{render_partial(Rs(:list), 'plain' => true)}
</body>
</html>
Class Method Summary collapse
-
.render_action(method, *params) ⇒ Object
shortcut to render_partial, accepts a method and contructs a link to the current controller, then calls render_partial on that.
-
.render_partial(url, options = {}) ⇒ Object
Renders a url ‘inline’.
-
.render_template(file, vars = {}) ⇒ Object
Render the template file in view_root of the current controller.
Class Method Details
.render_action(method, *params) ⇒ Object
shortcut to render_partial, accepts a method and contructs a link to the current controller, then calls render_partial on that
100 101 102 |
# File 'lib/ramaze/helper/partial.rb', line 100 def render_action method, *params render_partial(Rs(method), *params) end |
.render_partial(url, options = {}) ⇒ Object
Renders a url ‘inline’.
url: normal URL, like you’d use for redirecting. options: optional, will be used as request parameters.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ramaze/helper/partial.rb', line 35 def render_partial(url, = {}) # Save any request params that clash with the ones we're about to add in. saved = {} .keys.each {|x| saved[x] = Request.current.params[x] } # Add/overwrite with the specified params. Ensure keys are strings since # request[:foo] converts key to string when performing lookup. .each do |key, value| Request.current.params[key.to_s] = value end Controller.handle(url) ensure # Always reinstate the original .keys.each {|x| Request.current.params[x] = saved[x] } end |
.render_template(file, vars = {}) ⇒ Object
Render the template file in view_root of the current controller.
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 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ramaze/helper/partial.rb', line 55 def render_template(file, vars = {}) current = Action.current = { :controller => current.controller, :instance => current.instance.dup } file = file.to_s if Pathname(file).absolute? file = file.squeeze '/' unless File.exist?(file) Log.warn "render_template: #{file} does not exist." return '' end [:template] = file else roots = [[:controller].template_paths].flatten if (files = Dir[File.join("{#{roots.join(',')}}","{#{file},#{file}.*}")]).any? [:template] = files.first.squeeze '/' else Log.warn "render_template: #{file} does not exist in the following directories: #{roots.join(',')}." return '' end end binding = [:instance].scope # For Ruby 1.9/1.8.7 binding = binding.binding if binding.respond_to?(:binding) vars.each do |name, value| [:instance].instance_variable_set("@#{name}", value) value = "ObjectSpace._id2ref(#{ value.object_id })" eval "#{ name } = #{ value }", binding end [:binding] = binding Ramaze::Action().render end |