Class: Occams::Content::Tag::Children

Inherits:
Occams::Content::Tag show all
Defined in:
lib/occams/content/tags/children.rb

Overview

Nav Tag for unordered list of links to the children of the current page

{{ cms:children }}
{{ cms:children style: "font-weight: bold", exclude: "404-page, search-page" }}

To customize your children style, add a ‘children’ id to your CSS, e.g #children

color: #006633;
font-size: 90%;
margin-bottom: 4px;
font-style: italic;

and/or pass in style overrides with the ‘style’ parameter, as above

To exclude children, list their slugs with the ‘exclude’ parameter as comma-delimited string, e.g. as above - exclude: “404-page, search-page”

Instance Attribute Summary collapse

Attributes inherited from Occams::Content::Tag

#context, #params, #source

Instance Method Summary collapse

Methods inherited from Occams::Content::Tag

#allow_erb?, #nodes, #render

Constructor Details

#initialize(context:, params: [], source: nil) ⇒ Children

Returns a new instance of Children.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/occams/content/tags/children.rb', line 22

def initialize(context:, params: [], source: nil)
  super
  @locals = params.extract_options!
  @style  = ''
  @style  = "<style>#children {#{@locals['style']}}</style>\n" if @locals['style']
  @exclude = []
  @exclude = @locals['exclude'].split(',') if @locals['exclude']
  @list = ''
  # ActiveRecord_Associations_CollectionProxy
  @page_children = context.children.order(:position).to_ary
  if Rails.env == 'production'
    @page_children.delete_if { |child| !child.is_published }
  end
  @page_children.delete_if { |child| @exclude.include? child.slug }
end

Instance Attribute Details

#listObject

Returns the value of attribute list.



20
21
22
# File 'lib/occams/content/tags/children.rb', line 20

def list
  @list
end

#localsObject (readonly)

Returns the value of attribute locals.



19
20
21
# File 'lib/occams/content/tags/children.rb', line 19

def locals
  @locals
end

#page_childrenObject (readonly)

Returns the value of attribute page_children.



19
20
21
# File 'lib/occams/content/tags/children.rb', line 19

def page_children
  @page_children
end

#styleObject (readonly)

Returns the value of attribute style.



19
20
21
# File 'lib/occams/content/tags/children.rb', line 19

def style
  @style
end

Instance Method Details

#contentObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/occams/content/tags/children.rb', line 38

def content
  if @page_children.any?
    @list = "<ul id=\"children\">\n"
    @page_children.each do |c|
      @list += "  <li><a href=#{c.url(relative: true)}>#{c.label}</a></li>\n"
    end
    @list += '</ul>'
  end
  format("#{@style}#{@list}")
end