<link href="style.css" /> </head> <body> <h1>Another Page</h1> <% ' Some code here that connects to the DB and ' displays stuff %> </body> </html> AnotherPage.asp
<html> <head> <title>RHP Rocks!</title> <%= Stylesheets.render() %> </head> <body> <h1><%= $greeting %></h1> <p>RHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. If you are new to RHP and want to get some idea of how it works, try the introductory tutorial. After that, check out the online manual.</p> </body> </html> cgi/index.erb
<html> <head> <title>RHP Rocks!</title> <%= Stylesheets.render() %> </head> <body> <h1><%= $greeting %></h1> <p>RHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. If you are new to RHP and want to get some idea of how it works, try the introductory tutorial. After that, check out the online manual.</p> </body> </html>
body.length.to_s } [200, headers, [body]] end def render # ... end end body = render('views/root/show.html.haml') body = "<html><body><h1>Hello World</h1></body><html>"
end def render_with_layout(view_path) layout = File.open('views/layout/application.html.haml', 'r').re Haml::Engine.new(layout).render do render(view_path) end end end end
body.length.to_s } [200, headers, [body]] end def render # ... end end body = render('views/root/show.html.haml') body = render_with_layout('views/root/show.html.haml')
{ "Content-Length" => body.length.to_s } [200, headers, [body]] end def render(view_path) template = File.open(view_path, 'r').read Haml::Engine.new(template).render end def render_with_layout(view_path) layout = File.open('views/layout/application.html.haml', 'r').re Haml::Engine.new(layout).render do render(view_path) end end end class RootController < Controller def show body = render_with_layout('views/root/show.html.haml') headers = { "Content-Length" => body.length.to_s } [200, headers, [body]] end end
def render_with_layout(view_path) layout_template = load_template_file(layout) Haml::Engine.new(layout_template).render do render_template(view_path) end end end
def render_with_layout(view_path) layout_template = load_template_file('... ') Haml::Engine.new(layout_template).render do render(view_path) end end end class Controller def render(view_path, context = self) template = load_template_file(view_path) Haml::Engine.new(template).render(context) end def render_with_layout(view_path, context = self) layout_template = load_template_file('... ') Haml::Engine.new(layout_template).render(context) do render(view_path, context) end end end `
class User def self.all result = DB.exec "SELECT * FROM users" fields = result.fields result.collect do |row| hash = {} row.each_with_index do |value, i| hash[fields[i]] = value end end end end