Handle "reset.css" and add link in the generated menu

This commit is contained in:
chris2tof 2011-09-05 16:06:17 +08:00
parent 151f005815
commit 22c9ca4c74
5 changed files with 22 additions and 13 deletions

View File

@ -102,6 +102,11 @@ class Admin::DesignsController < ApplicationController
temp_file = File.new(dir + '/' + filename, 'w+')
temp_file.write (zip_file.read entry ).force_encoding('UTF-8')
design.default_css = temp_file
when /\A(#{zip_name})\/(reset\.css)\z/ #for reset css
filename = File.basename(entry.to_s)
temp_file = File.new(dir + '/' + filename, 'w+')
temp_file.write (zip_file.read entry ).force_encoding('UTF-8')
design.reset_css = temp_file
when /\A(#{zip_name})\/(layout\.html)\z/ #for layout html
filename = File.basename(entry.to_s)
temp_file = File.new(dir + '/' + filename, 'w+')

View File

@ -2,25 +2,24 @@ class Design
include Mongoid::Document
include Mongoid::Timestamps
field :title
field :author
field :intro
field :version
validates_presence_of :title
validates_presence_of :author
mount_uploader :default_css, AssetUploader
mount_uploader :reset_css, AssetUploader
has_many :pages
embeds_one :layout
mount_uploader :default_css, AssetUploader
embeds_many :themes
embeds_many :javascripts
embeds_many :images
validates_presence_of :title
validates_presence_of :author
after_save :procs_embedded_objects
# after_destroy :del_embedded_objects

View File

@ -20,7 +20,6 @@ class Layout < DesignFile
end
def parse_layout
debugger
parse_layout_contents(self)
end

View File

@ -21,4 +21,8 @@ class Page < Item
end
end
def is_home?
self.parent ? false : true
end
end

View File

@ -65,9 +65,10 @@ module Parser
end
c.define_tag 'stylesheets' do |tag|
res = ''
res << "<link href='#{page.design.reset_css.url}' rel='stylesheet' type='text/css' />"
res << "<link href='#{page.design.default_css.url}' rel='stylesheet' type='text/css' /> "
theme = page.design.themes.detect{ |d| d.id == page.theme_id }
res << "<link href='#{theme.file.url}' rel='stylesheet' type='text/css' />"
res << "<link href='#{theme.file.url}' rel='stylesheet' type='text/css' />" if theme
end
c.define_tag 'javascripts' do |tag|
res = ''
@ -173,9 +174,10 @@ module Parser
end
c.define_tag 'stylesheets' do |tag|
res = ''
res << "<link href='#{page.design.reset_css.url}' rel='stylesheet' type='text/css' />"
res << "<link href='#{page.design.default_css.url}' rel='stylesheet' type='text/css' />"
theme = page.design.themes.detect{ |d| d.id == page.theme_id }
res << "<link href='#{theme.file.url}' rel='stylesheet' type='text/css' />"
res << "<link href='#{theme.file.url}' rel='stylesheet' type='text/css' />" if theme
end
c.define_tag 'javascripts' do |tag|
res = ''
@ -244,8 +246,8 @@ module Parser
res << menu.values["li_class_#{current}"]
res << "_#{i}" if i
res << ">"
res << page.name
res << menu_level(page, current + 1, menu) if page.children.size > 0
res << "<a href='#{page.full_name}'>#{page.name}</a>"
res << menu_level(page, current + 1, menu) if page.children.size > 0 && !page.is_home?
res << "</li>"
end