fix for pagination and also added data-module in body

This commit is contained in:
Harry Bomrah 2014-11-05 17:25:28 +08:00
parent e73ebe9037
commit 3a1fb9c72b
2 changed files with 11 additions and 9 deletions

View File

@ -354,14 +354,15 @@ class PagesController < ApplicationController
if @editmode if @editmode
session[:mobile] = $temp_mobile session[:mobile] = $temp_mobile
end end
format_date(final_html_for_render) rescue final_html_for_render format_date(final_html_for_render,(original_view == "home" ? "home" : page.module)) rescue final_html_for_render
end end
def format_date(html) def format_date(html,module_key)
doc = Nokogiri::HTML(html, nil, "UTF-8") doc = Nokogiri::HTML(html, nil, "UTF-8")
doc.css("body").first.set_attribute("data-module",module_key) rescue nil
dates = doc.css("*[date-format]") dates = doc.css("*[date-format]")
if dates.blank? if dates.blank?
return html return doc.to_html
else else
dates.each do |d| dates.each do |d|
format = d.attributes["date-format"].value format = d.attributes["date-format"].value

View File

@ -238,7 +238,6 @@ module ApplicationHelper
html = html.gsub("{{#{key}}}",value.to_s) html = html.gsub("{{#{key}}}",value.to_s)
html = html.gsub("%7B%7B#{key}%7D%7D",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 total_pages = data['total_pages'].to_i rescue 1
if total_pages > 1 if total_pages > 1
html = html.gsub("{{pagination_goes_here}}",create_pagination(total_pages)) html = html.gsub("{{pagination_goes_here}}",create_pagination(total_pages))
@ -424,12 +423,14 @@ module ApplicationHelper
file = File.open(file) file = File.open(file)
doc = Nokogiri::HTML(file, nil, "UTF-8") doc = Nokogiri::HTML(file, nil, "UTF-8")
file.close file.close
querystring = request.GET rescue {}
querystring.delete("page_no")
paginationobj = doc.css("*[data-pagination='true']").first paginationobj = doc.css("*[data-pagination='true']").first
in_html = first = last = nextpage = prevpage = paginationobj.inner_html in_html = first = last = nextpage = prevpage = paginationobj.inner_html
f_html = "" f_html = ""
current_page_number = OrbitHelper.page_number current_page_number = OrbitHelper.page_number
if current_page_number > 1 if current_page_number > 1
first = first.gsub("%7B%7Bpagination_link%7D%7D","?page_no=1") first = first.gsub("%7B%7Bpagination_link%7D%7D","?page_no=1&#{querystring.to_query}")
first = first.gsub("{{page_number}}","First") first = first.gsub("{{page_number}}","First")
first = first.gsub("{{pagination_active}}","") first = first.gsub("{{pagination_active}}","")
f_html = f_html + first f_html = f_html + first
@ -447,25 +448,25 @@ module ApplicationHelper
end_number = end_number > total_pages ? total_pages : end_number end_number = end_number > total_pages ? total_pages : end_number
(start_number..end_number).each do |i| (start_number..end_number).each do |i|
h = in_html h = in_html
h = h.gsub("%7B%7Bpagination_link%7D%7D","?page_no=#{i.to_s}") h = h.gsub("%7B%7Bpagination_link%7D%7D","?page_no=#{i.to_s}&#{querystring.to_query}")
h = h.gsub("{{page_number}}",i.to_s) h = h.gsub("{{page_number}}",i.to_s)
h = h.gsub("{{pagination_active}}",(i == current_page_number ? "active" : "")) h = h.gsub("{{pagination_active}}",(i == current_page_number ? "active" : ""))
f_html = f_html + h f_html = f_html + h
end end
if current_page_number > 1 if current_page_number > 1
prevpage = prevpage.gsub("%7B%7Bpagination_link%7D%7D","?page_no=#{current_page_number - 1}") prevpage = prevpage.gsub("%7B%7Bpagination_link%7D%7D","?page_no=#{current_page_number - 1}&#{querystring.to_query}")
prevpage = prevpage.gsub("{{page_number}}","&laquo;") prevpage = prevpage.gsub("{{page_number}}","&laquo;")
prevpage = prevpage.gsub("{{pagination_active}}","") prevpage = prevpage.gsub("{{pagination_active}}","")
f_html = f_html + prevpage f_html = f_html + prevpage
end end
if current_page_number < total_pages if current_page_number < total_pages
nextpage = nextpage.gsub("%7B%7Bpagination_link%7D%7D","?page_no=#{current_page_number + 1}") nextpage = nextpage.gsub("%7B%7Bpagination_link%7D%7D","?page_no=#{current_page_number + 1}&#{querystring.to_query}")
nextpage = nextpage.gsub("{{page_number}}","&raquo;") nextpage = nextpage.gsub("{{page_number}}","&raquo;")
nextpage = nextpage.gsub("{{pagination_active}}","") nextpage = nextpage.gsub("{{pagination_active}}","")
f_html = f_html + nextpage f_html = f_html + nextpage
last = last.gsub("%7B%7Bpagination_link%7D%7D","?page_no=#{total_pages}") last = last.gsub("%7B%7Bpagination_link%7D%7D","?page_no=#{total_pages}&#{querystring.to_query}")
last = last.gsub("{{page_number}}","Last") last = last.gsub("{{page_number}}","Last")
last = last.gsub("{{pagination_active}}","") last = last.gsub("{{pagination_active}}","")
f_html = f_html + last f_html = f_html + last