# frozen_string_literal: true # 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 class ComfortableMediaSurfer::Content::Tags::Siblings < ComfortableMediaSurfer::Content::Tag attr_reader :locals, :style, :sibs attr_accessor :links def initialize(context:, params: [], source: nil) super @locals = params.extract_options! @style = '' @style = "" if @locals['style'] @exclude = [] @exclude = @locals['exclude'].split(',') if @locals['exclude'] @links = '' # ActiveRecord_Associations_CollectionProxy @sibs = context.self_and_siblings.order(:position).to_ary unless Rails.env == 'development' @sibs.delete_if { |sib| !sib.is_published } end @sibs.delete_if { |sib| @exclude.include? sib.slug } end def content if @sibs.count > 1 @links = '