Class: Occams::Content::Tag::Siblings
- Inherits:
-
Occams::Content::Tag
- Object
- Occams::Content::Tag
- Occams::Content::Tag::Siblings
- Defined in:
- lib/occams/content/tags/siblings.rb
Overview
Nav Tag for rendering previous and next sibling links relative to current page
{{ cms:siblings }}
{{ cms:siblings style: "font-style: italic", exclude: "404-page, search-page" }}
To customize your siblings style, add a ‘siblings’ id to your CSS, e.g #siblings
color: #006633;
font-size: 95%;
margin-top: 12px;
font-style: italic;
and/or pass in style overrides with the ‘style’ parameter (see above)
To exclude siblings, list their slugs with the ‘exclude’ parameter as comma-delimited string, e.g. as above - exclude: “404-page, search-page”
style and exclude parameters are optional
Instance Attribute Summary collapse
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
Attributes inherited from Occams::Content::Tag
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(context:, params: [], source: nil) ⇒ Siblings
constructor
A new instance of Siblings.
Methods inherited from Occams::Content::Tag
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ Siblings
Returns a new instance of Siblings.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/occams/content/tags/siblings.rb', line 23 def initialize(context:, params: [], source: nil) super @locals = params. @style = '' @style = "<style>#siblings {#{@locals['style']}}</style>" if @locals['style'] @exclude = [] @exclude = @locals['exclude'].split(',') if @locals['exclude'] @links = '<div id="siblings">' prevp = false sibs = context.self_and_siblings.sort_by(&:position) sibs.delete_if { |sib| @exclude.include? sib.slug } page_idx = sibs.index(context) sibs.each do |sib| sib_idx = sibs.index(sib) next if sibs.index(sib) == page_idx next if Rails.env == 'production' && !sib.is_published if sib_idx == page_idx - 1 @links += "<a href=#{sib.url(relative: true)}>#{sib.label}</a> « <em>Previous</em> • " prevp = true elsif sib_idx == page_idx + 1 @links += '•' unless prevp @links += "<em>Next</em> » <a href=#{sib.url(relative: true)}>#{sib.label}</a>" end end @links += '</div>' end |
Instance Attribute Details
#links ⇒ Object (readonly)
Returns the value of attribute links.
21 22 23 |
# File 'lib/occams/content/tags/siblings.rb', line 21 def links @links end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
21 22 23 |
# File 'lib/occams/content/tags/siblings.rb', line 21 def locals @locals end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
21 22 23 |
# File 'lib/occams/content/tags/siblings.rb', line 21 def style @style end |
Instance Method Details
#content ⇒ Object
52 53 54 |
# File 'lib/occams/content/tags/siblings.rb', line 52 def content format("#{@style}#{@links}") end |