Module: ZableHelper
- Includes:
- Zable::WillPaginate
- Defined in:
- app/helpers/zable_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
- #column(name, options = {}, &block) ⇒ Object
- #columns ⇒ Object
- #current_sort_order ⇒ Object
- #link_sort_order(name) ⇒ Object
- #pagination_element(collection, options) ⇒ Object
- #sorted_column?(name) ⇒ Boolean
- #zable(collection, klass, args = {}, &block) ⇒ Object
- #zable_element(args, block, collection, klass, params) ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'app/helpers/zable_helper.rb', line 4 def self.included(base) base.send :include, Zable::Html end |
Instance Method Details
#column(name, options = {}, &block) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/helpers/zable_helper.rb', line 53 def column(name, ={}, &block) col = { :name => name, :title => [:title], :sort => .has_key?(:sort) ? [:sort] : true, :block => block, :sorted? => sorted_column?(name), :sort_order => link_sort_order(name) } zable_columns = controller.request.instance_variable_get :@zable_columns zable_columns << col end |
#columns ⇒ Object
34 35 36 37 38 |
# File 'app/helpers/zable_helper.rb', line 34 def columns controller.request.instance_variable_set :@zable_columns, [] yield controller.request.instance_variable_get :@zable_columns end |
#current_sort_order ⇒ Object
44 45 46 |
# File 'app/helpers/zable_helper.rb', line 44 def current_sort_order params[:sort][:order].downcase.to_sym rescue :asc end |
#link_sort_order(name) ⇒ Object
48 49 50 51 |
# File 'app/helpers/zable_helper.rb', line 48 def link_sort_order(name) return nil unless sorted_column?(name) current_sort_order == :desc ? :asc : :desc end |
#pagination_element(collection, options) ⇒ Object
27 28 29 30 31 32 |
# File 'app/helpers/zable_helper.rb', line 27 def pagination_element(collection, ) content_tag :div, :class => 'brownFilterResultsBox' do page_entries_info(collection, .slice(:entry_name)) << will_paginate(collection, :renderer => LinkWithParamsRenderer.new([:params] || {})) end end |
#sorted_column?(name) ⇒ Boolean
40 41 42 |
# File 'app/helpers/zable_helper.rb', line 40 def sorted_column?(name) params[:sort][:attr] == name.to_s rescue false end |
#zable(collection, klass, args = {}, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'app/helpers/zable_helper.rb', line 8 def zable(collection, klass, args={}, &block) reset_cycle("zable_cycle") html = ''.html_safe #stylesheet_link_tag("zable") html << pagination_element(collection, args.slice(:entry_name, :params)) if args[:paginate] html << zable_element(args, block, collection, klass, args[:params]) html << pagination_element(collection, args.slice(:entry_name, :params)) if args[:paginate] html end |
#zable_element(args, block, collection, klass, params) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'app/helpers/zable_helper.rb', line 18 def zable_element(args, block, collection, klass, params) cols = columns(&block) cols.instance_variable_set :@search_params, controller.request.params[:search] cols.instance_variable_set :@_extra_params, params content_tag(:table, tag_args(args)) do table_header(klass, cols) << table_body(collection, cols, args) end end |