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.
6 7 8 9 10 |
# File 'lib/datewari/helper/link_renderer.rb', line 6 def initialize(config, paginator, template) @config = config @paginator = paginator @template = template end |
Instance Method Details
#container ⇒ Object
32 33 34 35 36 |
# File 'lib/datewari/helper/link_renderer.rb', line 32 def container content_tag :div, class: 'pagination' do yield end end |
#date_label(date, scope) ⇒ Object
70 71 72 |
# File 'lib/datewari/helper/link_renderer.rb', line 70 def date_label(date, scope) date.strftime(@config["#{scope}_format".to_sym]) end |
#date_link(date) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/datewari/helper/link_renderer.rb', line 54 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
74 75 76 |
# File 'lib/datewari/helper/link_renderer.rb', line 74 def date_param(date) date.strftime('%Y-%m-%d') end |
#gap ⇒ Object
62 63 64 |
# File 'lib/datewari/helper/link_renderer.rb', line 62 def gap content_tag :span, @config[:page_gap], class: 'gap' end |
#next_link ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/datewari/helper/link_renderer.rb', line 46 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
38 39 40 41 42 43 44 |
# File 'lib/datewari/helper/link_renderer.rb', line 38 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
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/datewari/helper/link_renderer.rb', line 12 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
66 67 68 |
# File 'lib/datewari/helper/link_renderer.rb', line 66 def separator content_tag :span, @config[:link_separator], class: 'separator' end |
#url(date) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/datewari/helper/link_renderer.rb', line 78 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 |