From 492f6914696189ec880451ee3df242a887fe383b Mon Sep 17 00:00:00 2001 From: chris2tof Date: Thu, 1 Sep 2011 09:12:41 +0800 Subject: [PATCH] Modifications for menu in Design --- app/controllers/admin/items_controller.rb | 2 +- app/controllers/application_controller.rb | 4 ++ app/models/design/design_file.rb | 1 + app/models/design/layout.rb | 1 + app/models/design/menu.rb | 10 +++++ app/views/admin/designs/._form.html.erb.swp | Bin 12288 -> 0 bytes lib/parser.rb | 44 ++++++++++++++++++++ 7 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 app/models/design/menu.rb delete mode 100644 app/views/admin/designs/._form.html.erb.swp 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 5e28e536e8822416f776fcc14f68eb6a33f933db..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2zi-n(6vvNl0SX94mLpKPMUlgg0b!AVkU%id0Ra+1$hySm=IF&XzDr9*ix6Uf zg^7Qm17l~z$im0~3mXG0h`#{A_w4*2sI(bCLg-ogsI~9;`Q7K;d1&1_cH{CDe#$?= zaO`93+NJaJQ-`M5>v_f&g|ex;zRj_`yu3|BIsBkVSihQHt>;2%6P^r@*F~1qmy}#K zbrE${Qjerj3yG;6F5AvmNX^<~0R;u%i!t&_M>s02v?yWPl8i0Wv@a$N(8217v^< z{3ixP#MnlKv9+C;5dQz~{s!=FFJmvjI#>hq;4-)X4uUUx82b!9fsf!Ncm|$=C*U!- z2~LA)@O7H8S6~CIgS#LG0^9~iz_;CaE_ef;gQwszcnCi1V(dM52i}6CUfDDiUGC&6YT?1$8S(BZaY4BVok<59JiQFood85g_@v^3`T z7b>jd(sZP>#@j;gc(Huwx38CD5kNU-9EV#K7twmZC5&{P=Cl3A`siD) zZF{*4+s634T+eaWDR&Q-+Q{PfGDGaU<%2bZ<-&up8;j=7aIRv$dE%B9$>P~EtifYn zi9I+mnb<9607K3pCz%bP21bj!P3}&@K#yXZI4GOUyWBwDP!*X zb^k_MIr_7$^2$ilz>}MemG|smE-Jw;#Z1~-m}2*PZqzF)7_}wn#|^ttoNu3A^lT^1 zC&)ht96q4DFnYr99Wh?NRaU!B{91ppWXtB23oGbH4j)jQ|CAq%9=#Ppm9%v)lA#p~ XyxM" 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