From 7a4ad240a8440dade35f00adcce0985027b53900 Mon Sep 17 00:00:00 2001 From: chris2tof Date: Mon, 22 Aug 2011 13:45:21 +0800 Subject: [PATCH] Clean code for layout and modifications in dev.rake --- app/controllers/admin/layouts_controller.rb | 54 ------------ app/controllers/admin/purchases_controller.rb | 2 + .../{ => admin}/sites_controller.rb | 6 +- app/models/design/design.rb | 2 + app/models/page.rb | 5 +- app/views/admin/designs/index.html.erb | 3 +- app/views/admin/layouts/_form.html.erb | 14 --- app/views/admin/layouts/edit.html.erb | 9 -- app/views/admin/layouts/index.html.erb | 28 ------ app/views/admin/layouts/new.html.erb | 10 --- app/views/{ => admin}/sites/index.html.erb | 0 app/views/{ => admin}/sites/new.html.erb | 0 app/views/layouts/admin.html.erb | 23 +++-- app/views/layouts/content.html.erb | 7 +- config/routes.rb | 5 +- lib/fraisier/README.txt | 85 +++++++++++++++++++ lib/fraisier/info.json | 5 ++ lib/fraisier/layout.html | 37 ++++++++ lib/fraisier/structure.css | 2 + lib/fraisier/themes/default.css | 2 + lib/parser.rb | 30 ++++++- lib/tasks/dev.rake | 56 +++++++++--- 22 files changed, 226 insertions(+), 159 deletions(-) delete mode 100644 app/controllers/admin/layouts_controller.rb rename app/controllers/{ => admin}/sites_controller.rb (51%) delete mode 100644 app/views/admin/layouts/_form.html.erb delete mode 100644 app/views/admin/layouts/edit.html.erb delete mode 100644 app/views/admin/layouts/index.html.erb delete mode 100644 app/views/admin/layouts/new.html.erb rename app/views/{ => admin}/sites/index.html.erb (100%) rename app/views/{ => admin}/sites/new.html.erb (100%) create mode 100644 lib/fraisier/README.txt create mode 100644 lib/fraisier/info.json create mode 100644 lib/fraisier/layout.html create mode 100644 lib/fraisier/structure.css create mode 100644 lib/fraisier/themes/default.css diff --git a/app/controllers/admin/layouts_controller.rb b/app/controllers/admin/layouts_controller.rb deleted file mode 100644 index 6661720c..00000000 --- a/app/controllers/admin/layouts_controller.rb +++ /dev/null @@ -1,54 +0,0 @@ -class Admin::LayoutsController < ApplicationController - - layout "admin" - before_filter :authenticate_user! - before_filter :is_admin? - - def index - @layouts = Layout.all.entries - end - - def show - #TODO -# @layout = Layout.find(params[:id]) -# redirect_to "/#{@layout.name}" - end - - def new - @layout = Layout.new - end - - def edit - @layout = Layout.find(params[:id]) - end - - def create - @layout = Layout.new(params[:layout]) - - if @layout.save - flash[:notice] = t('admin.create_success_layout') - redirect_to admin_layouts_url - else - render :action => 'new' - end - end - - def update - @layout = Layout.find(params[:id]) - - if @layout.update_attributes(params[:layout]) - flash[:notice] = t('admin.update_success_layout') - redirect_to admin_layouts_url - else - render :action => "edit" - end - end - - def destroy - @layout = Layout.find(params[:id]) - @layout.destroy - - redirect_to admin_layouts_url - end - -end diff --git a/app/controllers/admin/purchases_controller.rb b/app/controllers/admin/purchases_controller.rb index 3fbd80d4..f11cc414 100644 --- a/app/controllers/admin/purchases_controller.rb +++ b/app/controllers/admin/purchases_controller.rb @@ -3,6 +3,8 @@ class Admin::PurchasesController < ApplicationController require "uri" require 'zip/zip' + layout "admin" + def index @purchases = Purchase.all.entries end diff --git a/app/controllers/sites_controller.rb b/app/controllers/admin/sites_controller.rb similarity index 51% rename from app/controllers/sites_controller.rb rename to app/controllers/admin/sites_controller.rb index a8137715..9475e708 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -1,6 +1,8 @@ -class SitesController < ApplicationController +class Admin::SitesController < ApplicationController - #layout 'set_up' + layout "admin" + before_filter :authenticate_user! + before_filter :is_admin? def index @site = Site.first diff --git a/app/models/design/design.rb b/app/models/design/design.rb index 902a2448..f4eef5df 100644 --- a/app/models/design/design.rb +++ b/app/models/design/design.rb @@ -12,6 +12,8 @@ class Design validates_presence_of :title validates_presence_of :author + has_many :pages + embeds_one :layout mount_uploader :structure_css, AssetUploader diff --git a/app/models/page.rb b/app/models/page.rb index 1e2d73c2..d29685ae 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -1,14 +1,11 @@ class Page < Item - - #include LayoutSupport field :content field :design_name - field :design_id validates_presence_of :design_name, :design_id - referenced_in :design + belongs_to :design has_many :page_parts def create_parts diff --git a/app/views/admin/designs/index.html.erb b/app/views/admin/designs/index.html.erb index 2f0210f0..03683e66 100644 --- a/app/views/admin/designs/index.html.erb +++ b/app/views/admin/designs/index.html.erb @@ -1,6 +1,7 @@ <% content_for :secondary do %> <% end -%> diff --git a/app/views/admin/layouts/_form.html.erb b/app/views/admin/layouts/_form.html.erb deleted file mode 100644 index a34d8e86..00000000 --- a/app/views/admin/layouts/_form.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -

-<%= f.label :name, t('admin.name') %> -<%= f.text_field :name, :class => 'text' %> -

- -

-<%= f.label :description, t('admin.description') %> -<%= f.text_field :description, :class => 'text' %> -

- -

-<%= f.label "content", t('admin.content') %> -<%= f.text_area :content, :size => '100x30' %> -

diff --git a/app/views/admin/layouts/edit.html.erb b/app/views/admin/layouts/edit.html.erb deleted file mode 100644 index 6785d1c5..00000000 --- a/app/views/admin/layouts/edit.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -

<%= t('admin.editing_layout') %>

- -<%= form_for @layout, :url => admin_layout_path(@layout) do |f| %> - <%= f.error_messages %> - <%= render :partial => "form", :locals => { :f => f } %> -

- <%= f.submit t('update') %> <%= link_back %> -

-<% end %> diff --git a/app/views/admin/layouts/index.html.erb b/app/views/admin/layouts/index.html.erb deleted file mode 100644 index b0634d3a..00000000 --- a/app/views/admin/layouts/index.html.erb +++ /dev/null @@ -1,28 +0,0 @@ -<% content_for :secondary do %> - -<% end -%> - -<%= flash_messages %> - -

<%= t('admin.list_layouts') %>

- - - - - - - - -<% @layouts.each do |layout| %> - - - - - -<% end %> -
<%= t('admin.name') %><%= t('admin.description') %><%= t('admin.action') %>
<%= layout.name %><%= layout.description %> - <%= link_to t(:edit), edit_admin_layout_path(layout) %> | - <%= link_to t(:delete), admin_layout_path(layout), :confirm => t('sure?'), :method => :delete %> -
diff --git a/app/views/admin/layouts/new.html.erb b/app/views/admin/layouts/new.html.erb deleted file mode 100644 index 91d3fed5..00000000 --- a/app/views/admin/layouts/new.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -

<%= t('admin.new_layout') %>

- -<%= form_for :layout, :url => admin_layouts_path do |f| %> - <%= f.error_messages %> - <%= render :partial => "form", :locals => { :f => f } %> - -

- <%= f.submit t('create') %> <%= link_back %> -

