Modifications for menu in Design
This commit is contained in:
parent
98d6c3fa15
commit
492f691469
|
@ -12,7 +12,7 @@ class Admin::ItemsController < ApplicationController
|
|||
if params[:item_id]
|
||||
@item = Item.find(params[:item_id])
|
||||
else
|
||||
@item = Item.first(:conditions => {:parent_id => nil})
|
||||
@item = get_homepage
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -73,5 +73,9 @@ class ApplicationController < ActionController::Base
|
|||
''
|
||||
end
|
||||
end
|
||||
|
||||
def get_homepage
|
||||
Item.first(:conditions => {:parent_id => nil})
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class DesignFile
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
mount_uploader :file, AssetUploader
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class Layout < DesignFile
|
||||
include Parser
|
||||
embeds_one :menu
|
||||
embedded_in :design
|
||||
|
||||
attr_reader :content
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class Menu
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :levels, :type => Integer
|
||||
field :values, :type => Hash
|
||||
|
||||
embedded_in :layout
|
||||
|
||||
end
|
Binary file not shown.
|
@ -205,9 +205,45 @@ module Parser
|
|||
ret << item.i18n_variable[I18n.locale]
|
||||
ret << "</a>"
|
||||
end
|
||||
c.define_tag 'menu' do |tag|
|
||||
home = get_homepage
|
||||
menu = page.design.layout.menu
|
||||
menu_level(home, 1, menu)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def menu_level(page, current, menu)
|
||||
if current <= menu.levels
|
||||
res = "<ul id="
|
||||
res << menu.values["id_#{current}"]
|
||||
res << " class="
|
||||
res << menu.values["class_#{current}"]
|
||||
res << ">"
|
||||
i = nil
|
||||
i = 1 if menu.values["li_recursive_#{current}"]
|
||||
if current == 1 && menu.values['home'].eql?('true')
|
||||
res << menu_li(page, current, menu, i)
|
||||
i += 1 if i
|
||||
end
|
||||
page.children.each do |child|
|
||||
res << menu_li(child, current, menu, i)
|
||||
i += 1 if i
|
||||
end
|
||||
res << "</ul>"
|
||||
end
|
||||
end
|
||||
|
||||
def menu_li(page, current, menu, i)
|
||||
res = "<li class="
|
||||
res << menu.values["li_class_#{current}"]
|
||||
res << "_#{i}" if i
|
||||
res << ">"
|
||||
res << page.name
|
||||
res << menu_level(page, current + 1, menu) if page.children.size > 0
|
||||
res << "</li>"
|
||||
end
|
||||
|
||||
#=============
|
||||
def parse_layout_layout_part(layout)
|
||||
content = layout.content.force_encoding('UTF-8')
|
||||
|
@ -222,6 +258,14 @@ module Parser
|
|||
end
|
||||
c.define_tag 'stylesheets' do |tag|
|
||||
end
|
||||
c.define_tag 'menu' do |tag|
|
||||
layout.build_menu(:levels => 0, :values => {}) unless layout.menu
|
||||
layout.menu.levels = i = tag.attr['level'].to_i
|
||||
layout.menu.values.merge!({'home' => tag.attr['home']}) if i == 1
|
||||
layout.menu.values.merge!({"id_#{i}" => tag.attr['id'], "class_#{i}" => tag.attr['class'], "li_class_#{i}" => tag.attr['li_class'], "li_recursive_#{i}" => tag.attr['li_recursive']})
|
||||
layout.menu.save
|
||||
tag.expand
|
||||
end
|
||||
c.define_tag 'layout_part' do |tag|
|
||||
data={}
|
||||
data[:class_tag]=tag.attr['class'].to_s
|
||||
|
|
Loading…
Reference in New Issue