diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 542deaec..00704a73 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -11,13 +11,7 @@ class PagesController < ApplicationController def show @page = Page.find_by_name(params[:page_name]) - - if @page && !@page.external_link.blank? - redirect_to @page.external_link - else - render_liquid_page - end - + render_liquid_page end end diff --git a/app/models/item.rb b/app/models/item.rb index 20c81eb6..532cfe85 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -7,7 +7,7 @@ class Item key :name, String, :required => true, :index => true key :parent_name, String, :index => true - key :parent_id, String, :index => true + key :parent_id, String, :index => true key_i18n :title, String, :required => true diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 3c39240d..f9932480 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -4,7 +4,16 @@ class Snippet key :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 + before_validation :setup_default_value + + protected + + def setup_default_value + self.parent_id = Item.find_by_name( self.parent_name ).id + end end \ No newline at end of file diff --git a/lib/reroute_middleware.rb b/lib/reroute_middleware.rb index 88fe6a3d..1e60a7cf 100644 --- a/lib/reroute_middleware.rb +++ b/lib/reroute_middleware.rb @@ -12,10 +12,11 @@ class RerouteMiddleware env['REQUEST_URI'] =~ /^\/([\w]*)/ 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 - env['REQUEST_URI'] = env['REQUEST_URI'].sub!(parsed_entry_name, entry.component_name) + case entry.type + 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']}" end diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake new file mode 100644 index 00000000..a18a5d99 --- /dev/null +++ b/lib/tasks/dev.rake @@ -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 + \ No newline at end of file diff --git a/lib/template/about.page.en b/lib/template/about.page.en new file mode 100644 index 00000000..2b081c45 --- /dev/null +++ b/lib/template/about.page.en @@ -0,0 +1 @@ +

About us

\ No newline at end of file diff --git a/lib/template/about.page.zh_tw b/lib/template/about.page.zh_tw new file mode 100644 index 00000000..d2ecbd83 --- /dev/null +++ b/lib/template/about.page.zh_tw @@ -0,0 +1 @@ +

關於我們

\ No newline at end of file diff --git a/lib/template/footer.snippet.en b/lib/template/footer.snippet.en new file mode 100644 index 00000000..1486284b --- /dev/null +++ b/lib/template/footer.snippet.en @@ -0,0 +1 @@ +

Footer

\ No newline at end of file diff --git a/lib/template/footer.snippet.zh_tw b/lib/template/footer.snippet.zh_tw new file mode 100644 index 00000000..d8b078c7 --- /dev/null +++ b/lib/template/footer.snippet.zh_tw @@ -0,0 +1 @@ +

頁尾

\ No newline at end of file diff --git a/lib/template/nav.snippet.en b/lib/template/nav.snippet.en new file mode 100644 index 00000000..94d35a67 --- /dev/null +++ b/lib/template/nav.snippet.en @@ -0,0 +1,4 @@ +