Add rake dev:build for pages

This commit is contained in:
Wen-Tien Chang 2010-01-18 16:23:33 +08:00
parent 32e8bd108f
commit aab1199aee
15 changed files with 103 additions and 11 deletions

View File

@ -11,13 +11,7 @@ class PagesController < ApplicationController
def show def show
@page = Page.find_by_name(params[:page_name]) @page = Page.find_by_name(params[:page_name])
if @page && !@page.external_link.blank?
redirect_to @page.external_link
else
render_liquid_page render_liquid_page
end end
end end
end

View File

@ -4,7 +4,16 @@ class Snippet
key :name, String, :required => true, :index => true key :name, String, :required => true, :index => true
key :parent_name, String, :required => true, :index => true key :parent_name, String, :required => true, :index => true
key :parent_id, String, :required => true, :index => true
key_i18n :content, String key_i18n :content, String
before_validation :setup_default_value
protected
def setup_default_value
self.parent_id = Item.find_by_name( self.parent_name ).id
end
end end

View File

@ -12,10 +12,11 @@ class RerouteMiddleware
env['REQUEST_URI'] =~ /^\/([\w]*)/ env['REQUEST_URI'] =~ /^\/([\w]*)/
parsed_entry_name = $1 parsed_entry_name = $1
entry = Page.find_by_name( parsed_entry_name ) entry = Item.find_by_name( parsed_entry_name )
if entry && entry.component_name case entry.type
env['REQUEST_URI'] = env['REQUEST_URI'].sub!(parsed_entry_name, entry.component_name) when Component :
env['REQUEST_URI'] = env['REQUEST_URI'].sub!(parsed_entry_name, entry.engine_name)
env['QUERY_STRING'] = (env['QUERY_STRING'].blank?)? "entry_name=#{parsed_entry_name}" : "entry_name=#{parsed_entry_name}&#{env['QUERY_STRING']}" env['QUERY_STRING'] = (env['QUERY_STRING'].blank?)? "entry_name=#{parsed_entry_name}" : "entry_name=#{parsed_entry_name}&#{env['QUERY_STRING']}"
end end

26
lib/tasks/dev.rake Normal file
View File

@ -0,0 +1,26 @@
namespace :dev do
task :build => :environment do
[Announcement, Item, Snippet, Layout].each { |m| m.delete_all }
Layout.create!( :name => 'root', :content_zh_tw => File.open("#{RAILS_ROOT}/lib/template/root.layout.zh_tw").read,
:content_en => File.open("#{RAILS_ROOT}/lib/template/root.layout.en").read)
Page.create!( :name => "root", :title => I18n.t(:homepage), :layout_name => "root", :parent_name => nil,
:content_zh_tw => File.open("#{RAILS_ROOT}/lib/template/root.page.zh_tw").read,
:content_en => File.open("#{RAILS_ROOT}/lib/template/root.page.en").read )
["about"].each do |page_name|
Page.create!( :name => page_name, :title => page_name, :layout_name => "root", :parent_name => "root",
:content_zh_tw => File.open("#{RAILS_ROOT}/lib/template/#{page_name}.page.zh_tw").read,
:content_en => File.open("#{RAILS_ROOT}/lib/template/#{page_name}.page.en").read )
end
["nav", "footer"].each do |page_name|
Snippet.create!( :name => page_name, :parent_name => "root",
:content_zh_tw => File.open("#{RAILS_ROOT}/lib/template/#{page_name}.snippet.zh_tw").read,
:content_en => File.open("#{RAILS_ROOT}/lib/template/#{page_name}.snippet.en").read )
end
end
end

View File

@ -0,0 +1 @@
<h2>About us</h2>

View File

@ -0,0 +1 @@
<h2>關於我們</h2>

View File

@ -0,0 +1 @@
<p>Footer</p>

View File

@ -0,0 +1 @@
<p>頁尾</p>

View File

@ -0,0 +1,4 @@
<ul>
<li><a href="/">Homepage</a></li>
<li><a href="/about">About us</a></li>
<ul>

View File

@ -0,0 +1,4 @@
<ul>
<li><a href="/">首頁</a></li>
<li><a href="/about">關於我們</a></li>
<ul>

View File

@ -0,0 +1,24 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>RulingSite</title>
</head>
<body>
<div id="header">
{{ 'nav' | render_snippet }}
</div>
<div id="container">
{{page_content}}
</div>
<div id="footer">
{{ 'footer' | render_snippet }}
</div>
</body>
</html>

View File

@ -0,0 +1,24 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>RulingSite</title>
</head>
<body>
<div id="header">
{{ 'nav' | render_snippet }}
</div>
<div id="container">
{{page_content}}
</div>
<div id="footer">
{{ 'footer' | render_snippet }}
</div>
</body>
</html>

View File

@ -0,0 +1 @@
<p>This is homepage</p>

View File

@ -0,0 +1 @@
homepage<p>這是首頁</p>