Class: Datewari::Helper::LinkRenderer
- Inherits:
-
Object
- Object
- Datewari::Helper::LinkRenderer
- Defined in:
- lib/datewari/helper/link_renderer.rb
Instance Method Summary collapse
- #container ⇒ Object
- #date_label(date, scope) ⇒ Object
- #date_link(date) ⇒ Object
- #date_param(date) ⇒ Object
- #gap ⇒ Object
-
#initialize(config, paginator, template) ⇒ LinkRenderer
constructor
A new instance of LinkRenderer.
- #next_link ⇒ Object
- #prev_link ⇒ Object
- #render ⇒ Object
- #separator ⇒ Object
- #url(date) ⇒ Object
Constructor Details
#initialize(config, paginator, template) ⇒ LinkRenderer
Returns a new instance of LinkRenderer.
4 5 6 7 8 |
# File 'lib/datewari/helper/link_renderer.rb', line 4 def initialize(config, paginator, template) @config = config @paginator = paginator @template = template end |
Instance Method Details
#container ⇒ Object
30 31 32 33 34 |
# File 'lib/datewari/helper/link_renderer.rb', line 30 def container content_tag :div, class: 'pagination' do yield end end |
#date_label(date, scope) ⇒ Object
68 69 70 |
# File 'lib/datewari/helper/link_renderer.rb', line 68 def date_label(date, scope) date.strftime(@config["#{scope}_format".to_sym]) end |
#date_link(date) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/datewari/helper/link_renderer.rb', line 52 def date_link(date) if date == @paginator.current_date content_tag :em, date_label(date, @paginator.scope), class: 'current' else link_to date_label(date, @paginator.scope), url(date) end end |
#date_param(date) ⇒ Object
72 73 74 |
# File 'lib/datewari/helper/link_renderer.rb', line 72 def date_param(date) date.strftime('%Y-%m-%d') end |
#gap ⇒ Object
60 61 62 |
# File 'lib/datewari/helper/link_renderer.rb', line 60 def gap content_tag :span, @config[:page_gap], class: 'gap' end |
#next_link ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/datewari/helper/link_renderer.rb', line 44 def next_link if (date = @paginator.next_date) link_to @config[:next_label], url(date), class: 'next_page', rel: 'next' else content_tag :span, @config[:next_label], class: 'next_page disabled' end end |
#prev_link ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/datewari/helper/link_renderer.rb', line 36 def prev_link if (date = @paginator.prev_date) link_to @config[:previous_label], url(date), class: 'previous_page', rel: 'prev' else content_tag :span, @config[:previous_label], class: 'previous_page disabled' end end |
#render ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/datewari/helper/link_renderer.rb', line 10 def render return '' if @paginator.pages.size < 2 container do parts = PartsBuilder.new(@config, @paginator).build parts.map { |part| case part when :prev prev_link when :next next_link when :gap gap if @config[:page_links] else date_link(part) if @config[:page_links] end }.compact.join(separator).html_safe end end |
#separator ⇒ Object
64 65 66 |
# File 'lib/datewari/helper/link_renderer.rb', line 64 def separator content_tag :span, @config[:link_separator], class: 'separator' end |
#url(date) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/datewari/helper/link_renderer.rb', line 76 def url(date) date_param = if date == @paginator.pages.first nil else date_param(date) end request_params = @template.request.params.except(:controller, :action) url_for(request_params.merge(@config[:params]).merge(@config[:param_name] => date_param)) end |