tj_bootstrap_helper 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,4 +4,4 @@ This is Tony Jian's Bootstrap helper gem.
4
4
 
5
5
  == Install
6
6
 
7
- gem 'bootstrap_helper', :git => "git://github.com/tonytonyjan/tj_bootstrap_helper.git"
7
+ gem 'tj_bootstrap_helper', :git => "git://github.com/tonytonyjan/tj_bootstrap_helper.git"
@@ -0,0 +1,30 @@
1
+ if defined?(WillPaginate)
2
+ module WillPaginate
3
+ module ActionView
4
+ def will_paginate(collection = nil, options = {})
5
+ options[:renderer] ||= BootstrapLinkRenderer
6
+ super(collection, options).try(:html_safe)
7
+ end
8
+
9
+ class BootstrapLinkRenderer < LinkRenderer
10
+ protected
11
+
12
+ def html_container(html)
13
+ tag :div, tag(:ul, html), container_attributes
14
+ end
15
+
16
+ def page_number(page)
17
+ tag :li, link(page, page, :rel => rel_value(page)), :class => ('active' if page == current_page)
18
+ end
19
+
20
+ def previous_or_next_page(page, text, classname)
21
+ tag :li, link(text, page || '#'), :class => [classname[0..3], classname, ('disabled' unless page)].join(' ')
22
+ end
23
+
24
+ def gap
25
+ tag :li, link(super, '#'), :class => 'disabled'
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -22,7 +22,7 @@ module TJBootstrapHelper
22
22
  # slice:: integer between 1..12. Items per slice (row).
23
23
  # fluid:: boolean. Whether the div tag is fluid.
24
24
  def spans resources, options = {}, &block
25
- return unless resources.is_a? Array
25
+ return unless resources.is_a?(Array) || resources.is_a?(ActiveRecord::Relation)
26
26
  options[:span] ||= 4
27
27
  options[:slice] ||= 12/options[:span]
28
28
  options[:fluid] ||= false
@@ -48,7 +48,7 @@ module TJBootstrapHelper
48
48
  # slice:: integer between 1..12. Items per slice.
49
49
  # url_method:: string or symbol. URL method of items, default is resources' RESTful URL.
50
50
  def thumbs resources, image_url_method, options = {}, &block
51
- return unless resources.is_a? Array
51
+ return unless resources.is_a?(Array) || resources.is_a?(ActiveRecord::Relation)
52
52
  options[:span] ||= 4
53
53
  options[:slice] ||= 12/options[:span]
54
54
  ret = "".html_safe
@@ -1,3 +1,3 @@
1
1
  module TJBootstrapHelper
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -2,4 +2,6 @@ require "tj_bootstrap_helper/version"
2
2
  require "tj_bootstrap_helper/helper"
3
3
 
4
4
  module TJBootstrapHelper
5
+ class Engine < Rails::Engine
6
+ end
5
7
  end
@@ -1,5 +1,5 @@
1
1
  class HomeController < ApplicationController
2
2
  def index
3
- @posts = Post.all
3
+ @posts = Post.paginate(:page => params[:page], :per_page => 12)
4
4
  end
5
5
  end
@@ -4,6 +4,7 @@
4
4
  <p><a class="btn btn-primary btn-large">Learn more &raquo;</a></p>
5
5
  </div>
6
6
 
7
+ <%= will_paginate @posts %>
7
8
  <%= spans %w(asfd qwer zxcv), fluid: true do |word| %>
8
9
  <h2><%= word %></h2>
9
10
  <p>content</p>
@@ -21,4 +22,5 @@
21
22
  <h2><%= post.title %></h2>
22
23
  <p><%= post.content %></p>
23
24
  <p><a class="btn" href="#">View details &raquo;</a></p>
24
- <% end %>
25
+ <% end %>
26
+ <%= will_paginate @posts %>
Binary file
@@ -1,4 +1,4 @@
1
- 12.times{
1
+ 120.times{
2
2
  Post.create(
3
3
  :title => Faker::Lorem.sentence,
4
4
  :content => Faker::Lorem.paragraphs.join("\n"),