bootstrapとrals 2.3.8を統合したもの:will_paginateプラグインの使用
4364 ワード
renderを追加して、appication_helper.erb
http://www.leonardteo.com/2011/12/rails-bootstrap-and-will_paginate/will_paginate.zh.yml will pageinateの中国文化
class BootstrapLinkRenderer < ::WillPaginate::LinkRenderer
def initialize
#@gap_marker = @template.content_tag :li, @template.content_tag(:link(super, '#')), :class => 'disabled'
@gap_marker = '<li class="disabled"><a href="javascript:void(0)">…</a></span>'
end
def to_html
links = @options[:page_links] ? windowed_links : []
links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:previous_label])
links.push page_link_or_span(@collection.next_page, 'disabled next_page', @options[:next_label])
html = links.join(@options[:separator])
html = html.html_safe if html.respond_to? :html_safe
@options[:container] ? @template.content_tag(:ul, html, html_attributes) : html
end
def page_link(page, text, attributes = {})
@template.content_tag(:li, @template.link_to(text, url_for(page)), attributes)
end
def page_span(page, text, attributes = {})
@template.content_tag(:li,@template.link_to(text,"javascript:void(0)"), attributes)
end
end
ビュー層は以下のように参照されています <%=will_paginate @videos, {:renderer => BootstrapLinkRenderer,:previous_label => " ", :next_label => " "} %>
次のcssを追加してこそ完璧です.<style type="text/css">
.pagination .current a, .pagination .current a:hover{
background-color: transparent;
color: #999999;
cursor: default;
}
</style>
ライズ3.0以上、ご参考ください.http://www.leonardteo.com/2011/12/rails-bootstrap-and-will_paginate/will_paginate.zh.yml will pageinateの中国文化
zh:
will_paginate:
models:
entry:
previous_label: "← "
next_label: " →"
page_gap: "... ..."
page_entries_info:
single_page:
zero: " %{model} "
one: " 1 %{model}"
other: " %{count} %{model}"
single_page_html:
zero: " %{model} "
one: " <b>1</b> %{model}"
other: " <b> %{count}</b> %{model}"
multi_page: " %{model} %{from} - %{to} %{count} "
multi_page_html: " %{model} <b>%{from} - %{to}</b> <b>%{count}</b> "
entries
, models: entry
defaults = ["models.#{model_key}"]
defaults << Proc.new { |_, opts|
if model.respond_to? :model_name
model.model_name.human(:count => opts[:count])
else
name = model_key.to_s.tr('_', ' ')
raise "can't pluralize model name: #{model.inspect}" unless name.respond_to? :pluralize
opts[:count] == 1 ? name : name.pluralize
end
}
model_name = will_paginate_translate defaults, :count => model_count
will_パギナートtranslateの の は の りです. def will_paginate_translate(keys, options = {})
if defined? ::I18n
defaults = Array(keys).dup
defaults << Proc.new if block_given?
::I18n.translate(defaults.shift, options.merge(:default => defaults, :scope => :will_paginate))
else
key = Array === keys ? keys.first : keys
yield key, options
end
end