Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 7 commits
  • 11 files changed
  • 0 commit comments
  • 1 contributor
View
9 CHANGELOG.md
@@ -0,0 +1,9 @@
+# v0.0.2
+
+* Global configuration
+* Fixes escaped HTML in the will_paginate links
+* Includes vendor in gemspec file manifest
+
+# v0.0.1
+
+First public release
View
4 Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- paginated_table (0.0.1)
+ paginated_table (0.0.2)
jquery-rails
rails (~> 3.2)
will_paginate (~> 3.0)
@@ -111,7 +111,7 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
- tzinfo (0.3.32)
+ tzinfo (0.3.33)
will_paginate (3.0.3)
xpath (0.1.4)
nokogiri (~> 1.3)
View
30 README.md
@@ -1,6 +1,6 @@
# PaginatedTable
-[![Build Status](https://secure.travis-ci.org/dball/paginated_table.png)](http://travis-ci.org/dball/paginated\_table)
+[![Build Status](https://secure.travis-ci.org/dball/paginated_table.png)](http://travis-ci.org/dball/paginated_table)
PaginatedTable is a Rails plugin that makes rendering paginated, sorted
HTML tables dead simple.
@@ -13,10 +13,10 @@ HTML tables dead simple.
## Installation
-Add `paginated\_table` to your `Gemfile` and `bundle install`.
+Add `paginated_table` to your `Gemfile` and `bundle install`.
-Add the `paginated\_table` javascript to your application's javascript
-requires after `jquery` and `jquery\_ujs`:
+Add the `paginated_table` javascript to your application's javascript
+requires after `jquery` and `jquery_ujs`:
//= require jquery
//= require jquery_ujs
@@ -123,10 +123,32 @@ collection.
</div>
</div>
+### Global Configuration
+
+In an initializer, e.g. `config/initializers/paginated_table.rb`:
+
+ PaginatedTable.configure do |config|
+ config.rows_per_page = 20
+ end
+
## TODO
* AJAX links should be optional
* AJAX busy indicator
* AJAX error indicator
+
+* Partial should infer ivar by template name?
+
+* Escaped HTML leaks in the will_paginate links
+
+* Explicitly enable the :rows option
+ * It really belongs in the view helper, but it's simpler to implement
+ in the controller helper
+
+* Global configuration
+ * AJAX links
+
+* :per_page request param should be allowed to be ignored or restricted
+ to a configurable maximum
View
1 lib/paginated_table.rb
@@ -5,3 +5,4 @@ module PaginatedTable
require 'paginated_table/railtie'
require 'paginated_table/engine'
require 'paginated_table/page'
+require 'paginated_table/config'
View
25 lib/paginated_table/config.rb
@@ -0,0 +1,25 @@
+module PaginatedTable
+ def self.configure(&block)
+ @configuration = Configuration.new(&block)
+ end
+
+ def self.configuration
+ @configuration
+ end
+
+ class Configuration
+ attr_accessor :rows_per_page
+
+ def initialize
+ yield self
+ end
+ end
+
+ def self.set_default_configuration
+ configure do |config|
+ config.rows_per_page = 10
+ end
+ end
+
+ set_default_configuration
+end
View
3 lib/paginated_table/page.rb
@@ -2,7 +2,6 @@ module PaginatedTable
class Page
SORT_DIRECTIONS = %w(asc desc)
- DEFAULT_PER_PAGE = 10
attr_reader :number, :rows, :sort_column, :sort_direction
@@ -14,7 +13,7 @@ def self.opposite_sort_direction(sort_direction)
def initialize(attributes)
@number = Integer(attributes[:number] || 1)
raise ArgumentError unless @number > 0
- @rows = Integer(attributes[:rows] || DEFAULT_PER_PAGE)
+ @rows = Integer(attributes[:rows] || PaginatedTable.configuration.rows_per_page)
raise ArgumentError unless @rows > 0
@sort_column = attributes[:sort_column] || 'id'
@sort_direction = attributes[:sort_direction] || 'asc'
View
2 lib/paginated_table/version.rb
@@ -1,3 +1,3 @@
module PaginatedTable
- VERSION = "0.0.1"
+ VERSION = "0.0.2"
end
View
2 lib/paginated_table/view_helpers.rb
@@ -146,7 +146,7 @@ def sort_link(text, sort_on)
def tag(name, value, attributes = {})
if name == :a
- @template.link_to(value, attributes.delete(:href), attributes.merge(:remote => true))
+ @template.link_to(value.to_s.html_safe, attributes.delete(:href), attributes.merge(:remote => true))
else
super
end
View
2 paginated_table.gemspec
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.summary = "Easy paginated, sorted tables in rails"
s.description = "Provides AJAX paginated, sorted tables in rails with will_paginate and arel"
- s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]
+ s.files = Dir["{lib, vendor}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]
s.test_files = Dir["test/**/*"]
s.add_dependency "rails", "~> 3.2"
View
19 test/units/config_test.rb
@@ -0,0 +1,19 @@
+module PaginatedTable
+ describe "configuration" do
+ let(:configuration) { PaginatedTable.configuration }
+ after do
+ PaginatedTable.set_default_configuration
+ end
+
+ it "should have default rows_per_page" do
+ configuration.rows_per_page.must_equal 10
+ end
+
+ it "should let us set rows_per_page" do
+ PaginatedTable.configure do |config|
+ config.rows_per_page = 20
+ end
+ configuration.rows_per_page.must_equal 20
+ end
+ end
+end
View
4 test/units/view_helpers_test.rb
@@ -137,8 +137,10 @@ module PaginatedTable
describe "#tag" do
it "calls link_to on the view with the :remote option for :a tags" do
+ html_safe_text = stub("html_safe_text")
+ text = stub("text", :to_s => stub("string", :html_safe => html_safe_text))
view.expects(:link_to).
- with(text, href, { :class => 'highlight', :remote => true }).
+ with(html_safe_text, href, { :class => 'highlight', :remote => true }).
returns(link)
renderer.tag(:a, text, :class => 'highlight', :href => href).must_equal link
end

No commit comments for this range

Something went wrong with that request. Please try again.