From 151f00581561024ce15b7bd1d877e78f7b96b9e3 Mon Sep 17 00:00:00 2001
From: chris2tof
Date: Mon, 5 Sep 2011 15:18:36 +0800
Subject: [PATCH] structure.css -> default.css
Themes are optional, a theme overrides style in default.css
---
app/controllers/admin/designs_controller.rb | 27 +++++++++----------
app/controllers/admin/pages_controller.rb | 2 --
app/controllers/admin/purchases_controller.rb | 4 +--
app/models/design/design.rb | 2 +-
app/models/page.rb | 2 +-
app/views/admin/designs/_form.html.erb | 8 +++---
app/views/admin/pages/_form.html.erb | 2 +-
app/views/admin/pages/_themes_ddl.html.erb | 2 ++
app/views/admin/pages/reload_themes.js.erb | 2 +-
lib/fraisier/README.txt | 3 +--
lib/parser.rb | 8 +++---
11 files changed, 29 insertions(+), 33 deletions(-)
create mode 100644 app/views/admin/pages/_themes_ddl.html.erb
diff --git a/app/controllers/admin/designs_controller.rb b/app/controllers/admin/designs_controller.rb
index 84da2334..f331e096 100644
--- a/app/controllers/admin/designs_controller.rb
+++ b/app/controllers/admin/designs_controller.rb
@@ -94,28 +94,25 @@ class Admin::DesignsController < ApplicationController
themes_entries = []
javascripts_entries = []
images_entries = []
- #dir/zip_name
- #dir/zip_name
+
zip_file.entries.each do |entry|
case (path = entry.to_s)
- when /\A(#{zip_name})\/[^\/]*(\.css)\z/ #for structure css
+ when /\A(#{zip_name})\/(default\.css)\z/ #for default css
filename = File.basename(entry.to_s)
- temp_file4structure = File.new(dir + '/' + filename, 'w+')
- temp_file4structure.write (zip_file.read entry ).force_encoding('UTF-8')
- design.structure_css = temp_file4structure
- when /\A(#{zip_name})\/[^\/]*(\.html)\z/ #for layout html
+ 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})\/(layout\.html)\z/ #for layout html
filename = File.basename(entry.to_s)
- temp_file4layout = File.new(dir + '/' + filename, 'w+')
- temp_file4layout.write (zip_file.read entry ).force_encoding('UTF-8')
- design.layout.file = temp_file4layout
+ temp_file = File.new(dir + '/' + filename, 'w+')
+ temp_file.write (zip_file.read entry ).force_encoding('UTF-8')
+ design.layout.file = temp_file
design.layout.to_save=true
- when /\A(#{zip_name})\/(themes)\/.*(\.css)\z/
- #for themes css
+ when /\A(#{zip_name})\/(themes)\/.*(\.css)\z/ #for themes css
themes_entries << entry
- when /\A(#{zip_name})\/(javascripts)\/.*(\.js)\z/
- #for js
+ when /\A(#{zip_name})\/(javascripts)\/.*(\.js)\z/ #for js
javascripts_entries << entry
- when /\A(#{zip_name})\/(images)\/.*((\.jpg)|(\.png)|(\.gif))\z/ #for img
+ when /\A(#{zip_name})\/(images)\/.*((\.jpg)|(\.png)|(\.gif))\z/ #for img
images_entries << entry
end
end
diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb
index 5a5bc2c3..4ea26f12 100644
--- a/app/controllers/admin/pages_controller.rb
+++ b/app/controllers/admin/pages_controller.rb
@@ -23,7 +23,6 @@ class Admin::PagesController < ApplicationController
@item.parent_id = @parent_item.id rescue nil
@designs = Design.all.entries
@default_design = Design.first
- @default_theme = @default_design.themes.detect {|t| t.name.to_s == 'default' }
end
def edit
@@ -90,7 +89,6 @@ class Admin::PagesController < ApplicationController
def reload_themes
@design = Design.find(params[:id])
@themes = @design.themes
- @default_theme = @themes.detect {|t| t.name.to_s == 'default' }
respond_to do |format|
format.js {}
end
diff --git a/app/controllers/admin/purchases_controller.rb b/app/controllers/admin/purchases_controller.rb
index 56f3dbaa..9b341054 100644
--- a/app/controllers/admin/purchases_controller.rb
+++ b/app/controllers/admin/purchases_controller.rb
@@ -64,10 +64,10 @@ class Admin::PurchasesController < ApplicationController
design.layout.file = temp
design.layout.to_save = true
- title = design.structure_css_filename
+ title = design.default_css_filename
temp = File.new(dir + '/' + title, 'w+')
temp.write orig_zip.read(zip_name + '/' + title)
- design.structure_css = temp
+ design.default_css = temp
['themes', 'javascripts', 'images'].each do |type|
design.send(type).each do |object|
diff --git a/app/models/design/design.rb b/app/models/design/design.rb
index 9d3bc5c4..3e96ca51 100644
--- a/app/models/design/design.rb
+++ b/app/models/design/design.rb
@@ -15,7 +15,7 @@ class Design
has_many :pages
embeds_one :layout
- mount_uploader :structure_css, AssetUploader
+ mount_uploader :default_css, AssetUploader
embeds_many :themes
embeds_many :javascripts
diff --git a/app/models/page.rb b/app/models/page.rb
index 4e9f87ff..fe6916bf 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -1,7 +1,7 @@
class Page < Item
field :content
- field :theme_id, :type => BSON::ObjectId
+ field :theme_id, :type => BSON::ObjectId, :default => nil
belongs_to :design
has_many :page_parts
diff --git a/app/views/admin/designs/_form.html.erb b/app/views/admin/designs/_form.html.erb
index 7e1282c4..ac4317c4 100644
--- a/app/views/admin/designs/_form.html.erb
+++ b/app/views/admin/designs/_form.html.erb
@@ -26,11 +26,11 @@
<% end %>
-<%= f.label "structure_css", t('admin.structure_css') %>
-<% if @design.structure_css.blank? %>
- <%= f.file_field :structure_css %>
+<%= f.label "default_css", t('admin.default_css') %>
+<% if @design.default_css.blank? %>
+ <%= f.file_field :default_css %>
<% else%>
- <%= File.basename (@design.structure_css.url) %>
+ <%= File.basename (@design.default_css.url) %>
<% end %>
diff --git a/app/views/admin/pages/_form.html.erb b/app/views/admin/pages/_form.html.erb
index 1c8d1157..19e7c1a6 100644
--- a/app/views/admin/pages/_form.html.erb
+++ b/app/views/admin/pages/_form.html.erb
@@ -27,7 +27,7 @@
<% if @design %>
<%= f.select :theme_id, @design.themes.collect { |t| [t.name.capitalize, t.id] }%>
<% else %>
- <%= f.select :theme_id, @default_design.themes.collect { |t| [t.name.capitalize, t.id] }, :selected => @default_theme.id %>
+ <%= f.select :theme_id, @default_design.themes.collect { |t| [t.name.capitalize, t.id] }, :include_blank => true %>
<% end %>
diff --git a/app/views/admin/pages/_themes_ddl.html.erb b/app/views/admin/pages/_themes_ddl.html.erb
new file mode 100644
index 00000000..1bb31ac9
--- /dev/null
+++ b/app/views/admin/pages/_themes_ddl.html.erb
@@ -0,0 +1,2 @@
+
+<%= options_from_collection_for_select(@themes, :id, :name) %>
\ No newline at end of file
diff --git a/app/views/admin/pages/reload_themes.js.erb b/app/views/admin/pages/reload_themes.js.erb
index e3d111b4..8515d02a 100644
--- a/app/views/admin/pages/reload_themes.js.erb
+++ b/app/views/admin/pages/reload_themes.js.erb
@@ -1 +1 @@
-$('#page_theme_id').html("<%= escape_javascript(options_from_collection_for_select(@themes, :id, :name, @default_theme.id )) %>");
\ No newline at end of file
+$('#page_theme_id').html("<%= escape_javascript(render :partial => 'admin/pages/themes_ddl') %>");
\ No newline at end of file
diff --git a/lib/fraisier/README.txt b/lib/fraisier/README.txt
index 939b2e7e..13aaeae0 100644
--- a/lib/fraisier/README.txt
+++ b/lib/fraisier/README.txt
@@ -10,9 +10,8 @@ Package content:
My_design.zip
- info.json
- layout.html
- - structure.css
+ - default.css
- themes
- - default.css
- blue.css
- red.css
- javascripts
diff --git a/lib/parser.rb b/lib/parser.rb
index ddfa07a6..35911e78 100644
--- a/lib/parser.rb
+++ b/lib/parser.rb
@@ -65,7 +65,7 @@ module Parser
end
c.define_tag 'stylesheets' do |tag|
res = ''
- res << " "
+ res << " "
theme = page.design.themes.detect{ |d| d.id == page.theme_id }
res << ""
end
@@ -173,7 +173,7 @@ module Parser
end
c.define_tag 'stylesheets' do |tag|
res = ''
- res << ""
+ res << ""
theme = page.design.themes.detect{ |d| d.id == page.theme_id }
res << ""
end
@@ -226,7 +226,7 @@ module Parser
res << menu.values["class_#{current}"]
res << ">"
i = nil
- i = 1 if menu.values["li_recursive_#{current}"]
+ i = 1 if menu.values["li_incremental_#{current}"]
if current == 1 && menu.values['home'].eql?('true')
res << menu_li(page, current, menu, i)
i += 1 if i
@@ -267,7 +267,7 @@ module Parser
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.values.merge!({"id_#{i}" => tag.attr['id'], "class_#{i}" => tag.attr['class'], "li_class_#{i}" => tag.attr['li_class'], "li_incremental_#{i}" => tag.attr['li_incremental']})
layout.menu.save
tag.expand
end