Merge branch 'rails_3_1' of github.com:Rulingcom/orbit into rails_3_1

This commit is contained in:
chris2tof 2011-08-25 08:08:09 +08:00
commit c678545160
17 changed files with 77 additions and 161 deletions

View File

@ -4,7 +4,7 @@ gem 'rails', '>=3.1.0.rc4'
gem 'yajl-ruby', :require => 'yajl' gem 'yajl-ruby', :require => 'yajl'
gem 'bson_ext' gem 'bson_ext'
gem 'carrierwave', '0.5.6' gem 'carrierwave', '0.5.4'
gem 'ckeditor' gem 'ckeditor'
gem 'devise' gem 'devise'
gem 'mini_magick' gem 'mini_magick'

View File

@ -36,7 +36,7 @@ GEM
bson (1.3.1) bson (1.3.1)
bson_ext (1.3.1) bson_ext (1.3.1)
builder (3.0.0) builder (3.0.0)
carrierwave (0.5.6) carrierwave (0.5.4)
activesupport (~> 3.0) activesupport (~> 3.0)
chronic (0.6.2) chronic (0.6.2)
ckeditor (3.6.1) ckeditor (3.6.1)
@ -171,7 +171,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
bson_ext bson_ext
carrierwave (= 0.5.6) carrierwave (= 0.5.4)
ckeditor ckeditor
coffee-rails (~> 3.1.0.rc) coffee-rails (~> 3.1.0.rc)
delorean delorean

View File

@ -21,14 +21,16 @@ class Admin::PagesController < ApplicationController
@item = Page.new @item = Page.new
@item.is_published = true @item.is_published = true
@item.parent_id = @parent_item.id rescue nil @item.parent_id = @parent_item.id rescue nil
@designs = Design.all.entries
@default_design = @designs.detect {|d| d.title.to_s == 'Bob' }
end end
def edit def edit
@item = Page.find(params[:id]) @item = Page.find(params[:id])
# @item.content = parse_content(@item.content, {:locale => 'show'})
@item.content = parse_page_code(@item)
@i18n_variable = @item.i18n_variable @i18n_variable = @item.i18n_variable
@code = params[:code] @designs = Design.all.entries
@design = @item.design
@default_design = @design.themes.detect {|t| t.id == @item.theme_id }
end end
def create def create
@ -52,7 +54,6 @@ class Admin::PagesController < ApplicationController
def update def update
@item = Page.find(params[:id]) @item = Page.find(params[:id])
parse_content_update_code(@item, params[:page][:content])
if @item.update_attributes(params[:item]) if @item.update_attributes(params[:item])
flash[:notice] = t('admin.update_success_page') flash[:notice] = t('admin.update_success_page')
respond_to do |format| respond_to do |format|

View File

@ -12,7 +12,7 @@ module Admin::ItemHelper
ret << "<ul>" ret << "<ul>"
ret << "<li>" ret << "<li>"
ret << (link_to node.name, dest) ret << (link_to node.name, dest)
ret << ' | ' << (link_to t('admin.code'), eval("edit_admin_#{node._type.downcase}_path(node, :code => true)")) if node._type.eql?('Page') ret << ' | ' << (link_to t('admin.edit'), eval("edit_admin_#{node._type.downcase}_path(node)")) if node._type.eql?('Page')
ret << ' | ' << (link_to t('admin.new_page'), new_admin_page_path(:parent_id => node.id), :class => 'new_page') if node._type.eql?('Page') ret << ' | ' << (link_to t('admin.new_page'), new_admin_page_path(:parent_id => node.id), :class => 'new_page') if node._type.eql?('Page')
ret << ' | ' << (link_to t('admin.new_link'), new_admin_link_path(:parent_id => node.id), :class => 'new_link') if node._type.eql?('Page') ret << ' | ' << (link_to t('admin.new_link'), new_admin_link_path(:parent_id => node.id), :class => 'new_link') if node._type.eql?('Page')
ret << ' | ' << (link_to t(:delete), eval("delete_admin_#{node._type.downcase}_path(node, :authenticity_token => form_authenticity_token)"), :confirm => t('sure?'), :class => 'delete') ret << ' | ' << (link_to t(:delete), eval("delete_admin_#{node._type.downcase}_path(node, :authenticity_token => form_authenticity_token)"), :confirm => t('sure?'), :class => 'delete')

