diff --git a/app/controllers/admin/items_controller.rb b/app/controllers/admin/items_controller.rb index 19fbd56d..9c9f81e5 100644 --- a/app/controllers/admin/items_controller.rb +++ b/app/controllers/admin/items_controller.rb @@ -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 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7bda19c4..af703630 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -73,5 +73,9 @@ class ApplicationController < ActionController::Base '' end end + + def get_homepage + Item.first(:conditions => {:parent_id => nil}) + end end diff --git a/app/models/design/design_file.rb b/app/models/design/design_file.rb index fe419eea..3aec9a0c 100644 --- a/app/models/design/design_file.rb +++ b/app/models/design/design_file.rb @@ -1,5 +1,6 @@ class DesignFile include Mongoid::Document + include Mongoid::Timestamps mount_uploader :file, AssetUploader diff --git a/app/models/design/layout.rb b/app/models/design/layout.rb index 10b4b692..aaac1b3f 100644 --- a/app/models/design/layout.rb +++ b/app/models/design/layout.rb @@ -1,5 +1,6 @@ class Layout < DesignFile include Parser + embeds_one :menu embedded_in :design attr_reader :content diff --git a/app/models/design/menu.rb b/app/models/design/menu.rb new file mode 100644 index 00000000..47fbc0d9 --- /dev/null +++ b/app/models/design/menu.rb @@ -0,0 +1,10 @@ +class Menu + include Mongoid::Document + include Mongoid::Timestamps + + field :levels, :type => Integer + field :values, :type => Hash + + embedded_in :layout + +end diff --git a/app/views/admin/designs/._form.html.erb.swp b/app/views/admin/designs/._form.html.erb.swp deleted file mode 100644 index 5e28e536..00000000 Binary files a/app/views/admin/designs/._form.html.erb.swp and /dev/null differ diff --git a/lib/parser.rb b/lib/parser.rb index c8fc1940..ea427b66 100644 --- a/lib/parser.rb +++ b/lib/parser.rb @@ -205,9 +205,45 @@ module Parser ret << item.i18n_variable[I18n.locale] ret << "" 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 = "" + end + end + + def menu_li(page, current, menu, i) + res = "" + 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