ajax_pagination 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.md +20 -1
- data/README.md +49 -5
- data/Rakefile +16 -0
- data/ajax_pagination.gemspec +5 -2
- data/lib/ajax_pagination/controller_additions.rb +52 -3
- data/lib/ajax_pagination/helper_additions.rb +53 -4
- data/lib/ajax_pagination/version.rb +1 -1
- data/lib/assets/images/ajax-loader.gif +0 -0
- data/lib/assets/javascripts/ajax_pagination.js.erb +41 -31
- data/spec/PORT +1 -0
- data/spec/ajax_pagination/controller_additions_spec.rb +79 -0
- data/spec/ajax_pagination/helper_additions_spec.rb +45 -0
- data/spec/ajax_pagination/integration/ajaxpaginate_spec.rb +33 -0
- data/spec/ajax_pagination/integration/nojavascript_spec.rb +30 -0
- data/spec/ajax_pagination/integration/paginate_spec.rb +30 -0
- data/spec/rails_app/.gitignore +8 -0
- data/spec/rails_app/Gemfile +42 -0
- data/spec/rails_app/README.rdoc +261 -0
- data/spec/rails_app/Rakefile +7 -0
- data/spec/rails_app/app/assets/javascripts/application.js +17 -0
- data/spec/rails_app/app/assets/javascripts/posts.js +2 -0
- data/spec/rails_app/app/assets/stylesheets/application.css +26 -0
- data/spec/rails_app/app/assets/stylesheets/posts.css +4 -0
- data/spec/rails_app/app/assets/stylesheets/scaffold.css +56 -0
- data/spec/rails_app/app/controllers/application_controller.rb +10 -0
- data/spec/rails_app/app/controllers/changelog_controller.rb +13 -0
- data/spec/rails_app/app/controllers/pages_controller.rb +23 -0
- data/spec/rails_app/app/controllers/posts_controller.rb +95 -0
- data/spec/rails_app/app/controllers/sessions_controller.rb +11 -0
- data/spec/rails_app/app/helpers/application_helper.rb +2 -0
- data/spec/rails_app/app/helpers/posts_helper.rb +2 -0
- data/spec/rails_app/app/mailers/.gitkeep +0 -0
- data/spec/rails_app/app/models/.gitkeep +0 -0
- data/spec/rails_app/app/models/changelog.rb +19 -0
- data/spec/rails_app/app/models/post.rb +4 -0
- data/spec/rails_app/app/views/changelog/_page.html.erb +10 -0
- data/spec/rails_app/app/views/changelog/index.html.erb +3 -0
- data/spec/rails_app/app/views/layouts/application.html.erb +37 -0
- data/spec/rails_app/app/views/pages/about.html.erb +4 -0
- data/spec/rails_app/app/views/pages/readme.html.erb +4 -0
- data/spec/rails_app/app/views/pages/welcome.html.erb +6 -0
- data/spec/rails_app/app/views/posts/_form.html.erb +29 -0
- data/spec/rails_app/app/views/posts/_page.html.erb +15 -0
- data/spec/rails_app/app/views/posts/_upcomingpage.html.erb +15 -0
- data/spec/rails_app/app/views/posts/edit.html.erb +6 -0
- data/spec/rails_app/app/views/posts/index.html.erb +15 -0
- data/spec/rails_app/app/views/posts/new.html.erb +5 -0
- data/spec/rails_app/app/views/posts/show.html.erb +13 -0
- data/spec/rails_app/config.ru +4 -0
- data/spec/rails_app/config/application.rb +56 -0
- data/spec/rails_app/config/boot.rb +10 -0
- data/spec/rails_app/config/database.yml +25 -0
- data/spec/rails_app/config/environment.rb +5 -0
- data/spec/rails_app/config/environments/development.rb +37 -0
- data/spec/rails_app/config/environments/production.rb +67 -0
- data/spec/rails_app/config/environments/test.rb +37 -0
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails_app/config/initializers/inflections.rb +15 -0
- data/spec/rails_app/config/initializers/mime_types.rb +5 -0
- data/spec/rails_app/config/initializers/secret_token.rb +7 -0
- data/spec/rails_app/config/initializers/session_store.rb +8 -0
- data/spec/rails_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails_app/config/locales/en.yml +5 -0
- data/spec/rails_app/config/routes.rb +72 -0
- data/spec/rails_app/db/development.sqlite3 +0 -0
- data/spec/rails_app/db/migrate/20120219063632_create_posts.rb +10 -0
- data/spec/rails_app/db/migrate/20120219130149_add_published_to_post.rb +5 -0
- data/spec/rails_app/lib/assets/.gitkeep +0 -0
- data/spec/rails_app/log/.gitkeep +0 -0
- data/spec/rails_app/public/404.html +26 -0
- data/spec/rails_app/public/422.html +26 -0
- data/spec/rails_app/public/500.html +25 -0
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/rails_app/script/rails +6 -0
- data/spec/rails_app/test/fixtures/posts.yml +9 -0
- data/spec/rails_app/test/functional/posts_controller_test.rb +49 -0
- data/spec/rails_app/test/unit/helpers/posts_helper_test.rb +4 -0
- data/spec/rails_app/test/unit/post_test.rb +7 -0
- data/spec/spec_helper.rb +28 -0
- data/vendor/assets/javascripts/jquery.url.js +160 -0
- metadata +171 -86
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
RailsApp::Application.load_tasks
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require history
|
16
|
+
//= require ajax_pagination
|
17
|
+
//= require_tree .
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
14
|
+
|
15
|
+
.menu ul li {
|
16
|
+
display: inline-block;
|
17
|
+
border: 1px solid black;
|
18
|
+
}
|
19
|
+
.menu ul li a {
|
20
|
+
padding-left: 30px;
|
21
|
+
padding-right: 30px;
|
22
|
+
}
|
23
|
+
|
24
|
+
#alert {
|
25
|
+
color: red;
|
26
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
div.field, div.actions {
|
20
|
+
margin-bottom: 10px;
|
21
|
+
}
|
22
|
+
|
23
|
+
#notice {
|
24
|
+
color: green;
|
25
|
+
}
|
26
|
+
|
27
|
+
.field_with_errors {
|
28
|
+
padding: 2px;
|
29
|
+
background-color: red;
|
30
|
+
display: table;
|
31
|
+
}
|
32
|
+
|
33
|
+
#error_explanation {
|
34
|
+
width: 450px;
|
35
|
+
border: 2px solid red;
|
36
|
+
padding: 7px;
|
37
|
+
padding-bottom: 0;
|
38
|
+
margin-bottom: 20px;
|
39
|
+
background-color: #f0f0f0;
|
40
|
+
}
|
41
|
+
|
42
|
+
#error_explanation h2 {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
padding: 5px 5px 5px 15px;
|
46
|
+
font-size: 12px;
|
47
|
+
margin: -7px;
|
48
|
+
margin-bottom: 0px;
|
49
|
+
background-color: #c00;
|
50
|
+
color: #fff;
|
51
|
+
}
|
52
|
+
|
53
|
+
#error_explanation ul li {
|
54
|
+
font-size: 12px;
|
55
|
+
list-style: square;
|
56
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class ChangelogController < ApplicationController
|
2
|
+
# GET /posts
|
3
|
+
# GET /posts.json
|
4
|
+
def index
|
5
|
+
@changelogs = Changelog.paginate(:page => params[:page], :per_page => 2)
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.erb
|
9
|
+
ajax_pagination(format)
|
10
|
+
ajax_pagination format, :pagination => :menu, :partial => {:file => "changelog/index"}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class PagesController < ApplicationController
|
2
|
+
def readme
|
3
|
+
@readme = IO.read(File.expand_path("../../../../../README.md",__FILE__))
|
4
|
+
respond_to do |format|
|
5
|
+
format.html
|
6
|
+
ajax_pagination format, :pagination => :menu, :partial => {:file => "pages/readme"}
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def about
|
11
|
+
respond_to do |format|
|
12
|
+
format.html
|
13
|
+
ajax_pagination format, :pagination => :menu, :partial => {:file => "pages/about"}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def welcome
|
18
|
+
respond_to do |format|
|
19
|
+
format.html
|
20
|
+
ajax_pagination format, :pagination => :menu, :partial => {:file => "pages/welcome"}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
class PostsController < ApplicationController
|
2
|
+
# GET /posts
|
3
|
+
# GET /posts.json
|
4
|
+
def index
|
5
|
+
@posts = Post.published.order('published_at DESC').paginate(:page => params[:page], :per_page => 3)
|
6
|
+
@upcomingposts = Post.unpublished.order('published_at ASC').paginate(:page => params[:upcomingpage], :per_page => 2)
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.erb
|
9
|
+
format.json { render :json => @posts }
|
10
|
+
ajax_pagination(format)
|
11
|
+
ajax_pagination format, :pagination => :upcomingpage
|
12
|
+
ajax_pagination format, :pagination => :menu, :partial => {:file => "posts/index"}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /posts/1
|
17
|
+
# GET /posts/1.json
|
18
|
+
def show
|
19
|
+
@post = Post.find(params[:id])
|
20
|
+
|
21
|
+
respond_to do |format|
|
22
|
+
format.html # show.html.erb
|
23
|
+
format.json { render :json => @post }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# GET /posts/new
|
28
|
+
# GET /posts/new.json
|
29
|
+
def new
|
30
|
+
redirect_to posts_url, :alert => "Access Denied" and return if !session[:admin]
|
31
|
+
@post = Post.new
|
32
|
+
|
33
|
+
respond_to do |format|
|
34
|
+
format.html # new.html.erb
|
35
|
+
format.json { render :json => @post }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# GET /posts/1/edit
|
40
|
+
def edit
|
41
|
+
redirect_to post_url(params[:id]), :alert => "Access Denied" and return if !session[:admin]
|
42
|
+
@post = Post.find(params[:id])
|
43
|
+
@post.published_at = @post.created_at if @post.published_at.nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
# POST /posts
|
47
|
+
# POST /posts.json
|
48
|
+
def create
|
49
|
+
redirect_to posts_url, :alert => "Access Denied" and return if !session[:admin]
|
50
|
+
@post = Post.new(params[:post])
|
51
|
+
@post.published_at = @post.created_at if @post.published_at.nil?
|
52
|
+
|
53
|
+
respond_to do |format|
|
54
|
+
if @post.save
|
55
|
+
@post.published_at = @post.created_at if @post.published_at.nil?
|
56
|
+
@post.save
|
57
|
+
format.html { redirect_to @post, :notice => 'Post was successfully created.' }
|
58
|
+
format.json { render :json => @post, :status => :created, :location => @post }
|
59
|
+
else
|
60
|
+
format.html { render :action => "new" }
|
61
|
+
format.json { render :json => @post.errors, :status => :unprocessable_entity }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# PUT /posts/1
|
67
|
+
# PUT /posts/1.json
|
68
|
+
def update
|
69
|
+
redirect_to post_url(params[:id]), :alert => "Access Denied" and return if !session[:admin]
|
70
|
+
@post = Post.find(params[:id])
|
71
|
+
|
72
|
+
respond_to do |format|
|
73
|
+
if @post.update_attributes(params[:post])
|
74
|
+
format.html { redirect_to @post, :notice => 'Post was successfully updated.' }
|
75
|
+
format.json { head :no_content }
|
76
|
+
else
|
77
|
+
format.html { render :action => "edit" }
|
78
|
+
format.json { render :json => @post.errors, :status => :unprocessable_entity }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# DELETE /posts/1
|
84
|
+
# DELETE /posts/1.json
|
85
|
+
def destroy
|
86
|
+
redirect_to post_url(params[:id]), :alert => "Access Denied" and return if !session[:admin]
|
87
|
+
@post = Post.find(params[:id])
|
88
|
+
@post.destroy
|
89
|
+
|
90
|
+
respond_to do |format|
|
91
|
+
format.html { redirect_to posts_url }
|
92
|
+
format.json { head :no_content }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class SessionsController < ApplicationController
|
2
|
+
def signin
|
3
|
+
session[:admin] = true
|
4
|
+
redirect_to root_url, :notice => "Successfully signed in as admin"
|
5
|
+
end
|
6
|
+
|
7
|
+
def signout
|
8
|
+
session[:admin] = false
|
9
|
+
redirect_to root_url, :notice => "Successfully signed out"
|
10
|
+
end
|
11
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# This model is not actually backed by the database, but conveniently collects all the changelog entries as models
|
2
|
+
|
3
|
+
require 'will_paginate/array' # because model not backed by database, model returns arrays instead of ActiveRecord Relations
|
4
|
+
|
5
|
+
class Changelog < ActiveRecord::Base
|
6
|
+
attr_accessor :title, :content
|
7
|
+
def initialize(title,content)
|
8
|
+
@title = title
|
9
|
+
@content = content
|
10
|
+
end
|
11
|
+
def self.all
|
12
|
+
changelogs = IO.read(File.expand_path("../../../../../CHANGELOG.md",__FILE__)).split(/^## /).map{|str| Changelog.new(str.split(/$/,2)[0],str.split(/$/,2)[1])}
|
13
|
+
changelogs.slice!(0)
|
14
|
+
changelogs
|
15
|
+
end
|
16
|
+
def self.paginate(options={})
|
17
|
+
self.all.paginate(options)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%= will_paginate @changelogs, :params => { :pagination => nil } %>
|
2
|
+
<%= ajax_pagination_loadzone do %>
|
3
|
+
<% @changelogs.each do |changelog| %>
|
4
|
+
<%= content_tag :div, :style => "border-bottom: 1px solid black;" do %>
|
5
|
+
<h3><%= simple_format(changelog.title) %></h3>
|
6
|
+
<%= simple_format(changelog.content) %>
|
7
|
+
<% end %>
|
8
|
+
<% end %>
|
9
|
+
<% end %>
|
10
|
+
<%= will_paginate @changelogs, :params => { :pagination => nil } %>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>RailsApp</title>
|
5
|
+
<%= stylesheet_link_tag "application", :media => "all" %>
|
6
|
+
<%= javascript_include_tag "application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<div style="float: right;">
|
11
|
+
<% if session[:admin] %>
|
12
|
+
<%= link_to "Sign out", sessions_signout_url, :id => "signout" %>
|
13
|
+
<% else %>
|
14
|
+
<%= link_to "Sign in as admin", sessions_signin_url, :id => "signin" %>
|
15
|
+
<% end %>
|
16
|
+
</div>
|
17
|
+
<h1>AJAX Pagination Example Application</h1>
|
18
|
+
<div class="ajaxpagination menu" data-pagination="menu">
|
19
|
+
<ul>
|
20
|
+
<li><%= link_to "Home", root_url %></li>
|
21
|
+
<li><%= link_to "Posts", posts_url %></li>
|
22
|
+
<li><%= link_to "Changelog", changelog_url %></li>
|
23
|
+
<li><%= link_to "Readme", pages_readme_url %></li>
|
24
|
+
<li><%= link_to "About", pages_about_url %></li>
|
25
|
+
</ul>
|
26
|
+
</div>
|
27
|
+
<%= ajax_pagination :pagination => "menu", :reload => {:urlpart => "path", :urlregex => "^.*$"}, :loadzone => true do %>
|
28
|
+
<% if flash[:notice] %>
|
29
|
+
<p id="notice"><%= flash[:notice] %></p>
|
30
|
+
<% end %>
|
31
|
+
<% if flash[:alert] %>
|
32
|
+
<p id="alert"><%= flash[:alert] %></p>
|
33
|
+
<% end %>
|
34
|
+
<%= yield %>
|
35
|
+
<% end %>
|
36
|
+
</body>
|
37
|
+
</html>
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<h1 id="aboutpagetitle">About</h1> <!-- Don't change this line, rspec test uses this to detect About page -->
|
2
|
+
|
3
|
+
<p>This gem was created by Ronald Chan, who ajaxified his pagination of a rails application. Because the code added some common features, and the code was also modularised, it becomes much more useful to package it up in a gem, so that everybody can use it. The separation of the code also makes the application better managed, since it provides functionality not specific to the application.</p>
|
4
|
+
<p>This example application was created for testing purposes. It is also a good example application so that you can see what the gem can do.</p>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<h2 id="welcomepagetitle">Example Rails Application for AJAX Pagination</h2> <!-- Don't change this line, rspec test uses this to detect page -->
|
2
|
+
<p>Welcome to the example application for the Rails gem, AJAX Pagination. This gem will ajaxify your pagination and navigation.</p>
|
3
|
+
|
4
|
+
<p>The posts and changelog are good examples of how pagination of your records can be ajaxified easily. Additionally, the whole site has content which is loaded with AJAX calls, because the menu navigation links also have AJAX Pagination applied to them.</p>
|
5
|
+
|
6
|
+
<p>This site is used to test the gem. Because a good part of this gem involves javascript, it is tested using the Capybara gem.</p>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%= form_for(@post) do |f| %>
|
2
|
+
<% if @post.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @post.errors.full_messages.each do |msg| %>
|
8
|
+
<li><%= msg %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.label :title %><br />
|
16
|
+
<%= f.text_field :title %>
|
17
|
+
</div>
|
18
|
+
<div class="field">
|
19
|
+
<%= f.label :content %><br />
|
20
|
+
<%= f.text_area :content %>
|
21
|
+
</div>
|
22
|
+
<div class="field">
|
23
|
+
<%= f.label :published_at %><br />
|
24
|
+
<%= f.text_field :published_at %>
|
25
|
+
</div>
|
26
|
+
<div class="actions">
|
27
|
+
<%= f.submit %>
|
28
|
+
</div>
|
29
|
+
<% end %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%= will_paginate @posts, :params => { :pagination => nil } %>
|
2
|
+
<%= ajax_pagination_loadzone do %>
|
3
|
+
<% @posts.each do |post| %>
|
4
|
+
<div style="border-bottom: 1px solid black; padding-bottom: 10px;">
|
5
|
+
<p><h3><%= post.title %></h3><i>Published on <%= post.published_at.strftime('%d %B %Y') if post.published_at? %></i></p>
|
6
|
+
<%= simple_format(post.content) %>
|
7
|
+
<%= link_to 'Show', post %>
|
8
|
+
<% if session[:admin] %>
|
9
|
+
| <%= link_to 'Edit', edit_post_path(post) %> |
|
10
|
+
<%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %>
|
11
|
+
<% end %>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
14
|
+
<% end %>
|
15
|
+
<%= will_paginate @posts, :params => { :pagination => nil } %>
|