Skip to content

Instantly share code, notes, and snippets.

@liushooter
Created August 9, 2012 07:11
Show Gist options
  • Save liushooter/3301870 to your computer and use it in GitHub Desktop.
Save liushooter/3301870 to your computer and use it in GitHub Desktop.
ERB模板
body {
background-color: <%= @color %>;
}
<title><%= @title %></title>
<head>
<style type="text/css">
<%= render "home.css.erb" %>
</style>
</head>
#encoding:utf-8
require "erb"
class Page
def initialize title, color
@title = title
@color = color
end
def render path
content = File.read(File.expand_path(path))
t = ERB.new(content)
t.result(binding)
end
end
file=File.open("home.html","w:utf-8")
page = Page.new("Home", "#CCCCCC")
file.puts page.render("home.erb")
file.close
p "ok"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment