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) mongo (~> 1.3)
tzinfo (~> 0.3.22) tzinfo (~> 0.3.22)
multi_json (1.0.3) multi_json (1.0.3)
nokogiri (1.5.0)
orm_adapter (0.0.5) orm_adapter (0.0.5)
polyglot (0.3.1) polyglot (0.3.1)
rack (1.3.0) rack (1.3.0)
@ -160,7 +159,6 @@ DEPENDENCIES
jquery-rails (>= 1.0.3) jquery-rails (>= 1.0.3)
mini_magick mini_magick
mongoid mongoid
nokogiri
rails (>= 3.1.0.rc4) rails (>= 3.1.0.rc4)
rake (>= 0.9.2) rake (>= 0.9.2)
rcov rcov

View File

@ -12,8 +12,9 @@ class Design
validates_presence_of :author validates_presence_of :author
mount_uploader :layout, DesignFileUploader mount_uploader :layout, DesignFileUploader
mount_uploader :structure_css, DesignFileUploader
embeds_many :stylesheets embeds_many :themes
embeds_many :javascripts embeds_many :javascripts
embeds_many :images embeds_many :images
@ -24,8 +25,8 @@ class Design
self.files = (attrs << 'javascripts') self.files = (attrs << 'javascripts')
end end
def stylesheets=(*attrs) def themes=(*attrs)
self.files = (attrs << 'stylesheets') self.files = (attrs << 'themes')
end end
def images=(*attrs) def images=(*attrs)
@ -52,14 +53,14 @@ class Design
protected protected
def del_embedded_objects 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| objects.each do |object|
object.destroy object.destroy
end end
end end
end end
def procs_embedded_objects 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| objects.each do |object|
if object.file.blank? if object.file.blank?
object.to_save = false object.to_save = false

View File

@ -1,16 +1,11 @@
class Layout class Layout < DesignFile
include Mongoid::Document embedded_in :design
include Mongoid::Timestamps
field :name, :index => true field :name, :index => true
field :description
field :content
field :parent_id
references_many :children, :class_name => "Item" references_many :children, :class_name => "Item"
has_many :layout_parts has_many :layout_parts
belongs_to :design,:class_name=>"Design"
validates_presence_of :name validates_presence_of :name
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/ validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
@ -19,5 +14,4 @@ class Layout
def self.exist_one? def self.exist_one?
Layout.count > 0 Layout.count > 0
end end
end end

View File

@ -3,17 +3,17 @@ class Page < Item
#include LayoutSupport #include LayoutSupport
field :content field :content
field :layout_name field :design_name
field :layout_id 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 has_many :page_parts
def create_parts def create_parts
page_layout = self.get_layout page_design = self.get_design
page_layout.layout_parts.each do |p| 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'] self.page_parts.create( :name => p.name, :i18n_variable_id => I18nVariable.create.id, :kind => 'text' ) if p['editable']
end end
end end
@ -26,8 +26,8 @@ class Page < Item
end end
end end
def get_layout def get_design
Layout.find(layout_id) Design.find(design_id)
end end
protected protected
@ -35,8 +35,8 @@ class Page < Item
def setup_default_value def setup_default_value
super super
if self.layout_id if self.design_id
self.layout_name = get_layout.name self.design_name = get_design.title
end end
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 %> <% end %>
</p> </p>
<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>
<p> <p>

View File

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

View File

@ -1,2 +1,2 @@
$('#panel_main').html("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>"); $('#panel_main').html("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>");
history.pushState(null, document.title, "<%= escape_javascript(admin_page_url(@item)) %>"); history.pushState(null, document.title, "<%= escape_javascript(admin_page_url(@item)) %>");

View File

@ -98,7 +98,7 @@ module Parser
def parse_page(page) def parse_page(page)
if page._type == 'Page' if page._type == 'Page'
layout_content = page.layout.content layout_content = page.design.layout.content
context = parser_context(page) context = parser_context(page)
parser = Radius::Parser.new(context, :tag_prefix => 'r') parser = Radius::Parser.new(context, :tag_prefix => 'r')
parser.parse(parser.parse(layout_content)) parser.parse(parser.parse(layout_content))
@ -107,7 +107,7 @@ module Parser
def parse_page_edit(page) def parse_page_edit(page)
if page._type == 'Page' if page._type == 'Page'
layout_content = page.layout.content layout_content = page.design.layout.content
context = parser_context_edit(page) context = parser_context_edit(page)
parser = Radius::Parser.new(context, :tag_prefix => 'r') parser = Radius::Parser.new(context, :tag_prefix => 'r')
parser.parse(parser.parse(layout_content)) parser.parse(parser.parse(layout_content))
@ -185,7 +185,7 @@ module Parser
end end
def parse_page_code(page) def parse_page_code(page)
layout_content = page.layout.content layout_content = page.design.layout.content
context = parser_context_code(page) context = parser_context_code(page)
parser = Radius::Parser.new(context, :tag_prefix => 'r') parser = Radius::Parser.new(context, :tag_prefix => 'r')
parser.parse(layout_content) parser.parse(layout_content)