From 706ec745c33e8c11cf7fc3868f26d5a16e1bdf70 Mon Sep 17 00:00:00 2001 From: Kaito Date: Mon, 8 Aug 2011 09:30:44 +0800 Subject: [PATCH] modified V,C,M related with layout and have bug between layout and design --- Gemfile.lock | 2 -- app/models/design.rb | 11 ++++++----- app/models/layout.rb | 12 +++--------- app/models/page.rb | 20 ++++++++++---------- app/models/theme.rb | 3 +++ app/views/admin/designs/_form.html.erb | 10 +++++++++- app/views/admin/pages/_form.html.erb | 4 ++-- app/views/admin/pages/update.js.erb | 2 +- lib/parser.rb | 6 +++--- 9 files changed, 37 insertions(+), 33 deletions(-) create mode 100644 app/models/theme.rb diff --git a/Gemfile.lock b/Gemfile.lock index 8cab2db4..ab5e7389 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,7 +77,6 @@ GEM mongo (~> 1.3) tzinfo (~> 0.3.22) multi_json (1.0.3) - nokogiri (1.5.0) orm_adapter (0.0.5) polyglot (0.3.1) rack (1.3.0) @@ -160,7 +159,6 @@ DEPENDENCIES jquery-rails (>= 1.0.3) mini_magick mongoid - nokogiri rails (>= 3.1.0.rc4) rake (>= 0.9.2) rcov diff --git a/app/models/design.rb b/app/models/design.rb index 5d23e663..f2470527 100644 --- a/app/models/design.rb +++ b/app/models/design.rb @@ -12,8 +12,9 @@ class Design validates_presence_of :author mount_uploader :layout, DesignFileUploader + mount_uploader :structure_css, DesignFileUploader - embeds_many :stylesheets + embeds_many :themes embeds_many :javascripts embeds_many :images @@ -24,8 +25,8 @@ class Design self.files = (attrs << 'javascripts') end - def stylesheets=(*attrs) - self.files = (attrs << 'stylesheets') + def themes=(*attrs) + self.files = (attrs << 'themes') end def images=(*attrs) @@ -52,14 +53,14 @@ class Design protected def del_embedded_objects - [self.stylesheets, self.javascripts, self.images].each do |objects| + [self.themes, self.javascripts, self.images].each do |objects| objects.each do |object| object.destroy end end end def procs_embedded_objects - [self.stylesheets, self.javascripts, self.images].each do |objects| + [self.themes, self.javascripts, self.images].each do |objects| objects.each do |object| if object.file.blank? object.to_save = false diff --git a/app/models/layout.rb b/app/models/layout.rb index 20a2a46f..8b6f7957 100644 --- a/app/models/layout.rb +++ b/app/models/layout.rb @@ -1,16 +1,11 @@ -class Layout +class Layout < DesignFile - include Mongoid::Document - include Mongoid::Timestamps + embedded_in :design + field :name, :index => true - field :description - field :content - field :parent_id - references_many :children, :class_name => "Item" has_many :layout_parts - belongs_to :design,:class_name=>"Design" validates_presence_of :name validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/ @@ -19,5 +14,4 @@ class Layout def self.exist_one? Layout.count > 0 end - end diff --git a/app/models/page.rb b/app/models/page.rb index 726809f5..1e2d73c2 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -3,17 +3,17 @@ class Page < Item #include LayoutSupport field :content - field :layout_name - field :layout_id + field :design_name + field :design_id - validates_presence_of :layout_name, :layout_id + validates_presence_of :design_name, :design_id - referenced_in :layout + referenced_in :design has_many :page_parts def create_parts - page_layout = self.get_layout - page_layout.layout_parts.each do |p| + page_design = self.get_design + page_design.layout.layout_parts.each do |p| self.page_parts.create( :name => p.name, :i18n_variable_id => I18nVariable.create.id, :kind => 'text' ) if p['editable'] end end @@ -26,8 +26,8 @@ class Page < Item end end - def get_layout - Layout.find(layout_id) + def get_design + Design.find(design_id) end protected @@ -35,8 +35,8 @@ class Page < Item def setup_default_value super - if self.layout_id - self.layout_name = get_layout.name + if self.design_id + self.design_name = get_design.title end end diff --git a/app/models/theme.rb b/app/models/theme.rb new file mode 100644 index 00000000..54088e19 --- /dev/null +++ b/app/models/theme.rb @@ -0,0 +1,3 @@ +class Theme < Stylesheet + embedded_in :design +end diff --git a/app/views/admin/designs/_form.html.erb b/app/views/admin/designs/_form.html.erb index bc11e33b..43f8e389 100644 --- a/app/views/admin/designs/_form.html.erb +++ b/app/views/admin/designs/_form.html.erb @@ -24,7 +24,15 @@ <% end %>

-<%= render :partial => 'design_file' ,:locals => { :fieldname=>"stylesheet",:object=>@design ,:f=>f,:rtype=>'stylesheets',:item_destroy=>true,:item_editable=>true } %> +<%= f.label "structure_css", t('admin.structure_css') %> +<% if @design.structure_css.blank? %> + <%= f.file_field :structure_css %> + <% else%> + <%= File.basename (Design.all.last.structure_css.url) %> +<% end %> +

+

+<%= render :partial => 'design_file' ,:locals => { :fieldname=>"themes",:object=>@design ,:f=>f,:rtype=>'stylesheets',:item_destroy=>true,:item_editable=>true } %>

diff --git a/app/views/admin/pages/_form.html.erb b/app/views/admin/pages/_form.html.erb index 89c56e69..54ee892f 100644 --- a/app/views/admin/pages/_form.html.erb +++ b/app/views/admin/pages/_form.html.erb @@ -15,8 +15,8 @@ <% end %>

-<%= f.label :layout_id, t('admin.layout_name') %> -<%= f.select :layout_id, Layout.all.map{ |l| [l.description, l.id] } %> +<%= f.label :design_id, t('admin.design_name') %> +<%= f.select :design_id, Design.all.map{ |l| [l.title, l.id] } %>

diff --git a/app/views/admin/pages/update.js.erb b/app/views/admin/pages/update.js.erb index 4fdd4357..20cb22c1 100644 --- a/app/views/admin/pages/update.js.erb +++ b/app/views/admin/pages/update.js.erb @@ -1,2 +1,2 @@ $('#panel_main').html("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>"); -history.pushState(null, document.title, "<%= escape_javascript(admin_page_url(@item)) %>"); \ No newline at end of file +history.pushState(null, document.title, "<%= escape_javascript(admin_page_url(@item)) %>"); diff --git a/lib/parser.rb b/lib/parser.rb index 7f24c8a8..08616dfe 100644 --- a/lib/parser.rb +++ b/lib/parser.rb @@ -98,7 +98,7 @@ module Parser def parse_page(page) if page._type == 'Page' - layout_content = page.layout.content + layout_content = page.design.layout.content context = parser_context(page) parser = Radius::Parser.new(context, :tag_prefix => 'r') parser.parse(parser.parse(layout_content)) @@ -107,7 +107,7 @@ module Parser def parse_page_edit(page) if page._type == 'Page' - layout_content = page.layout.content + layout_content = page.design.layout.content context = parser_context_edit(page) parser = Radius::Parser.new(context, :tag_prefix => 'r') parser.parse(parser.parse(layout_content)) @@ -185,7 +185,7 @@ module Parser end def parse_page_code(page) - layout_content = page.layout.content + layout_content = page.design.layout.content context = parser_context_code(page) parser = Radius::Parser.new(context, :tag_prefix => 'r') parser.parse(layout_content)