New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kaminari and its helpers works well around Sinatra(and also Padrino) with least dependency #179

Merged
merged 2 commits into from Dec 10, 2011

Conversation

Projects
None yet
4 participants
@udzura
Member

udzura commented Nov 22, 2011

こんにちは。

twitter 等でお世話になりました。近藤うちお(@udzura)です。

このたび、 「最低限の依存」で kaminari gem とそのヘルパーを Sinatra で動かせるようになりました。 (super thanks to #161 & #174)

主な仕様は以下のとおりです。

  • gem 'kaminari', :require => 'kaminari/sinatra' で Sinatra でも pagination scopes が利用可能になる
  • Kaminari::Hooks は良いアイデアだと思ったのでマージ
  • activesupport actionpack railties に依存(たとえSinatraでも)
  • Sinatra での link_to_next_page ヘルパーは、ブロックをとらず :placeholder オプションを取る

(素の ERB, Erubis では

   <%= link_to_next_page @users, 'Next Page' do %>
     <span>No More Pages</span>
   <% end %>

がSyntaxErrorになってしまうためです。。)

  • Sinatra::Base を継承したクラスで register Kaminari::Helpers::SinatraHelpers を宣言すれば、ヘルパーが使用可能になる。ただし、 padrino-helper がロード可能な状態でないと警告が出て何もしない。
  • テストあります

既存のテストは壊していないことを確認しています。

よろしければマージしていただければ、嬉しく思います。ご確認ください。

---- locale :en

Hi, Matsuda-san.

I am Uchio Kondo (@udzura), thank you for mentions on twitter.

This request is a patch to make kaminari and its helpers work well with Sinatra with "least" dependency (super thanks to #161 & #174)

Major specifications are below:

  • With gem 'kaminari', :require => 'kaminari/sinatra', pagination scopes are abailable for Sinatra.
  • Kaminari::Hooks is a good idea, then merged.
  • Dependent on %{activesupport actionpack railties} even if they use Sinatra.
  • link_to_next_page helper method takes a :placeholder option, not a block for Sinatra.

( This is because below causes a Syntax Error:

   <%= link_to_next_page @users, 'Next Page' do %>
     <span>No More Pages</span>
   <% end %>

for a naive ERB and Erubis. )

  • You can register Kaminari::Helpers::SinatraHelpers, but if padrino-helper wouldn't be loadable it'd do nothing with warnings.
  • With basic tests.

And existing tests doesn't seem to be broken.

I'm happy if you accept the request, so would you check it out?

@martijn

This comment has been minimized.

Show comment
Hide comment
@martijn

martijn Nov 24, 2011

+1
Works beautifully in my Padrino 0.10.5 app. Thank you!

martijn commented Nov 24, 2011

+1
Works beautifully in my Padrino 0.10.5 app. Thank you!

@hooopo

This comment has been minimized.

Show comment
Hide comment
@hooopo

hooopo Mar 7, 2013

Thanks. but this will only render partials in gem path, and what to do with custom tag view in app(eg. myapp/app/views/kaminari/_paginator.html.erb) ?

hooopo commented on lib/kaminari/helpers/sinatra_helper.rb in 1da155b Mar 7, 2013

Thanks. but this will only render partials in gem path, and what to do with custom tag view in app(eg. myapp/app/views/kaminari/_paginator.html.erb) ?

@udzura udzura referenced this pull request May 2, 2013

Merged

Fix tests for sinatra #388

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment