Created
August 9, 2012 07:11
-
-
Save liushooter/3301870 to your computer and use it in GitHub Desktop.
ERB模板
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background-color: <%= @color %>; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<title><%= @title %></title> | |
<head> | |
<style type="text/css"> | |
<%= render "home.css.erb" %> | |
</style> | |
</head> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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