forked from saurabh/orbit4-5
modified parser and also rendering of 404 not found page .. also added force method for frontend and also to disbale layout in frontend
This commit is contained in:
parent
751b6ab2ea
commit
7f921e6f21
|
@ -1,3 +1,6 @@
|
||||||
|
# pass the layout=false for not rendering the layouts and also can specify the methods to in the backend controller.
|
||||||
|
# data-layout-content="arrayname" in layouts can be used to render data in the array
|
||||||
|
|
||||||
class PagesController < ApplicationController
|
class PagesController < ApplicationController
|
||||||
before_action :get_key
|
before_action :get_key
|
||||||
layout :get_layout
|
layout :get_layout
|
||||||
|
@ -22,7 +25,7 @@ class PagesController < ApplicationController
|
||||||
page = Page.first
|
page = Page.first
|
||||||
OrbitHelper.set_params params
|
OrbitHelper.set_params params
|
||||||
OrbitHelper.set_site_locale locale
|
OrbitHelper.set_site_locale locale
|
||||||
render :html => render_final_page("home",page).html_safe
|
render :html => render_final_page("home",page,true).html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@ -33,15 +36,16 @@ class PagesController < ApplicationController
|
||||||
if path.last.include? '-'
|
if path.last.include? '-'
|
||||||
params[:page_id] = path[-2]
|
params[:page_id] = path[-2]
|
||||||
params[:slug] = path[-1]
|
params[:slug] = path[-1]
|
||||||
params[:uid] = path[-1].split("-").last
|
uid = path[-1].split("-").last
|
||||||
params[:target_action] = "show"
|
uid = uid.split("?").first
|
||||||
|
params[:uid] = uid
|
||||||
|
params[:target_action] = params[:method] || "show"
|
||||||
else
|
else
|
||||||
params[:page_id] = path[-1]
|
params[:page_id] = path[-1]
|
||||||
params[:slug] = nil
|
params[:slug] = nil
|
||||||
params[:uid] = nil
|
params[:uid] = nil
|
||||||
params[:target_action] = "index"
|
params[:target_action] = params[:method] || "index"
|
||||||
end
|
end
|
||||||
|
|
||||||
page = Page.find_by_param(params[:page_id])
|
page = Page.find_by_param(params[:page_id])
|
||||||
if !page.nil?
|
if !page.nil?
|
||||||
if page.enabled_for.include? I18n.locale.to_s
|
if page.enabled_for.include? I18n.locale.to_s
|
||||||
|
@ -56,9 +60,14 @@ class PagesController < ApplicationController
|
||||||
OrbitHelper.set_site_locale locale
|
OrbitHelper.set_site_locale locale
|
||||||
OrbitHelper.set_page_categories page.categories || []
|
OrbitHelper.set_page_categories page.categories || []
|
||||||
OrbitHelper.set_page_data_count page.data_count
|
OrbitHelper.set_page_data_count page.data_count
|
||||||
|
if params[:layout].kind_of?(String)
|
||||||
|
layout = to_bool(params[:layout])
|
||||||
|
else
|
||||||
|
layout = true
|
||||||
|
end
|
||||||
|
|
||||||
# render render_final_page("#{module_app}/#{params[:target_action]}",page)
|
# render render_final_page("#{module_app}/#{params[:target_action]}",page)
|
||||||
render :html => render_final_page("#{module_app}/#{params[:target_action]}",page).html_safe
|
render :html => render_final_page("#{module_app}/#{params[:target_action]}",page,layout).html_safe
|
||||||
else
|
else
|
||||||
render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found
|
render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found
|
||||||
end
|
end
|
||||||
|
@ -154,9 +163,9 @@ class PagesController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def render_final_page(original_view=get_view,page)
|
def render_final_page(original_view=get_view,page,layout)
|
||||||
|
if layout
|
||||||
parts = page.page_parts
|
parts = page.page_parts rescue []
|
||||||
@part_partials = {}
|
@part_partials = {}
|
||||||
|
|
||||||
parts.each do |part|
|
parts.each do |part|
|
||||||
|
@ -191,6 +200,11 @@ class PagesController < ApplicationController
|
||||||
if original_view != "home"
|
if original_view != "home"
|
||||||
viewarea = doc.css("*[data-content='true']")[0]
|
viewarea = doc.css("*[data-content='true']")[0]
|
||||||
viewarea.inner_html = render_to_string(original_view)
|
viewarea.inner_html = render_to_string(original_view)
|
||||||
|
end
|
||||||
|
doc.to_html
|
||||||
|
|
||||||
|
else
|
||||||
|
render_to_string(original_view)
|
||||||
end
|
end
|
||||||
# newlayout = "#{page.name}_layout.html.erb"
|
# newlayout = "#{page.name}_layout.html.erb"
|
||||||
# file_path = File.join(Rails.root, 'app', 'views', 'frontend', newlayout)
|
# file_path = File.join(Rails.root, 'app', 'views', 'frontend', newlayout)
|
||||||
|
@ -200,7 +214,6 @@ class PagesController < ApplicationController
|
||||||
# f.close
|
# f.close
|
||||||
# view_to_render = "frontend/#{newlayout}"
|
# view_to_render = "frontend/#{newlayout}"
|
||||||
# view_to_render
|
# view_to_render
|
||||||
doc.to_html
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_widget_path(widget)
|
def get_widget_path(widget)
|
||||||
|
@ -208,8 +221,8 @@ class PagesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_view
|
def get_view
|
||||||
page = Page.find(params[:id])
|
page = Page.find(params[:id]) rescue Page.root
|
||||||
if page == Page.first
|
if page == Page.root
|
||||||
@view = File.join(Rails.root, 'app', 'templates', "#{@key}", 'home/index.html.erb')
|
@view = File.join(Rails.root, 'app', 'templates', "#{@key}", 'home/index.html.erb')
|
||||||
else
|
else
|
||||||
module_name = page.module.downcase.singularize
|
module_name = page.module.downcase.singularize
|
||||||
|
@ -247,5 +260,8 @@ class PagesController < ApplicationController
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
def to_bool(str)
|
||||||
|
return true if str == "true"
|
||||||
|
return false if str == "false"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -118,15 +118,18 @@ module ApplicationHelper
|
||||||
file = File.open(File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "#{params[:target_action]}.html.erb"))
|
file = File.open(File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "#{params[:target_action]}.html.erb"))
|
||||||
doc = Nokogiri::HTML(file, nil, "UTF-8")
|
doc = Nokogiri::HTML(file, nil, "UTF-8")
|
||||||
file.close
|
file.close
|
||||||
wrap_element_html = doc.to_s
|
|
||||||
html_to_render = ""
|
|
||||||
controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
|
controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
|
||||||
data = controller.send("#{params[:target_action]}")
|
data = controller.send("#{params[:target_action]}")
|
||||||
if data.blank? || data.empty?
|
if data.blank? || data.empty?
|
||||||
render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found
|
file = File.open("#{Rails.root}/public/404.html")
|
||||||
|
doc = Nokogiri::HTML(file, nil, "UTF-8")
|
||||||
|
file.close
|
||||||
|
doc.to_html.html_safe
|
||||||
else
|
else
|
||||||
wrap_elements = doc.css("*[data-repeat]")
|
wrap_elements = doc.css("*[data-repeat-content]")
|
||||||
if wrap_elements.count == 0
|
if wrap_elements.count == 0
|
||||||
|
wrap_element_html = doc.to_s
|
||||||
|
|
||||||
el = wrap_element_html
|
el = wrap_element_html
|
||||||
data.each do |key,value|
|
data.each do |key,value|
|
||||||
value = value.nil? ? "" : value
|
value = value.nil? ? "" : value
|
||||||
|
@ -136,9 +139,14 @@ module ApplicationHelper
|
||||||
el.html_safe
|
el.html_safe
|
||||||
else
|
else
|
||||||
keys = data.keys
|
keys = data.keys
|
||||||
|
not_array_key = nil
|
||||||
|
data.keys.each do |key|
|
||||||
|
not_array_key = key if data["#{key}"].kind_of?(Hash)
|
||||||
|
end
|
||||||
wrap_elements.each do |wrap_element|
|
wrap_elements.each do |wrap_element|
|
||||||
html_to_render = ""
|
html_to_render = ""
|
||||||
(data[keys[0]].kind_of?(Array) ? data[keys[0]] : data[keys[1]]).each do |item|
|
content_array = wrap_element.attr("data-repeat-content")
|
||||||
|
data["#{content_array}"].each do |item|
|
||||||
el = wrap_element.inner_html
|
el = wrap_element.inner_html
|
||||||
item.each do |key,value|
|
item.each do |key,value|
|
||||||
value = value.nil? ? "" : value
|
value = value.nil? ? "" : value
|
||||||
|
@ -150,8 +158,8 @@ module ApplicationHelper
|
||||||
wrap_element.inner_html = html_to_render
|
wrap_element.inner_html = html_to_render
|
||||||
end
|
end
|
||||||
html = doc.to_html
|
html = doc.to_html
|
||||||
if keys[1]
|
if data["#{not_array_key}"]
|
||||||
(data[keys[1]].kind_of?(Array) ? data[keys[0]] : data[keys[1]]).each do |key,value|
|
data["#{not_array_key}"].each do |key,value|
|
||||||
value = value.nil? ? "" : value
|
value = value.nil? ? "" : value
|
||||||
html = html.gsub("{{#{key}}}",value)
|
html = html.gsub("{{#{key}}}",value)
|
||||||
html = html.gsub("%7B%7B#{key}%7D%7D",value)
|
html = html.gsub("%7B%7B#{key}%7D%7D",value)
|
||||||
|
@ -164,7 +172,7 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def action_data
|
def action_data
|
||||||
controller = "#{params[:target_controller].capitalize}Controller".constantize.new
|
controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
|
||||||
data = controller.send("#{params[:target_action]}")
|
data = controller.send("#{params[:target_action]}")
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<p class="pic"><img src="{{image}}" alt=""></p>
|
<p class="pic"><img src="{{image}}" alt=""></p>
|
||||||
<p>{{body}}</p>
|
<p>{{body}}</p>
|
||||||
</section>
|
</section>
|
||||||
<div class="post-related">
|
<div class="post-related" data-repeat="">
|
||||||
asdf
|
<a href="{{link_to_file}}">{{file}}</a>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
|
@ -1,22 +1,10 @@
|
||||||
<section class="show" module="gallery">
|
<div class="index" module="gallery">
|
||||||
<div class="post-title">
|
<h2 class="widget-title">{{album-title}}</h2>
|
||||||
<h1>{{album-title}}</h1>
|
<ul class="row" data-repeat-content="images">
|
||||||
|
<li class="col-md-3 col-sm-4 col-xs-3">
|
||||||
|
<a href="{{link_to_show}}">
|
||||||
|
<img class="img-rounded" src="{{thumb-src}}" alt="">
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<small class="post-meta-date">
|
|
||||||
<span>
|
|
||||||
TAGS :
|
|
||||||
<a href="#"><span class="label label-info">theme</span></a>
|
|
||||||
<a href="#"><span class="label label-info">theme</span></a>
|
|
||||||
<a href="#"><span class="label label-info">theme</span></a>
|
|
||||||
</span>
|
|
||||||
<span class="author">BY : author</span>
|
|
||||||
<span class="unit">AT : unit</span>
|
|
||||||
<span class="date">2014-03-07 19:24:37</span>
|
|
||||||
</small>
|
|
||||||
<section class="post">
|
|
||||||
<img class="photo" src="http://placehold.it/768x600" alt="">
|
|
||||||
</section>
|
|
||||||
<div class="post-related">
|
|
||||||
asdf
|
|
||||||
</div>
|
|
||||||
</section>
|
|
Loading…
Reference in New Issue