Class: Locomotive::Steam::Liquid::Tags::Nav

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/locomotive/steam/liquid/tags/nav.rb

Overview

Display the children pages of the site, current page or the parent page. If not precised, nav is applied on the current page. The html output is based on the ul/li tags.

Usage:

nav site % => <ul class=“nav”><li class=“on”><a href=“/features”>Features</a></li></ul>

{% nav site, no_wrapper: true, exclude: ‘contact|about’, id: ‘main-nav’, class: ‘nav’, active_class: ‘on’ }

Constant Summary collapse

Syntax =
/(#{::Liquid::VariableSignature}+)/o

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, options) ⇒ Nav

Returns a new instance of Nav.



21
22
23
24
25
26
27
28
29
# File 'lib/locomotive/steam/liquid/tags/nav.rb', line 21

def initialize(tag_name, markup, options)
  markup =~ Syntax

  @source = ($1 || 'page').gsub(/"|'/, '')

  self.set_options(markup, options)

  super
end

Instance Attribute Details

#current_localeObject

Returns the value of attribute current_locale.



19
20
21
# File 'lib/locomotive/steam/liquid/tags/nav.rb', line 19

def current_locale
  @current_locale
end

#current_pageObject

Returns the value of attribute current_page.



19
20
21
# File 'lib/locomotive/steam/liquid/tags/nav.rb', line 19

def current_page
  @current_page
end

#current_siteObject

Returns the value of attribute current_site.



19
20
21
# File 'lib/locomotive/steam/liquid/tags/nav.rb', line 19

def current_site
  @current_site
end

#page_repositoryObject

Returns the value of attribute page_repository.



19
20
21
# File 'lib/locomotive/steam/liquid/tags/nav.rb', line 19

def page_repository
  @page_repository
end

#servicesObject

Returns the value of attribute services.



19
20
21
# File 'lib/locomotive/steam/liquid/tags/nav.rb', line 19

def services
  @services
end

Instance Method Details

#render(context) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/locomotive/steam/liquid/tags/nav.rb', line 31

def render(context)
  self.set_vars_from_context(context)

  set_template_if_asked

  # get all the children of a source: site (index page), parent or page.
  pages     = children_of(fetch_starting_page)
  _output   = self.build_entries_output(pages, context)

  if self.no_wrapper?
   _output
  else
    self.render_tag(:nav, id: @_options[:id], css: @_options[:class]) do
      self.render_tag(:ul) { _output }
    end
  end
end