Merge pull request #327 from belighted/2.0.0.rc
Add nav compatibility with twitter menu dropdown
This commit is contained in:
commit
58c5e9e238
@ -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, :class => '', :active_class => 'on' }
|
@options = { :id => 'nav', :depth => 1, :class => '', :active_class => 'on', :bootstrap => false }
|
||||||
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]
|
||||||
@ -90,21 +90,37 @@ module Locomotive
|
|||||||
|
|
||||||
label = %{#{icon if @options[:icon] != 'after' }#{title}#{icon if @options[:icon] == 'after' }}
|
label = %{#{icon if @options[:icon] != 'after' }#{title}#{icon if @options[:icon] == 'after' }}
|
||||||
|
|
||||||
output = %{<li id="#{page.slug.dasherize}-link" class="link#{selected} #{css}">}
|
dropdow = ""
|
||||||
output << %{<a href="/#{@site.localized_page_fullpath(page)}">#{label}</a>}
|
link_options = ""
|
||||||
|
href = "/#{page.fullpath}"
|
||||||
|
caret = ""
|
||||||
|
|
||||||
|
if render_children_for_page?(page, depth) && @options[:bootstrap] == "true"
|
||||||
|
dropdow = "dropdown"
|
||||||
|
link_options = %{class="dropdown-toggle" data-toogle="dropdown"}
|
||||||
|
href = "#"
|
||||||
|
caret = %{<b class="caret"></b>}
|
||||||
|
end
|
||||||
|
|
||||||
|
output = %{<li id="#{page.slug.to_s.dasherize}-link" class="link#{selected} #{css} #{dropdow}">}
|
||||||
|
output << %{<a href="#{href}" #{link_options}>#{label} #{caret}</a>}
|
||||||
output << render_entry_children(page, depth.succ) if (depth.succ <= @options[:depth].to_i)
|
output << render_entry_children(page, depth.succ) if (depth.succ <= @options[:depth].to_i)
|
||||||
output << %{</li>}
|
output << %{</li>}
|
||||||
|
|
||||||
output.strip
|
output.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_children_for_page?(page, depth)
|
||||||
|
depth.succ <= @options[:depth].to_i && page.children.reject { |c| !include_page?(c) }.any?
|
||||||
|
end
|
||||||
|
|
||||||
# Recursively creates a nested unordered list for the depth specified
|
# Recursively creates a nested unordered list for the depth specified
|
||||||
def render_entry_children(page, depth)
|
def render_entry_children(page, depth)
|
||||||
output = %{}
|
output = %{}
|
||||||
|
|
||||||
children = page.children_with_minimal_attributes( @options[:add_attributes] ).reject { |c| !include_page?(c) }
|
children = page.children_with_minimal_attributes( @options[:add_attributes] ).reject { |c| !include_page?(c) }
|
||||||
if children.present?
|
if children.present?
|
||||||
output = %{<ul id="#{@options[:id]}-#{page.slug.dasherize}">}
|
output = %{<ul id="#{@options[:id]}-#{page.slug.to_s.dasherize}" class="#{@options[:bootstrap] == "true" ? "dropdown-menu" : ""}">}
|
||||||
children.each do |c, page|
|
children.each do |c, page|
|
||||||
css = []
|
css = []
|
||||||
css << 'first' if children.first == c
|
css << 'first' if children.first == c
|
||||||
|
Loading…
Reference in New Issue
Block a user