Clean code for layout and modifications in dev.rake
This commit is contained in:
parent
e74f2931b1
commit
7a4ad240a8
|
@ -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
|
|
@ -3,6 +3,8 @@ class Admin::PurchasesController < ApplicationController
|
|||
require "uri"
|
||||
require 'zip/zip'
|
||||
|
||||
layout "admin"
|
||||
|
||||
def index
|
||||
@purchases = Purchase.all.entries
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<% content_for :secondary do %>
|
||||
<ul class="list">
|
||||
<li><%= link_to t(:new_design, :scope => :admin), new_admin_design_path, :class => 'button positive' %></li>
|
||||
<li><%= link_to t(:new_design, :scope => :admin), new_admin_design_path %></li>
|
||||
<li><%= link_to t('admin.upload_design'), upload_package_admin_designs_path %></li>
|
||||
</ul>
|
||||
<% end -%>
|
||||
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
<p>
|
||||
<%= f.label :name, t('admin.name') %>
|
||||
<%= f.text_field :name, :class => 'text' %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label :description, t('admin.description') %>
|
||||
<%= f.text_field :description, :class => 'text' %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label "content", t('admin.content') %>
|
||||
<%= f.text_area :content, :size => '100x30' %>
|
||||
</p>
|
|
@ -1,9 +0,0 @@
|
|||
<h1><%= t('admin.editing_layout') %></h1>
|
||||
|
||||
<%= form_for @layout, :url => admin_layout_path(@layout) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
<%= render :partial => "form", :locals => { :f => f } %>
|
||||
<p>
|
||||
<%= f.submit t('update') %> <%= link_back %>
|
||||
</p>
|
||||
<% end %>
|
|
@ -1,28 +0,0 @@
|
|||
<% content_for :secondary do %>
|
||||
<ul class="list">
|
||||
<li><%= link_to t(:new_layout, :scope => :admin), new_admin_layout_path, :class => 'button positive' %></li>
|
||||
</ul>
|
||||
<% end -%>
|
||||
|
||||
<%= flash_messages %>
|
||||
|
||||
<h1><%= t('admin.list_layouts') %></h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th><%= t('admin.name') %></th>
|
||||
<th><%= t('admin.description') %></th>
|
||||
<th><%= t('admin.action') %></th>
|
||||
</tr>
|
||||
|
||||
<% @layouts.each do |layout| %>
|
||||
<tr>
|
||||
<td><%= layout.name %></td>
|
||||
<td><%= layout.description %></td>
|
||||
<td>
|
||||
<%= link_to t(:edit), edit_admin_layout_path(layout) %> |
|
||||
<%= link_to t(:delete), admin_layout_path(layout), :confirm => t('sure?'), :method => :delete %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
|
@ -1,10 +0,0 @@
|
|||
<h1><%= t('admin.new_layout') %></h1>
|
||||
|
||||
<%= form_for :layout, :url => admin_layouts_path do |f| %>
|
||||
<%= f.error_messages %>
|
||||
<%= render :partial => "form", :locals => { :f => f } %>
|
||||
|
||||
<p>
|
||||
<%= f.submit t('create') %> <%= link_back %>
|
||||
</p>
|
||||
<% end %>
|
|
@ -28,18 +28,17 @@
|
|||
</div>
|
||||
|
||||
<div id="header">
|
||||
|
||||
<h1>RulingSite <%= t('admin.admin') %></h1>
|
||||
|
||||
<ul id="nav">
|
||||
<li><%= link_to t('homepage'), root_path %></li>
|
||||
<li><%= link_to t('admin.layout'), admin_layouts_path %></li>
|
||||
<li><%= link_to t('admin.design'), admin_designs_path %></li>
|
||||
<li><%= link_to t('admin.asset'), admin_assets_path %></li>
|
||||
<li><%= link_to t('admin.user_info'), admin_user_info_models_path %></li>
|
||||
<li><%= link_to t('admin.user_role'), admin_user_role_models_path %></li>
|
||||
<li><%= link_to t('admin.translation'), admin_translations_path %></li>
|
||||
</ul>
|
||||
<h1>RulingSite <%= t('admin.admin') %></h1>
|
||||
<ul id="nav">
|
||||
<li><%= link_to t('homepage'), root_path %></li>
|
||||
<li><%= link_to t('admin.item'), admin_items_path %></li>
|
||||
<li><%= link_to t('admin.design'), admin_designs_path %></li>
|
||||
<li><%= link_to t('admin.purchase'), admin_purchases_path %></li>
|
||||
<li><%= link_to t('admin.asset'), admin_assets_path %></li>
|
||||
<li><%= link_to t('admin.user_info'), admin_user_info_models_path %></li>
|
||||
<li><%= link_to t('admin.user_role'), admin_user_role_models_path %></li>
|
||||
<li><%= link_to t('admin.translation'), admin_translations_path %></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
<link rel="shortcut icon" href="/favicon.ico">
|
||||
<%= 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 %>
|
||||
<!--[if IE]>
|
||||
<%= stylesheet_link_tag "ie", :media => "screen, projection" %>
|
||||
|
@ -21,7 +21,8 @@
|
|||
<ul id="panel_nav">
|
||||
<li><%= link_to t('homepage'), root_path %></li>
|
||||
<li><%= link_to t('admin.item'), admin_items_path %></li>
|
||||
<li><%= link_to t('admin.layout'), admin_layouts_path %></li>
|
||||
<li><%= link_to t('admin.design'), admin_designs_path %></li>
|
||||
<li><%= link_to t('admin.purchase'), admin_purchases_path %></li>
|
||||
<li><%= link_to t('admin.asset'), admin_assets_path %></li>
|
||||
<li><%= link_to t('admin.user_info'), admin_user_info_models_path %></li>
|
||||
<li><%= link_to t('admin.user_role'), admin_user_role_models_path %></li>
|
||||
|
|
|
@ -2,8 +2,6 @@ PrototypeR4::Application.routes.draw do
|
|||
|
||||
devise_for :users
|
||||
|
||||
resources :sites
|
||||
|
||||
# routes for sinatra app
|
||||
match '/site/set_registered', :to => CentralServerExchangeApp
|
||||
match '/site/public_key', :to => CentralServerExchangeApp
|
||||
|
@ -20,7 +18,6 @@ PrototypeR4::Application.routes.draw do
|
|||
end
|
||||
end
|
||||
resources :items
|
||||
resources :layouts
|
||||
resources :links do
|
||||
member do
|
||||
get 'delete'
|
||||
|
@ -37,7 +34,7 @@ PrototypeR4::Application.routes.draw do
|
|||
get 'download'
|
||||
end
|
||||
end
|
||||
resources :homes
|
||||
resources :sites
|
||||
resources :snippets
|
||||
resources :translations
|
||||
resources :user_info_models
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
Naming convention:
|
||||
1 - The file names can only be changed inside themes, javascripts and images.
|
||||
2 - File names must not contain spaces, spaces must be replace by underscores
|
||||
3 - CSS files can only have the extensions ".css" or ".scss"
|
||||
4 - Javascript files must have the extension ".js"
|
||||
5 - Image files can have any extension
|
||||
|
||||
|
||||
Package content:
|
||||
My_design.zip
|
||||
- info.json
|
||||
- layout.html
|
||||
- structure.css
|
||||
- themes
|
||||
- default.css
|
||||
- blue.css
|
||||
- red.css
|
||||
- javascripts
|
||||
- one.js
|
||||
- two.js
|
||||
- images
|
||||
- pic.jpg
|
||||
- pic_1.png
|
||||
- pic_2.jpg
|
||||
- README
|
||||
|
||||
|
||||
"info.json" file:
|
||||
|
||||
Content:
|
||||
{
|
||||
"title": "your_title",
|
||||
"author": "your_author",
|
||||
"intro": "your_intro"
|
||||
}
|
||||
|
||||
Title: it's the title of your design as it's going to appeared in your website, it can contain spaces
|
||||
Author: it's the name of the creator of the design
|
||||
Intro: it's introduction that can contain more details about your design
|
||||
|
||||
|
||||
"layout.html" file:
|
||||
|
||||
This HTML file can contain 3 types of elements: headers, blocks and footers.
|
||||
Each element defining a header, a block or a footer must be a <div>.
|
||||
Furthermore, each of those <div> must include an <layout_part> as follow:
|
||||
|
||||
<div ID="div_1" class="header">
|
||||
<r:layout_part ID="div_1" class="header" name="header_1">
|
||||
// Your code here
|
||||
</r:layout_part>
|
||||
</div>
|
||||
|
||||
Attributes convention:
|
||||
- each pair of <div> and <layout_part> tags, must have the same ID and class.
|
||||
- the <r:layout_part> tag as one more attribute: "name", it must contain the type of the element followed by the number of the element (if you have 2 header elements, you will have "header_1" and "header_2"
|
||||
|
||||
Javascripts and stylsheets:
|
||||
|
||||
The links to your javascript files and stylesheet files must be encapsulated respectively in <r:javascripts></r:javascripts> and <stylesheets></stylesheets> tags.
|
||||
|
||||
|
||||
"strucutre.css" file:
|
||||
|
||||
The 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"…
|
||||
|
||||
|
||||
Themes:
|
||||
|
||||
Themes are stylesheet files that modify the visual aspects of the page.
|
||||
The themes folder must contain at least one file named "default.css" that will be the default theme.
|
||||
Themes stylesheets reference elements by class.
|
||||
They can set attributes like "color", "background-image", "border"…
|
||||
|
||||
|
||||
Javascripts:
|
||||
|
||||
This folder contains the javascript files used by the design.
|
||||
|
||||
|
||||
Images:
|
||||
|
||||
This folder contains the images used by the design.
|
||||
They can have the extensions ".jpg", ".png"...
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"title": "Fraisier",
|
||||
"author": "Paul",
|
||||
"intro": "Strawberry cake"
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>RulingSite</title>
|
||||
<r:stylesheets>
|
||||
<!-- your stylesheets here -->
|
||||
</r:stylesheets>
|
||||
<r:javascripts>
|
||||
<!-- your javascripts here -->
|
||||
</r:javascripts>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- example -->
|
||||
<div id="header_top" class="header">
|
||||
<r:layout_part id='header_top' class='header' name='header_1'>
|
||||
</r:layout_part>
|
||||
</div>
|
||||
<div id="header_bottom" class="header">
|
||||
<r:layout_part id='header_bottom' class='header' name='header_2'>
|
||||
</r:layout_part>
|
||||
</div>
|
||||
|
||||
<div id="main_content" class="content">
|
||||
<r:layout_part id="main_content" class='content' name='block_1' editable="true">
|
||||
</r:layout_part>
|
||||
</div>
|
||||
|
||||
<div id="footer" class="footer">
|
||||
<r:layout_part id="footer" class='footer' name='footer_1'>
|
||||
</r:layout_part>
|
||||
</div>
|
||||
<!-- END example -->
|
||||
</body>
|
||||
</html>
|
|
@ -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"… */
|
|
@ -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"… */
|
|
@ -64,8 +64,19 @@ module Parser
|
|||
res
|
||||
end
|
||||
c.define_tag 'stylesheets' do |tag|
|
||||
contents = tag.expand
|
||||
contents.to_html
|
||||
res = ''
|
||||
res << "<link href='#{page.design.structure_css.url}' rel='stylesheet' type='text/css' /> "
|
||||
page.design.themes.each do |theme|
|
||||
res << "<link href='#{theme.file.url}' rel='stylesheet' type='text/css' /> "
|
||||
end
|
||||
res
|
||||
end
|
||||
c.define_tag 'javascripts' do |tag|
|
||||
res = ''
|
||||
page.design.javascripts.each do |js|
|
||||
res << "<script type='text/javascript' src='#{js.file.url}'></script>"
|
||||
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 << "<link href='#{page.design.structure_css.url}' rel='stylesheet' type='text/css' />"
|
||||
page.design.themes.each do |theme|
|
||||
res << "<link href='#{theme.file.url}' rel='stylesheet' type='text/css' />"
|
||||
end
|
||||
res
|
||||
end
|
||||
c.define_tag 'javascripts' do |tag|
|
||||
res = ''
|
||||
page.design.javascripts.each do |js|
|
||||
res << "<script type='text/javascript' src='#{js.file.url}'></script>"
|
||||
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 }
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace :dev do
|
|||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue