Class: Locomotive::Steam::Liquid::Tags::LocaleSwitcher

Inherits:
Liquid::Tag
  • Object
show all
Includes:
Concerns::Attributes, Concerns::I18nPage
Defined in:
lib/locomotive/steam/liquid/tags/locale_switcher.rb

Overview

Display the links to change the locale of the current page

Usage:

locale_switcher % => <div id=“locale-switcher”><a href=“/features” class=“current en”>Features</a><a href=“/fr/fonctionnalites” class=“fr”>Fonctionnalités</a></div>

{% locale_switcher label: locale, sep: ‘ - ’ }

options:

- label: iso (de, fr, en, ...etc), locale (Deutsch, Français, English, ...etc), title (page title)
- sep: piece of html code separating 2 locales

notes:

- "iso" is the default choice for label
- " | " is the default separating code

Instance Attribute Summary collapse

Attributes included from Concerns::Attributes

#raw_attributes

Instance Method Summary collapse

Methods included from Concerns::I18nPage

#change_page_locale

Constructor Details

#initialize(tag_name, markup, options) ⇒ LocaleSwitcher

Returns a new instance of LocaleSwitcher.



30
31
32
33
34
# File 'lib/locomotive/steam/liquid/tags/locale_switcher.rb', line 30

def initialize(tag_name, markup, options)
  super

  parse_attributes(markup, label: 'iso', sep: ' | ')
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



28
29
30
# File 'lib/locomotive/steam/liquid/tags/locale_switcher.rb', line 28

def attributes
  @attributes
end

#current_localeObject (readonly)

Returns the value of attribute current_locale.



28
29
30
# File 'lib/locomotive/steam/liquid/tags/locale_switcher.rb', line 28

def current_locale
  @current_locale
end

#pageObject (readonly)

Returns the value of attribute page.



28
29
30
# File 'lib/locomotive/steam/liquid/tags/locale_switcher.rb', line 28

def page
  @page
end

#siteObject (readonly)

Returns the value of attribute site.



28
29
30
# File 'lib/locomotive/steam/liquid/tags/locale_switcher.rb', line 28

def site
  @site
end

#url_builderObject (readonly)

Returns the value of attribute url_builder.



28
29
30
# File 'lib/locomotive/steam/liquid/tags/locale_switcher.rb', line 28

def url_builder
  @url_builder
end

Instance Method Details

#render(context) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/locomotive/steam/liquid/tags/locale_switcher.rb', line 36

def render(context)
  evaluate_attributes(context)

  set_vars_from_context(context)

  %{<div id="locale-switcher">#{build_site_locales}</div>}
end