made frontend kernel more stable .. now should not break in any case

This commit is contained in:
Harry Bomrah 2014-07-16 17:12:23 +08:00
parent 9b42eb4e8b
commit 32c6975f76
2 changed files with 30 additions and 18 deletions

View File

@ -40,6 +40,9 @@ module ApplicationHelper
temp_title = params[:slug].sub("-#{params[:uid]}","")
temp_title = temp_title.gsub("-"," ")
title = "#{temp_title} | #{title}"
elsif params[:target_action] == "index"
temp_title = Page.find_by(:page_id => params[:page_id]).name
title = "#{temp_title} | #{title}"
end
end
title
@ -201,6 +204,9 @@ module ApplicationHelper
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "#{params[:layout_type]}.html.erb")
if !File.exists?f
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "index.html.erb")
if !File.exists?f
return "<div class='well'>Maybe the administrator has changed the theme, please select the index page design again from the page settings.</div>".html_safe
end
end
file = File.open(f)
doc = Nokogiri::HTML(file, nil, "UTF-8")
@ -214,14 +220,14 @@ module ApplicationHelper
htmls[0].each_with_index do |h,i|
html = html.gsub(h,htmls[1][i])
end
if data["extras"]
data["extras"].each do |key,value|
extras = data["extras"] || {}
extras["page-title"] = Page.find_by(:page_id => params[:page_id]).name rescue "" if !extras["page-title"]
extras.each do |key,value|
value = value.nil? ? "" : value
html = html.gsub("{{#{key}}}",value.to_s)
html = html.gsub("%7B%7B#{key}%7D%7D",value.to_s)
end
end
total_pages = data['total_pages'].to_i rescue 1
if total_pages > 1
html = html.gsub("{{pagination_goes_here}}",create_pagination(total_pages))
@ -230,7 +236,7 @@ module ApplicationHelper
end
html.html_safe
else
return "<div>It seems we have a problem with the module at this point of time, we will try to fix it as soon as possible, Sorry for the inconvenience!! :( </div>".html_safe
return "<div class='well'>It seems we have a problem with the module at this point of time, we will try to fix it as soon as possible. Sorry for the inconvenience!! :( </div>".html_safe
end
else
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "#{params[:target_action]}.html.erb")
@ -241,7 +247,7 @@ module ApplicationHelper
controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
data = controller.send("#{params[:target_action]}") rescue nil
if data.nil?
return "<div>It seems we have a problem with the module at this point of time, we will try to fix it as soon as possible, Sorry for the inconvenience!! :( </div>".html_safe
return "<div class='well'>It seems we have a problem with the module at this point of time, we will try to fix it as soon as possible. Sorry for the inconvenience!! :( </div>".html_safe
end
if data.blank? || data.empty?
@ -285,17 +291,18 @@ module ApplicationHelper
htmls[0].each_with_index do |h,i|
html = html.gsub(h,htmls[1][i])
end
if data["#{not_array_key}"]
data["#{not_array_key}"].each do |key,value|
extras = data["#{not_array_key}"] || {}
extras.each do |key,value|
next if key.eql? 'impressionist'
value = value.nil? ? "" : value
html = html.gsub("{{#{key}}}",value.to_s)
html = html.gsub("%7B%7B#{key}%7D%7D",value.to_s)
end
end
html.html_safe
end
end
else
return "<div class='well'>There is a problem with the design. We will try to fix it as soon as possible. Sorry for the inconvenience!! :(</div>".html_safe
end
end
end

View File

@ -50,7 +50,12 @@ module PagesHelper
if !File.exists?f
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'widgets', "#{controller_name}", "_#{widget_file}.html.erb");
if !File.exists?f
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', "#{controller_name}", "_widget.html.erb");
if File.exists?f
f = File.join('../templates', "#{@key}", 'modules', "#{controller_name}", "_widget.html.erb");
else
return "<div class='well'>Maybe the administrator has changed the theme, please select the widget design again from the page settings.</div>".html_safe
end
else
f = File.join('../templates', "#{@key}", 'widgets', "#{controller_name}", "_#{widget_file}.html.erb");
end
@ -78,7 +83,7 @@ module PagesHelper
end
html.html_safe
else
return "<div>It seems we have a problem with the module at this point of time, we will try to fix it as soon as possible, Sorry for the inconvenience!! :( </div>".html_safe
return "<div class='well'>It seems we have a problem with the module at this point of time, we will try to fix it as soon as possible. Sorry for the inconvenience!! :( </div>".html_safe
end
end