enhance the nav tag (allow custom css classes for the list and the selected menu item) + clean the locomotive.rb template file

This commit is contained in:
Didier Lafforgue 2012-02-15 18:26:58 +01:00
parent 3b5d04238f
commit 87c8f3bfd7
2 changed files with 10 additions and 14 deletions

View File

@ -1,6 +1,6 @@
Locomotive.configure do |config| Locomotive.configure do |config|
# A single locomotive instance can serve one single site or many. # A single locomotiveCMS instance can serve one single site or many.
# If you want to run many different websites, you will have to specify # If you want to run many different websites, you will have to specify
# your own domain name (ex: locomotivehosting.com). # your own domain name (ex: locomotivehosting.com).
# #
@ -16,24 +16,20 @@ Locomotive.configure do |config|
# end # end
config.multi_sites = false config.multi_sites = false
# configure the hosting target for the production environment. Locomotive can be installed in: # configure the hosting target for the production environment. LocomotiveCMS can be installed in:
# - your own server # - your own server
# - Heroku (you need to create an account in this case) # - Heroku (you need to create an account in this case)
# - Bushi.do (see the bushi.do website for more explanations) # - Bushi.do (see the bushi.do website for more explanations)
# #
# the possible options are: server, heroku, bushido or auto (default) # the possible options are: server, heroku, bushido or auto (default)
# if you select 'auto', Locomotive will look after specific ENV variables to check # if you select 'auto', LocomotiveCMS will look after specific ENV variables to check
# the matching platform (Heroku and Bushido set their own ENV variables). # the matching platform (Heroku and Bushido set their own ENV variables).
# #
config.hosting = :auto config.hosting = :auto
# In case you host Locomotive in Heroku, the engine uses the heroku api to add / remove domains. # In case you host LocomotiveCMS in Heroku, the engine uses the heroku api to add / remove domains.
# there are 2 ways of passing heroku credentials to Locomotive
# - from ENV variables: HEROKU_LOGIN & HEROKU_PASSWORD
# - from this file, see the example below and uncomment it if needed
# config.heroku = { # config.heroku = {
# :login => '<your_heroku_login>', # :api_key => '<your_heroku_api_key>
# :password => '<your_heroku_password>'
# } # }
# configure how many items we display in sub menu in the "Contents" section. # configure how many items we display in sub menu in the "Contents" section.
@ -52,7 +48,7 @@ Locomotive.configure do |config|
config.enable_logs = true config.enable_logs = true
# configure the e-mail address which will be shown in the DeviseMailer, NotificationMailer, ...etc # configure the e-mail address which will be shown in the DeviseMailer, NotificationMailer, ...etc
# if you do not put the domain name in the email, Locomotive will take the default domain name depending # if you do not put the domain name in the email, LocomotiveCMS will take the default domain name depending
# on your deployment target (server, Heroku, Bushido, ...etc) # on your deployment target (server, Heroku, Bushido, ...etc)
# #
# Ex: # Ex:

View File

@ -10,7 +10,7 @@ module Locomotive
# #
# {% nav site %} => <ul class="nav"><li class="on"><a href="/features">Features</a></li></ul> # {% nav site %} => <ul class="nav"><li class="on"><a href="/features">Features</a></li></ul>
# #
# {% nav site, no_wrapper: true, depth: 1, exclude: 'contact|about', id: 'main-nav' } # {% nav site, no_wrapper: true, exclude: 'contact|about', id: 'main-nav', class: 'nav', active_class: 'on' }
# #
class Nav < ::Liquid::Tag class Nav < ::Liquid::Tag
@ -19,7 +19,7 @@ module Locomotive
def initialize(tag_name, markup, tokens, context) def initialize(tag_name, markup, tokens, context)
if markup =~ Syntax if markup =~ Syntax
@source = ($1 || 'page').gsub(/"|'/, '') @source = ($1 || 'page').gsub(/"|'/, '')
@options = { :id => 'nav', :depth => 1 } @options = { :id => 'nav', :depth => 1, :class => '', :active_class => 'on' }
markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') } markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') }
@options[:exclude] = Regexp.new(@options[:exclude]) if @options[:exclude] @options[:exclude] = Regexp.new(@options[:exclude]) if @options[:exclude]
@ -46,7 +46,7 @@ module Locomotive
output = children_output.join("\n") output = children_output.join("\n")
if @options[:no_wrapper] != 'true' if @options[:no_wrapper] != 'true'
output = %{<ul id="#{@options[:id]}">\n#{output}</ul>} output = %{<ul id="#{@options[:id]}" class="#{@options[:class]}">\n#{output}</ul>}
end end
output output
@ -71,7 +71,7 @@ module Locomotive
# Returns a list element, a link to the page and its children # Returns a list element, a link to the page and its children
def render_entry_link(page, css, depth) def render_entry_link(page, css, depth)
selected = @page.fullpath =~ /^#{page.fullpath}/ ? ' on' : '' selected = @page.fullpath =~ /^#{page.fullpath}/ ? " #{@options[:active_class]}" : ''
icon = @options[:icon] ? '<span></span>' : '' icon = @options[:icon] ? '<span></span>' : ''
label = %{#{icon if @options[:icon] != 'after' }#{page.title}#{icon if @options[:icon] == 'after' }} label = %{#{icon if @options[:icon] != 'after' }#{page.title}#{icon if @options[:icon] == 'after' }}