Module: Searchgasm::Helpers::ControlTypes::Links
- Defined in:
- lib/searchgasm/helpers/control_types/links.rb
Instance Method Summary collapse
-
#order_as_links(options = {}) ⇒ Object
Creates a group of links that ascend or descend the data.
-
#order_by_links(options = {}) ⇒ Object
Creates a group of links that order the data by a column or columns.
-
#page_links(options = {}) ⇒ Object
Creates a group of links that paginate through the data.
-
#per_page_links(options = {}) ⇒ Object
Creates a group of links that limit how many items are on each page.
Instance Method Details
#order_as_links(options = {}) ⇒ Object
Creates a group of links that ascend or descend the data. All that this does is loop through the :choices option and call order_as_link and then glue it all together.
Examples
order_as_links
order_as_links(:choices => [:ascending, :descending])
Options
Please look at order_as_link. All options there are applicable here and are passed onto each option.
-
:choices
– default: [“asc”, “desc”], the choices to loop through when calling order_as_link
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/searchgasm/helpers/control_types/links.rb', line 43 def order_as_links( = {}) add_order_as_links_defaults!() = .deep_dup .delete(:choices) html = "" [:choices].each do |choice| = links_option.deep_dup text, value = option_text_and_value(choice) [:text] ||= text html += order_as_link(value, ) end html end |
#order_by_links(options = {}) ⇒ Object
Creates a group of links that order the data by a column or columns. All that this does is loop through the :choices option and call order_by_link and then glue it all together.
Examples
order_by_links
order_by_links(:choices => [:name, {:orders => {:line_items => :total}}, :email])
Options
Please look at order_by_link. All options there are applicable here and are passed onto each option.
-
:choices
– default: the models column names, the choices to loop through when calling order_by_link
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/searchgasm/helpers/control_types/links.rb', line 17 def order_by_links( = {}) add_order_by_links_defaults!() = .deep_dup .delete(:choices) html = "" [:choices].each do |choice| = links_option.deep_dup text, value = option_text_and_value(choice) [:text] ||= text html += order_by_link(value, ) end html end |
#page_links(options = {}) ⇒ Object
Creates a group of links that paginate through the data. Kind of like a flickr page navigation. This one has some nifty options.
Examples
page_links
page_links(:first => "<< First", :last => "Last >>")
Classes and tags
If the user is on the current page they will get a <span> tag, not an <a> tag. If they are on the first page the “first” and “prev” options will be a <span> also. The same goes for “next” and “last” if the user is on the last page. Other than that each element will come with a CSS class so you can style it to your liking. Somtimes the easiest way to understand this Is to either look at the example (linked in the README) or try it out and view the HTML source. It’s pretty simple, but here are the explanations:
-
page
- This is in every element, span or a. -
first_page
- This is for the “first page” element only. -
prev_page
- This is for the “prev page” element only. -
current_page
- This is for the current page element -
next_page
- This is for the “next page” element only. -
last_page
- This is for the “last page” element only. -
disabled_page
- Any element that is a span instead of an a tag.
Options
Please look at per_page_link. All options there are applicable here and are passed onto each option.
-
:inner_spread
– default: 3, set to nil to show all pages, set 0 to show no page links. This represents how many choices available on each side of the current page -
:outer_spread
– default: 1, set to nil to disable, set to 0 show no outer spread but the separator will still be present. This represents how many choices are in the “outer” spread. -
:prev
– default: “< Prev”, set to nil to omit. This is an extra link on the left side of the page links that will go to the previous page -
:next
– default: “Next >”, set to nil to omit. This is an extra link on the right side of the page links that will go to the next page -
:first
– default: nil, set to nil to omit. This is an extra link on thefar left side of the page links that will go to the first page -
:last
– default: nil, set to nil to omit. This is an extra link on the far right side of the page links that will go to the last page
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/searchgasm/helpers/control_types/links.rb', line 115 def page_links( = {}) add_page_links_defaults!() return if [:last_page] <= 1 inner_spread_start = inner_spread_end = lower_gap = lower_outer_spread_start = lower_outer_spread_end = upper_gap = upper_outer_spread_start = upper_outer_spread_end = 0 if ![:inner_spread].blank? inner_spread_start = [:current_page] - [:inner_spread] inner_spread_start = [:first_page] if inner_spread_start < [:first_page] inner_spread_end = [:current_page] + [:inner_spread] inner_spread_end = [:last_page] if inner_spread_end > [:last_page] if ![:outer_spread].blank? lower_gap = inner_spread_start - [:first_page] if lower_gap > 0 lower_outer_spread_start = [:first_page] lower_outer_spread_end = [:outer_spread] > lower_gap ? lower_gap : [:outer_spread] end upper_gap = [:last_page] - inner_spread_end if upper_gap > 0 upper_outer_spread_start = [:last_page] - ([:outer_spread] > upper_gap ? upper_gap : [:outer_spread]) + 1 upper_outer_spread_end = [:last_page] end end else inner_spread_start = [:first_page] inner_spread_end = [:last_page] end html = "" html += span_or_page_link(:first, .deep_dup, [:current_page] == [:first_page]) if [:first] html += span_or_page_link(:prev, .deep_dup, [:current_page] == [:first_page]) if [:prev] if lower_gap > 0 (lower_outer_spread_start..lower_outer_spread_end).each { |page| html += span_or_page_link(page, .deep_dup, false) } html += content_tag(:span, "…", [:html]) if (inner_spread_start - lower_outer_spread_end) > 1 end (inner_spread_start..inner_spread_end).each { |page| html += span_or_page_link(page, .deep_dup, page == [:current_page]) } if upper_gap > 0 html += content_tag(:span, "…", [:html]) if (upper_outer_spread_start - inner_spread_end) > 1 (upper_outer_spread_start..upper_outer_spread_end).each { |page| html += span_or_page_link(page, .deep_dup, false) } end html += span_or_page_link(:next, .deep_dup, [:current_page] == [:last_page]) if [:next] html += span_or_page_link(:last, .deep_dup, [:current_page] == [:last_page]) if [:last] html end |
#per_page_links(options = {}) ⇒ Object
Creates a group of links that limit how many items are on each page. All that this does is loop through the :choices option and call per_page_link and then glue it all together.
Examples
per_page_links
per_page_links(:choices => [25, 50, nil])
Options
Please look at per_page_link. All options there are applicable here and are passed onto each option.
-
:choices
– default: [[“10 per page”, 10], [“25 per page”, 25], [“50 per page”, 50], [“100 per page”, 100], [“150 per page”, 150], [“200 per page”, 200], [“Show all”, nil]]
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/searchgasm/helpers/control_types/links.rb', line 69 def per_page_links( = {}) add_per_page_links_defaults!() = .deep_dup .delete(:choices) html = "" [:choices].each do |choice| = .deep_dup text, value = option_text_and_value(choice) [:text] ||= text searchgasm_add_class!([:html], Config.helpers.order_by_links_ordering_by_class_name) if [:search_obj].per_page == value html += per_page_link(value, ) end html end |