diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 6d63fc4..d688144 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -51,6 +51,7 @@ class PagesController < ApplicationController params[:slug] = nil params[:uid] = nil params[:target_action] = params[:method] || "index" + OrbitHelper.set_page_number params[:page_no].to_i || 1 end page = Page.find_by_param(params[:page_id]) if !page.nil? @@ -213,8 +214,10 @@ class PagesController < ApplicationController html_string = html_string + p end pp = doc.css("*[#{key}]") - pp = pp[0] - pp.inner_html = html_string + if !pp.blank? + pp = pp[0] + pp.inner_html = html_string + end end if original_view != "home" diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f4dfe98..e2274de 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -164,7 +164,6 @@ module ApplicationHelper file.close controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new data = controller.send("#{params[:target_action]}") - keys = data.keys wrap_elements = doc.css("*[data-list][data-level='0']") htmls = parsing_repeats_again(wrap_elements,data,1) html = doc.to_s @@ -172,13 +171,38 @@ module ApplicationHelper html = html.gsub(h,htmls[1][i]) end - if keys[1] - (data[keys[1]].kind_of?(Array) ? data[keys[0]] : data[keys[1]]).each do |key,value| + if data["extras"] + data["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 + file = File.join(Rails.root, 'app', 'templates', "#{@key}", 'home', "pagination.html.erb") + total_pages = data['total_pages'].to_i rescue 1 + if total_pages > 1 + if File.exists?file + file = File.open(file) + doc = Nokogiri::HTML(file, nil, "UTF-8") + file.close + paginationobj = doc.css("*[data-pagination='true']").first + in_html = paginationobj.inner_html + f_html = "" + (1..total_pages).each do |i| + h = in_html + h = h.gsub("%7B%7Bpagination_link%7D%7D","?page_no=#{i.to_s}") + h = h.gsub("{{page_number}}",i.to_s) + h = h.gsub("{{pagination_active}}",(i == OrbitHelper.page_number ? "active" : "")) + f_html = f_html + h + end + paginationobj.inner_html = f_html + html = html.gsub("{{pagination_goes_here}}",paginationobj.to_s) + else + html = html.gsub("{{pagination_goes_here}}",""); + end + else + html = html.gsub("{{pagination_goes_here}}",""); + end html.html_safe elsif params[:target_action] == "show" file = File.open(File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "#{params[:target_action]}.html.erb")) diff --git a/app/helpers/orbit_helper.rb b/app/helpers/orbit_helper.rb index e6d927b..70d0441 100644 --- a/app/helpers/orbit_helper.rb +++ b/app/helpers/orbit_helper.rb @@ -15,6 +15,14 @@ module OrbitHelper @data_count end + def self.set_page_number(page) + @page_number = page + end + + def self.page_number + @page_number || 1 + end + def self.page_categories @categories end diff --git a/app/templates/orbit_bootstrap/home/page.html.erb b/app/templates/orbit_bootstrap/home/page.html.erb index 4f777f1..fd8594f 100644 --- a/app/templates/orbit_bootstrap/home/page.html.erb +++ b/app/templates/orbit_bootstrap/home/page.html.erb @@ -6,15 +6,17 @@ <%= render_orbit_bar %> <%= render_header %> -
+
-
-
- <%= yield %> -
+
+
+
+ <%= yield %> +
+
diff --git a/app/templates/orbit_bootstrap/home/pagination.html.erb b/app/templates/orbit_bootstrap/home/pagination.html.erb index d5d755d..96c2b2f 100644 --- a/app/templates/orbit_bootstrap/home/pagination.html.erb +++ b/app/templates/orbit_bootstrap/home/pagination.html.erb @@ -1,3 +1,3 @@ -
- \ No newline at end of file +{{pagination_goes_here}} \ No newline at end of file diff --git a/lib/orbit_category/categorizable.rb b/lib/orbit_category/categorizable.rb index a48e58d..f78eafc 100644 --- a/lib/orbit_category/categorizable.rb +++ b/lib/orbit_category/categorizable.rb @@ -13,13 +13,13 @@ module OrbitCategory if OrbitHelper.page_data_count == 0 self.all else - self.all.limit(OrbitHelper.page_data_count) + self.all.page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) end else if OrbitHelper.page_data_count == 0 self.where(:category_id.in => categories) rescue [] else - self.where(:category_id.in => categories).limit(OrbitHelper.page_data_count) rescue [] + self.where(:category_id.in => categories).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue [] end end else