View File

@ -1,3 +1,13 @@
class Theme < Stylesheet class Theme < Stylesheet
embedded_in :design embedded_in :design
field :name
before_save :set_name
protected
def set_name
self.name = self.file_filename.split('.')[0]
end
end end

View File

@ -1,9 +1,9 @@
class Page < Item class Page < Item
field :content field :content
field :design_name field :theme_id
validates_presence_of :design_name, :design_id validates_presence_of :design_id
belongs_to :design belongs_to :design
has_many :page_parts has_many :page_parts
@ -27,15 +27,4 @@ class Page < Item
Design.find(design_id) Design.find(design_id)
end end
protected
def setup_default_value
super
if self.design_id
self.design_name = get_design.title
end
end
end end

View File

@ -0,0 +1,10 @@
<%= flash_messages %>
<h1><%= t('admin.editing_page') %></h1>
<%= form_for @item, :url => admin_page_path(@item) do |f| %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit t('update') %> <%= link_back %>
</p>
<% end %>

View File

@ -1,8 +0,0 @@
<%= flash_messages %>
<%= form_for @item, :url => admin_page_path(@item), :html => { :class => 'form' } do |f| %>
<%= render :partial => "admin/pages/form_code", :locals => { :f => f, :locale => locale } %>
<p>
<%= f.submit t(:update) %> <%= link_back %>
</p>
<% end %>

View File

@ -15,8 +15,14 @@
<% end %> <% end %>
<p> <p>
<%= f.label :design_id, t('admin.design_name') %> <%= t('admin.design_name') %>
<%= f.select :design_id, Design.all.map{ |l| [l.title, l.id] } %> <%#= f.select :design_id, @designs.collect { |d| [d.title, d.id] }, :selected => @default_design.id %>
<%= f.select :design_id, @designs.collect { |d| [d.title, d.id] } %>
</p>
<p>
<%= t('admin.theme') %>
<%#= f.select :theme_id, @default_design.themes.collect { |t| [t.name, t.id] }, :selected => @default_design.themes.detect {|t| t.file_filename.to_s == 'default.css' }.id %>
<%= f.select :theme_id, @design.themes.collect { |t| [t.name, t.id] }%>
</p> </p>
<p> <p>

View File

@ -1,3 +0,0 @@
<%= f.error_messages %>
<%= f.text_area :content %>

View File

@ -2,14 +2,4 @@
<%= render 'admin/items/site_map_left_bar' %> <%= render 'admin/items/site_map_left_bar' %>
<% end -%> <% end -%>
<h1><%= t('admin.editing_page') %></h1> <%= render 'edit' %>
<%= form_for @item, :url => admin_page_path(@item) do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit t('update') %> <%= link_back %>
</p>
<% end %>

View File

@ -1 +1 @@
$('#panel_main').html("<%= escape_javascript(render(:partial => @code ? 'edit_code' : 'edit')) %>"); $('#panel_main').html("<%= escape_javascript(render 'edit') %>");

View File

@ -2,4 +2,4 @@
<%= render 'admin/items/site_map_left_bar' %> <%= render 'admin/items/site_map_left_bar' %>
<% end -%> <% end -%>
<%= render @code ? 'show_code' : 'show' %> <%= render 'show' %>

View File

@ -0,0 +1 @@
/* Some css */

View File