-<% end %> diff --git a/app/views/sites/index.html.erb b/app/views/admin/sites/index.html.erb similarity index 100% rename from app/views/sites/index.html.erb rename to app/views/admin/sites/index.html.erb diff --git a/app/views/sites/new.html.erb b/app/views/admin/sites/new.html.erb similarity index 100% rename from app/views/sites/new.html.erb rename to app/views/admin/sites/new.html.erb diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index eb6b5c3d..c88dc423 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -28,18 +28,17 @@
diff --git a/app/views/layouts/content.html.erb b/app/views/layouts/content.html.erb index 8b4d3a13..bac1b87f 100644 --- a/app/views/layouts/content.html.erb +++ b/app/views/layouts/content.html.erb @@ -6,9 +6,9 @@ <%= yield :page_specific_link %> <%= stylesheet_link_tag "content", :media => "screen, projection" %> - <%= javascript_include_tag :ckeditor %> + <%#= javascript_include_tag :ckeditor %> - <%= javascript_include_tag "jquery", "jquery-ui", "rails", "easy", "application", :cache => 'all' %> + <%#= javascript_include_tag "jquery", "jquery-ui", "rails", "easy", "application", :cache => 'all' %> <%= yield :page_specific_javascript %> + + + + + + + + +
+ + +
+
+ + +
+ +
+ + +
+ + + + + diff --git a/lib/fraisier/structure.css b/lib/fraisier/structure.css new file mode 100644 index 00000000..ea0bd6bf --- /dev/null +++ b/lib/fraisier/structure.css @@ -0,0 +1,2 @@ +/* This stylesheet file contains the structure of the page, it reference elements by their ID. +In this file, you can set structural attributes like "width", "height", "position"… */ \ No newline at end of file diff --git a/lib/fraisier/themes/default.css b/lib/fraisier/themes/default.css new file mode 100644 index 00000000..2e35c537 --- /dev/null +++ b/lib/fraisier/themes/default.css @@ -0,0 +1,2 @@ +/* This stylesheet file contains the visual aspect of the page, it reference elements by their class. +In this file, you can set visual attributes like "color", "background-color", "border"… */ \ No newline at end of file diff --git a/lib/parser.rb b/lib/parser.rb index b9cfc2e7..83e5bcf8 100644 --- a/lib/parser.rb +++ b/lib/parser.rb @@ -64,8 +64,19 @@ module Parser res end c.define_tag 'stylesheets' do |tag| - contents = tag.expand - contents.to_html + res = '' + res << " " + page.design.themes.each do |theme| + res << " " + end + res + end + c.define_tag 'javascripts' do |tag| + res = '' + page.design.javascripts.each do |js| + res << "" + end + res end c.define_tag 'image' do |tag| asset = Asset.find(tag.attr['id']) @@ -163,8 +174,19 @@ module Parser end end c.define_tag 'stylesheets' do |tag| - contents = tag.expand - contents.to_html + res = '' + res << "" + page.design.themes.each do |theme| + res << "" + end + res + end + c.define_tag 'javascripts' do |tag| + res = '' + page.design.javascripts.each do |js| + res << "" + end + res end c.define_tag 'layout_part' do |tag| part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 1059ed17..a6747f4f 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -10,8 +10,8 @@ namespace :dev do puts 'Dropping ' + collection.name if include include end.each(&:drop) - - Site.create!( :valid_locales => [ 'en', 'zh_tw' ], :in_use_locales => [ 'zh_tw', 'en' ] ) + + Site.create( :school => 'The Best School', :department => 'Awesome', :valid_locales => [ 'en', 'zh_tw' ], :in_use_locales => [ 'zh_tw', 'en' ]) user = User.new( :email => 'chris@rulingcom.com', :password => 'password', :password_confirmation => 'password', :admin => true, :active_roles => ['teacher']) user.user_roles.build(:key => 'teacher', :discipline_en => 'Database', :discipline_zh_tw => '資料庫' ) @@ -50,22 +50,50 @@ namespace :dev do uim_1.save! - layout = Layout.create!( :name => 'root', :description => 'root', :content => File.open("#{Rails.root}/lib/template/root.layout").read ) - layout.layout_parts.create!( :name => 'header', :content => File.open("#{Rails.root}/lib/template/nav.snippet").read ) - layout.layout_parts.create!( :name => 'main_content', :editable => true ) - layout.layout_parts.create!( :name => 'footer', :content => File.open("#{Rails.root}/lib/template/footer.snippet").read ) + # layout = Layout.create!( :name => 'root', :description => 'root', :content => File.open("#{Rails.root}/lib/template/root.layout").read ) + # layout.layout_parts.create!( :name => 'header', :content => File.open("#{Rails.root}/lib/template/nav.snippet").read ) + # layout.layout_parts.create!( :name => 'main_content', :editable => true ) + # layout.layout_parts.create!( :name => 'footer', :content => File.open("#{Rails.root}/lib/template/footer.snippet").read ) + # + # home = Page.create!( :i18n_variable_id => var_10.id, :layout_id => layout.id, :name => 'home', :is_published => true ) + # home.page_parts.create!( :name => 'main_content', :content => File.open("#{Rails.root}/lib/template/home.page").read, :kind => 'text', :i18n_variable_id => var_13.id ) + # + # about = Page.create!( :i18n_variable_id => var_11.id, :layout_id => layout.id, :name => 'about', :is_published => true, :parent_id => home.id ) + # about.page_parts.create!( :name => 'main_content', :content => File.open("#{Rails.root}/lib/template/about.page").read, :kind => 'text', :i18n_variable_id => var_14.id ) - home = Page.create!( :i18n_variable_id => var_10.id, :layout_id => layout.id, :name => 'home', :is_published => true ) - home.page_parts.create!( :name => 'main_content', :content => File.open("#{Rails.root}/lib/template/home.page").read, :kind => 'text', :i18n_variable_id => var_13.id ) + # Link.create!( :i18n_variable_id => var_12.id, :name => 'google', :is_published => true, :parent_id => home.id, :url => 'www.google.com' ) + # + # ["nav", "footer"].each do |page_name| + # Snippet.create!( :name => page_name, :parent_id => home.id, :content => File.open("#{Rails.root}/lib/template/#{page_name}.snippet").read ) + # end - about = Page.create!( :i18n_variable_id => var_11.id, :layout_id => layout.id, :name => 'about', :is_published => true, :parent_id => home.id ) - about.page_parts.create!( :name => 'main_content', :content => File.open("#{Rails.root}/lib/template/about.page").read, :kind => 'text', :i18n_variable_id => var_14.id ) + design = Design.new(:title => "Fraisier", :author => "Paul", :intro => "Strawberry cake") - Link.create!( :i18n_variable_id => var_12.id, :name => 'google', :is_published => true, :parent_id => home.id, :url => 'www.google.com' ) + design.structure_css = File.open("#{Rails.root}/lib/fraisier/structure.css") - ["nav", "footer"].each do |page_name| - Snippet.create!( :name => page_name, :parent_id => home.id, :content => File.open("#{Rails.root}/lib/template/#{page_name}.snippet").read ) - end + # image = design.images.build(:file => File.open("#{Rails.root}/lib/fraisier/img/buttons.gif")) + # + # js = design.javascripts.build(:file => File.open("#{Rails.root}/lib/fraisier/inettuts.js")) + # + # theme = design.themes.build(:file => File.open("#{Rails.root}/lib/fraisier/inettuts.js.css")) + + design.build_layout + design.layout.file = File.open("#{Rails.root}/lib/fraisier/layout.html") + + design.layout.save + # theme.save + # image.save + # js.save + + design.save + + design.layout.layout_parts.create!( :name => 'header_1') + design.layout.layout_parts.create!( :name => 'header_2') + design.layout.layout_parts.create!( :name => 'block_1') + design.layout.layout_parts.create!( :name => 'footer_1') + + home = Page.create!( :i18n_variable_id => var_10.id, :design_id => design.id, :name => 'home', :is_published => true ) + home.page_parts.create!( :name => 'header_1', :kind => 'text') end