modified V,C,M related with layout and have bug between layout and design

This commit is contained in:
Kaito 2011-08-08 09:30:44 +08:00
parent c8d58e30aa
commit 706ec745c3
9 changed files with 37 additions and 33 deletions

View File

@ -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

View File

@ -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

View File

@ -1,16 +1,11 @@
class Layout
class Layout < DesignFile
embedded_in :design
include Mongoid::Document
include Mongoid::Timestamps
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

View File

@ -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

3
app/models/theme.rb Normal file
View File

@ -0,0 +1,3 @@
class Theme < Stylesheet
embedded_in :design
end

View File

@ -24,7 +24,15 @@
<% end %>
</p>
<p>
<%= 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 %>
</p>
<p>
<%= render :partial => 'design_file' ,:locals => { :fieldname=>"themes",:object=>@design ,:f=>f,:rtype=>'stylesheets',:item_destroy=>true,:item_editable=>true } %>
</p>
<p>

View File

@ -15,8 +15,8 @@
<% end %>
<p>
<%= 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] } %>
</p>
<p>

View File

@ -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)