Module: Serve::RenderHelpers

Included in:
ViewHelpers
Defined in:
lib/serve/view_helpers.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) render(partial, options = {})



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/serve/view_helpers.rb', line 116

def render(partial, options={})
  if partial.is_a?(Hash)
    options = options.merge(partial)
    partial = options.delete(:partial)
  end  
  template = options.delete(:template)
  case
  when partial
    render_partial(partial)
  when template
    render_template(template)
  else
    raise "render options not supported #{options.inspect}"
  end
end

- (Object) render_partial(partial)



132
133
134
# File 'lib/serve/view_helpers.rb', line 132

def render_partial(partial)
  render_template(partial, :partial => true)
end

- (Object) render_template(template, options = {})



136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/serve/view_helpers.rb', line 136

def render_template(template, options={})
  path = File.dirname(parser.script_filename)
  if template =~ %r{^/}
    template = template[1..-1]
    path = @root_path
  end
  filename = template_filename(File.join(path, template), :partial => options.delete(:partial))
  if File.file?(filename)
    parser.parse_file(filename)
  else
    raise "File does not exist #{filename.inspect}"
  end
end