Revert "Clean code and add 'name' in theme.rb"
This reverts commit 608180646b
.
This commit is contained in:
parent
608180646b
commit
00813c9060
2
Gemfile
2
Gemfile
|
@ -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.4'
|
gem 'carrierwave', '0.5.6'
|
||||||
gem 'ckeditor'
|
gem 'ckeditor'
|
||||||
gem 'devise'
|
gem 'devise'
|
||||||
gem 'mini_magick'
|
gem 'mini_magick'
|
||||||
|
|
|
@ -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.4)
|
carrierwave (0.5.6)
|
||||||
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.4)
|
carrierwave (= 0.5.6)
|
||||||
ckeditor
|
ckeditor
|
||||||
coffee-rails (~> 3.1.0.rc)
|
coffee-rails (~> 3.1.0.rc)
|
||||||
delorean
|
delorean
|
||||||
|
|
|
@ -21,11 +21,14 @@ 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.content = parse_content(@item.content, {:locale => 'show'})
|
||||||
|
@item.content = parse_page_code(@item)
|
||||||
|
@i18n_variable = @item.i18n_variable
|
||||||
|
@code = params[:code]
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -48,6 +51,19 @@ class Admin::PagesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
@item = Page.find(params[:id])
|
||||||
|
parse_content_update_code(@item, params[:page][:content])
|
||||||
|
if @item.update_attributes(params[:item])
|
||||||
|
flash[:notice] = t('admin.update_success_page')
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
redirect_to admin_page_url(@item)
|
||||||
|
}
|
||||||
|
format.js {}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render :action => "edit"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|
|
@ -12,6 +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.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')
|
||||||
|
|
|
@ -1,15 +1,3 @@
|
||||||
class Theme < Stylesheet
|
class Theme < Stylesheet
|
||||||
embedded_in :design
|
embedded_in :design
|
||||||
field :name
|
|
||||||
|
|
||||||
has_many :pages
|
|
||||||
|
|
||||||
before_save :set_name
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def set_name
|
|
||||||
self.name = self.file_filename.split('.')[0]
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
class Page < Item
|
class Page < Item
|
||||||
|
|
||||||
field :content
|
field :content
|
||||||
|
field :design_name
|
||||||
|
|
||||||
validates_presence_of :design_id
|
validates_presence_of :design_name, :design_id
|
||||||
|
|
||||||
belongs_to :design
|
belongs_to :design
|
||||||
belongs_to :theme
|
|
||||||
has_many :page_parts
|
has_many :page_parts
|
||||||
|
|
||||||
def create_parts
|
def create_parts
|
||||||
|
@ -27,4 +27,15 @@ 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
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
<%= 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 %>
|
|
@ -15,14 +15,8 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<%= t('admin.design_name') %>
|
<%= f.label :design_id, t('admin.design_name') %>
|
||||||
<%= f.select :design_id, @designs.collect { |d| [d.title, d.id] }, :selected => @default_design.id %>
|
<%= f.select :design_id, Design.all.map{ |l| [l.title, l.id] } %>
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<%= @item.design.inspect %>
|
|
||||||
<%= 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.collection_select :design, @designs, :id, :title %>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
<%= f.error_messages %>
|
||||||
|
|
||||||
|
<%= f.text_area :content %>
|
|
@ -0,0 +1,15 @@
|
||||||
|
<% content_for :sidebar do %>
|
||||||
|
<%= render 'admin/items/site_map_left_bar' %>
|
||||||
|
<% end -%>
|
||||||
|
|
||||||
|
<h1><%= t('admin.editing_page') %></h1>
|
||||||
|
|
||||||
|
<%= 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 %>
|
|
@ -0,0 +1 @@
|
||||||
|
$('#panel_main').html("<%= escape_javascript(render(:partial => @code ? 'edit_code' : 'edit')) %>");
|
|
@ -2,4 +2,4 @@
|
||||||
<%= render 'admin/items/site_map_left_bar' %>
|
<%= render 'admin/items/site_map_left_bar' %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
||||||
<%= render 'show' %>
|
<%= render @code ? 'show_code' : 'show' %>
|
|
@ -0,0 +1,2 @@
|
||||||
|
$('#panel_main').html("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>");
|
||||||
|
history.pushState(null, document.title, "<%= escape_javascript(admin_page_url(@item)) %>");
|
|
@ -1 +0,0 @@
|
||||||
/* Some css */
|
|
104
lib/parser.rb
104
lib/parser.rb
|
@ -105,6 +105,12 @@ 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
|
||||||
|
@ -208,6 +214,33 @@ 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
|
||||||
|
@ -232,7 +265,76 @@ 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
|
||||||
base.send :helper_method, :parse_page_edit if base.respond_to? :helper_method
|
base.send :helper_method, :parse_page_edit if base.respond_to? :helper_method
|
||||||
|
|
|
@ -75,47 +75,25 @@ 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/themes/default.css"))
|
# theme = design.themes.build(:file => File.open("#{Rails.root}/lib/fraisier/inettuts.js.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_1 = Design.new(:title => "Bob", :author => "Me", :intro => "Moran")
|
design.layout.layout_parts.create!( :name => 'block_1')
|
||||||
|
design.layout.layout_parts.create!( :name => 'footer_1')
|
||||||
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.id, :name => 'home', :is_published => true )
|
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', :content => File.open("#{Rails.root}/lib/template/home.page").read, :kind => 'text', :i18n_variable_id => var_13.id )
|
home.page_parts.create!( :name => 'header_1', :kind => 'text')
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue