module Alchemy
module PagesHelper
include Alchemy::BaseHelper
include Alchemy::ElementsHelper
def picture_essence_caption(content)
content.try(:essence).try(:caption)
end
# Renders links to language root pages of all published languages.
#
# @option options linkname [String] ('name') Renders name/code of language, or I18n translation for code.
# @option options show_title [Boolean] (true) Renders title attributes for the links.
# @option options spacer [String] ('') Renders the passed spacer string. You can also overwrite the spacer partial: "alchemy/language_links/_spacer".
# @option options reverse [Boolean] (false) Reverses the ordering of the links.
#
def language_links(options={})
options = {
linkname: 'name',
show_title: true,
spacer: '',
reverse: false
}.merge(options)
languages = Language.published.with_language_root.order("name #{options[:reverse] ? 'DESC' : 'ASC'}")
return nil if languages.count < 2
render(
partial: "alchemy/language_links/language",
collection: languages,
spacer_template: "alchemy/language_links/spacer",
locals: {languages: languages, options: options}
)
end
def language_switches(options={})
ActiveSupport::Deprecation.warn("Used deprecated language_switches helper. It will be removed in Alchemy v3.0. You can use language_links instead.")
language_links(options)
end
def language_switcher(options={})
ActiveSupport::Deprecation.warn("Used deprecated language_switcher helper. It will be removed in Alchemy v3.0. You can use language_links instead.")
language_links(options)
end
# Renders the layout from @page.page_layout. File resists in /app/views/page_layouts/_LAYOUT-NAME.html.erb
def render_page_layout(options={})
render :partial => "alchemy/page_layouts/#{@page.page_layout.downcase}"
rescue ActionView::MissingTemplate
warning("PageLayout: '#{@page.page_layout}' not found. Rendering standard page_layout.")
render :partial => "alchemy/page_layouts/standard"
end
# Renders a partial for current site
#
# Place a rails partial into +app/views/alchemy/site_layouts+
#
# and name it like your site name.
#
# == Example:
#
# <%= render_site_layout %>
#
# renders +app/views/alchemy/site_layouts/_default_site.html.erb+ for the site named "Default Site".
#
def render_site_layout
render current_site
rescue ActionView::MissingTemplate
warning("Site layout for #{current_site.try(:name)} not found. Please run `rails g alchemy:site_layouts`")
return ""
end
# Renders the navigation.
#
# It produces a html
structure with all necessary classes so you can produce every navigation the web uses today.
# I.E. dropdown-navigations, simple mainnavigations or even complex nested ones.
#
# === En detail:
#
#
#
# As you can see: Everything you need.
#
# Not pleased with the way Alchemy produces the navigation structure?
# Then feel free to overwrite the partials (_renderer.html.erb and _link.html.erb) found in +views/navigation/+ or pass different partials via the options +:navigation_partial+ and +:navigation_link_partial+.
#
# === The options are:
#
# :submenu => false # Do you want a nested
structure for the deeper levels of your navigation, or not? Used to display the subnavigation within the mainnaviagtion. E.g. for dropdown menues.
# :all_sub_menues => false # Renders the whole page tree.
# :from_page => @root_page # Do you want to render a navigation from a different page then the current page? Then pass an Page instance or a Alchemy::PageLayout name as string.
# :spacer => nil # A spacer for the entries can be passed. Simple string, or even a complex html structure. E.g: "|".
# :navigation_partial => "navigation/renderer" # Pass a different partial to be taken for the navigation rendering.
# :navigation_link_partial => "navigation/link" # Alchemy places an html link in