1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00

Merge pull request #552 from apotonick/views-prefix

Add views_prefix Option For Alternative Views Directory
This commit is contained in:
Yuki Nishijima 2014-05-08 23:08:49 -04:00
commit 987ad89cfe
5 changed files with 21 additions and 3 deletions

View file

@ -168,6 +168,11 @@ Run the following generator command, then edit the generated file.
<%= paginate @users, :remote => true %>
This would add <tt>data-remote="true"</tt> to all the links inside.
* specifying an alternative views directory (default is <tt>kaminari/</tt>)
<%= paginate @users, :views_prefix => '../templates/pagination' %>
This would search for partials in <tt>app/views/../templates/pagination</tt>.
* the +link_to_next_page+ and +link_to_previous_page+ helper method
<%= link_to_next_page @items, 'Next Page' %>

View file

@ -0,0 +1 @@
<p><%= current_page %></p>

View file

@ -25,7 +25,7 @@ module Kaminari
h[:right] = outer_window if h[:right] == 0
end
@template, @options = template, options
@theme = @options[:theme] ? "#{@options[:theme]}/" : ''
@theme = @options.delete(:theme)
@window_options.merge! @options
@window_options[:current_page] = @options[:current_page] = PageProxy.new(@window_options, @options[:current_page], nil)

View file

@ -18,12 +18,12 @@ module Kaminari
def initialize(template, options = {}) #:nodoc:
@template, @options = template, options.dup
@param_name = @options.delete(:param_name) || Kaminari.config.param_name
@theme = @options[:theme] ? "#{@options.delete(:theme)}/" : ''
@theme = @options.delete(:theme)
@params = template.params.except(*PARAM_KEY_BLACKLIST).merge(@options.delete(:params) || {})
end
def to_s(locals = {}) #:nodoc:
@template.render :partial => "kaminari/#{@theme}#{self.class.name.demodulize.underscore}", :locals => @options.merge(locals), :formats => [:html]
@template.render :partial => partial_path, :locals => @options.merge(locals), :formats => [:html]
end
def page_url_for(page)
@ -50,6 +50,13 @@ module Kaminari
page_params
end
def partial_path
[@options[:views_prefix] || "kaminari",
@theme,
self.class.name.demodulize.underscore
].compact.join("/")
end
end
# Tag that contains a link

View file

@ -15,6 +15,11 @@ describe 'Kaminari::ActionViewExtension', :if => defined?(Rails) do
lambda { helper.escape_javascript(helper.paginate @users, :params => {:controller => 'users', :action => 'index'}) }.should_not raise_error
end
end
context 'accepts :view_prefixes option' do
subject { helper.paginate @users, :views_prefix => "alternative/kaminari" }
it { should eq("<p>1</p>") }
end
end
describe '#link_to_previous_page' do