@ -105,12 +105,6 @@ module Parser
end end
end end
def parse_content(page_content, attributes = {})
context = parser_context(page_content, attributes)
parser = Radius::Parser.new(context, :tag_prefix => 'r')
parser.parse(page_content)
end
def parse_page(page) def parse_page(page)
if page._type == 'Page' if page._type == 'Page'
layout_content = page.design.layout.content layout_content = page.design.layout.content
@ -214,33 +208,6 @@ module Parser
end end
end end
def parse_page_code(page)
layout_content = page.design.layout.content
context = parser_context_code(page)
parser = Radius::Parser.new(context, :tag_prefix => 'r')
parser.parse(layout_content)
end
def parser_context_code(page) #context should be interpretd as the orginally one
Radius::Context.new do |c|
c.define_tag 'stylesheets' do |tag|
res << "<r:layout_part>"
res << tag.expand.to_s
res << "</r:layout_part>"
end
c.define_tag 'layout_part' do |tag|
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }
res = ''
res << "<r:layout_part"
tag.attr.each do |l|
res << " #{l[0]}='#{l[1]}'"
end
res << ">"
res << part.content if part
res << "</r:layout_part>"
end
end
end
#============= #=============
def parse_layout_layout_part(layout) def parse_layout_layout_part(layout)
content = layout.content content = layout.content
@ -265,75 +232,6 @@ module Parser
end end
end end
end end
#============
def parse_content_update_code(page, page_content)
context = parser_context_update_code(page, page_content)
parser = Radius::Parser.new(context, :tag_prefix => 'r')
parser.parse(page_content)
end
def parser_context_update_code(page, page_content)
Radius::Context.new do |c|
c.define_tag 'layout_part' do |tag|
@part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }
tag.locals.name = tag.attr['name'].to_s
if @part
part_update = tag.expand
if part_update
if !part_update.eql?(@part.content)
@part.content = tag.expand
@part.save
tag.locals.action = 'update'
end
else
tag.locals.action = 'destroy'
end
else
tag.locals.action = 'new'
end
res = ''
res << "<r:layout_part"
tag.attr.each do |l|
res << " #{l[0]}='#{l[1]}'"
end
res << ">"
res << tag.expand
res << "</r:layout_part>"
end
c.define_tag 'multi_lang' do |tag|
case tag.locals.action
when 'new', 'update'
@h = {}
tag.expand
@part.i18n_variable = @h
when 'destroy'
else
res = ''
res << "<r:multi_lang"
tag.attr.each do |l|
res << " #{l[0]}='#{l[1]}'"
end
res << ">"
res << tag.expand
res << "</r:multi_lang>"
end
end
c.define_tag 'multi_lang:lang' do |tag|
if tag.locals.action
@h.merge!(tag.attr['name'] => "#{tag.expand}")
else
res = ''
res << "<r:lang"
tag.attr.each do |l|
res << " #{l[0]}='#{l[1]}'"
end
res << ">"
res << tag.expand
res << "</r:lang>"
end
end
end
end
def self.included(base) def self.included(base)
base.send :helper_method, :parse_page if base.respond_to? :helper_method base.send :helper_method, :parse_page if base.respond_to? :helper_method

View File

@ -75,25 +75,47 @@ namespace :dev do
# #
# js = design.javascripts.build(:file => File.open("#{Rails.root}/lib/fraisier/inettuts.js")) # 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")) theme = design.themes.build(:file => File.open("#{Rails.root}/lib/fraisier/themes/default.css"))
theme_1 = design.themes.build(:file => File.open("#{Rails.root}/lib/fraisier/themes/red.css"))
design.build_layout design.build_layout
design.layout.file = File.open("#{Rails.root}/lib/fraisier/layout.html") design.layout.file = File.open("#{Rails.root}/lib/fraisier/layout.html")
design.layout.save design.layout.save
# theme.save theme.save
theme_1.save
# image.save # image.save
# js.save # js.save
design.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') design_1 = Design.new(:title => "Bob", :author => "Me", :intro => "Moran")
design_1.structure_css = File.open("#{Rails.root}/lib/fraisier/structure.css")
# 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_1.themes.build(:file => File.open("#{Rails.root}/lib/fraisier/themes/default.css"))
theme_1 = design_1.themes.build(:file => File.open("#{Rails.root}/lib/fraisier/themes/red.css"))
design_1.build_layout
design_1.layout.file = File.open("#{Rails.root}/lib/fraisier/layout.html")
design_1.layout.save
theme.save
theme_1.save
# image.save
# js.save
design_1.save
home = Page.create!( :i18n_variable_id => var_10.id, :design_id => design_1.id, :name => 'home', :is_published => true, :theme_id => theme.id )
home.page_parts.create!( :name => 'header_1', :content => File.open("#{Rails.root}/lib/template/home.page").read, :kind => 'text', :i18n_variable_id => var_13.id )
end end