From 5a5107a1525dacc73593d14e46adfbd2d78d0be6 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Mon, 7 Apr 2014 15:57:06 +0800 Subject: [PATCH] completed home page rendering... --- app/controllers/pages_controller.rb | 35 +++++++++++++------ app/helpers/orbit_helper.rb | 23 +++++++----- app/helpers/pages_helper.rb | 2 ++ .../modules/announcements/_widget.html.erb | 3 +- config/routes.rb | 2 +- 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 611bf24..6c97697 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -16,9 +16,18 @@ class PagesController < ApplicationController render get_view end + def home + @manifest = @key + @dataApi = nil + page = Page.where(:number => 0,:page_id => "").first + OrbitHelper.set_params params + OrbitHelper.set_site_locale locale + render :html => render_final_page("home",page).html_safe + end + def show path = request.original_fullpath.split('/') - if path.size == 2 + if path.size <= 2 redirect_to root_path else if path.last.include? '-' @@ -79,15 +88,18 @@ class PagesController < ApplicationController subparts = part.sub_parts partials = [] subparts.each do |subpart| - # partials << render_to_string(:partial => get_widget_path(widget_path)) - partials << render_widget_for_frontend(params[:target_controller],subpart.widget_method,subpart.widget_type) + partials << render_widget_for_frontend(subpart.module,subpart.widget_method,subpart.widget_type) end @part_partials["data-pp='#{part.part_id}'"] = partials end @file = nil @layout_html = nil - @file = File.join('../templates', "#{@key}", '/home/page.html.erb') + if original_view == "home" + @file = File.join('../templates', "#{@key}", '/home/index.html.erb') + else + @file = File.join('../templates', "#{@key}", '/home/page.html.erb') + end @layout_html = render_to_string(@file) doc = Nokogiri::HTML(@layout_html, nil, "UTF-8") @@ -101,8 +113,10 @@ class PagesController < ApplicationController pp.inner_html = html_string end - viewarea = doc.css("*[data-content='true']")[0] - viewarea.inner_html = render_to_string(original_view) + if original_view != "home" + viewarea = doc.css("*[data-content='true']")[0] + viewarea.inner_html = render_to_string(original_view) + end # newlayout = "#{page.name}_layout.html.erb" # file_path = File.join(Rails.root, 'app', 'views', 'frontend', newlayout) @@ -119,10 +133,9 @@ class PagesController < ApplicationController end def get_view - page = Page.find(params[:id]) - - if page.page_id == "home" - @view = File.join(Rails.root, 'app', 'templates', "#{@key}", '/home/index.html.erb') + page = Page.find(params[:id]) + if page.page_id == "" && page.number == 0 + @view = File.join(Rails.root, 'app', 'templates', "#{@key}", 'home/index.html.erb') else module_name = page.module.downcase.pluralize @view = File.join(Rails.root, 'app', 'templates', "#{@key}", "modules/#{module_name}/index.html.erb") @@ -145,7 +158,7 @@ class PagesController < ApplicationController def get_layout if request[:action] == "edit_view" page = Page.find(params[:id]) - if page.page_id == "home" + if page.page_id == "" && page.number == 0 false else File.join("../../templates", "#{@key}", '/home/page.html.erb') diff --git a/app/helpers/orbit_helper.rb b/app/helpers/orbit_helper.rb index 5ce06d7..2c3e652 100644 --- a/app/helpers/orbit_helper.rb +++ b/app/helpers/orbit_helper.rb @@ -8,7 +8,12 @@ module OrbitHelper end def self.url_to_show(slug) - "/#{@site_locale}#{@params[:url]}/#{slug}" + if @params[:url] + "/#{@site_locale}#{@params[:url]}/#{slug}" + else + page = Page.where(:module => self.current_widget_module).first + "/#{@site_locale}#{page.url}/#{slug}" + end end def self.set_site_locale(locale) @@ -18,12 +23,12 @@ module OrbitHelper def self.get_site_locale @site_locale end - - def self.to_param(title) - if I18n.locale.to_s == "en" - title.parameterize - else - title - end - end + + def self.current_widget_module + @controller_name + end + + def self.set_current_widget_module(name) + @controller_name = name + end end diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index 81c4843..55942dd 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -12,11 +12,13 @@ module PagesHelper end def render_widget_for_frontend(controller_name, widget_method, widget_file) + controller_name = controller_name.downcase.pluralize file = File.open(File.join(Rails.root, 'app', 'templates', "#{Template::KEY}", 'modules', "#{controller_name}", "_#{widget_file}.html.erb")) doc = Nokogiri::HTML(file, nil, "UTF-8") file.close wrap_elements = doc.css("*[data-repeat]") controller = "#{controller_name.capitalize}Controller".classify.constantize.new + OrbitHelper.set_current_widget_module controller_name.downcase.singularize data = controller.send("#{widget_method}") keys = data.keys wrap_elements.each do |wrap_element| diff --git a/app/templates/orbit_classic/modules/announcements/_widget.html.erb b/app/templates/orbit_classic/modules/announcements/_widget.html.erb index b44427d..7fe9c01 100644 --- a/app/templates/orbit_classic/modules/announcements/_widget.html.erb +++ b/app/templates/orbit_classic/modules/announcements/_widget.html.erb @@ -10,5 +10,4 @@ -

More

-

{{name}}

\ No newline at end of file +

More

\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index adfde71..79d0007 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,7 @@ OrbitStore::Application.routes.draw do # See how all your routes lay out with "rake routes". # You can have the root of your site routed with "root" - root 'home#index' + root 'pages#home' scope "(:locale)", locale: /en|zh_tw/ do get ':page(/:page)(/:page)(/:page)', to: 'pages#show', constraints: KeywordConstraint.new resources :pages