completed home page rendering...

This commit is contained in:
Harry Bomrah 2014-04-07 15:57:06 +08:00
parent 3ca008e041
commit 5a5107a152
5 changed files with 42 additions and 23 deletions

View File

@ -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')

View File

@ -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

View File

@ -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|

View File

@ -10,5 +10,4 @@
</div>
</div>
</div>
<p class="text-center"><a data-href="more" class="btn btn-primary" role="button" href="{{link_to_index}}">More</a></p>
<p class="text-center">{{name}}</p>
<p class="text-center"><a data-href="more" class="btn btn-primary" role="button" href="{{link_to_index}}">More</a></p>

View File

@ -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