Class: CustomTags::MenuGenerator

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/custom_tags.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ MenuGenerator

Returns a new instance of MenuGenerator



44
45
46
47
48
# File 'lib/custom_tags.rb', line 44

def initialize(tag_name, markup, tokens )
  super
  @tag_name = tag_name
  @args = eval('{'+ markup +'}')  
end

Instance Method Details

#create_child(object) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/custom_tags.rb', line 69

def create_child(object)
  str = ""
  str = '<ul id="' + object.name + '">'
  object.children.each do |child|
    str += "<li><a href=#{child.title_sanitized.to_s == '' ? '#' : '/' + child.title_sanitized}>#{child.name}</a>"
    #str += "<li>#{link_to child.name, (child.title_sanitized.to_s == '' ? '#' : '/' + child.title_sanitized)}"
    str += child.children.blank? ? '</li>' : create_child(child) + '</li>'
  end
  str += '</ul>'
end


54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/custom_tags.rb', line 54

def menu_generator(args)
  str = ""
  @menus = $current_website.menus.link_on_menu
  ul = args[:ul] ? "<ul id=#{args[:ul]} class=#{args[:ul]}>" : '<ul>'
  li = args[:li] ? "<li id=#{args[:li]} class=#{args[:li]}>" : '<li>'
  current = args[:current] ? "<li id=#{args[:current]} class=#{args[:current]}>" : '<li>'
  str += ul
  @menus.roots.each do |root|
   str += li + "<a href=#{root.title_sanitized.to_s == '' ? '#' : '/' + root.title_sanitized}>#{root.name}</a>"
   #str += li + "#{link_to root.name, (root.title_sanitized.to_s == '' ? '#' : '/' + root.title_sanitized) }"
   str += root.children.blank? ? '</li>' : create_child(root) + '</li>'
  end
  str += '</ul>'
end

#render(context) ⇒ Object



50
51
52
# File 'lib/custom_tags.rb', line 50

def render(context)
  menu_generator(@args)
end