Sha256: e2b544a1fdc7a74f09026390d41ccab8af77f522f68a47a735f35098274ae0f5
Contents?: true
Size: 1.82 KB
Versions: 3
Compression:
Stored size: 1.82 KB
Contents
module Listings # = Helpers module ActionViewExtensions def render_listing(key, options = {}) options.reverse_merge! :params => {} params_for_listing = {:listing => key}.merge(params).merge(options[:params]).with_indifferent_access listing = prepare_listing(params_for_listing, self) res = listings_partial_render 'listing', listing Kaminari::Helpers::Tag.paginate_with_listings(nil) res end def listings_link_to_filter(text, key, value) link_to text, '#', onclick: "$(this).closest('.listing').trigger('listings:filter:key:set', ['#{key}', '#{escape_javascript(value)}']);return false;" end def listings_partial_render(view, listing, options = {}) prefix = [ "listings/#{listing.name}", "listings/#{listing.theme}", "listings" ].select { |p| lookup_context.exists?("#{p}/_#{view}") }.first render "#{prefix}/#{view}", options.merge(listing: listing) end def prepare_listing(params, view_context, paging = true) params.delete :controller params.delete :action Kaminari::Helpers::Tag.paginate_with_listings(view_context.listings) listing_class = lookup_listing_class(params[:listing]) listing_class.new.tap do |listing| _prepare_view_context view_context listing.view_context = view_context if !paging listing.page_size = :none end listing.query_items(params) end end def lookup_listing_class(name) "#{name}_listing".classify.constantize end def _prepare_view_context(view_context) # forward methods from this view context to main app if they are not found view_context.class.send(:define_method, 'method_missing') do |m, *args, &block| view_context.main_app.send(m, *args, &block) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
listings-0.1.7 | lib/listings/action_view_extensions.rb |
listings-0.1.6 | lib/listings/action_view_extensions.rb |
listings-0.1.5 | lib/listings/action_view_extensions.rb |