Clean code and add 'name' in theme.rb
This commit is contained in:
parent
118455aa81
commit
608180646b
2
Gemfile
2
Gemfile
|
@ -4,7 +4,7 @@ gem 'rails', '>=3.1.0.rc4'
|
|||
gem 'yajl-ruby', :require => 'yajl'
|
||||
|
||||
gem 'bson_ext'
|
||||
gem 'carrierwave', '0.5.6'
|
||||
gem 'carrierwave', '0.5.4'
|
||||
gem 'ckeditor'
|
||||
gem 'devise'
|
||||
gem 'mini_magick'
|
||||
|
|
|
@ -36,7 +36,7 @@ GEM
|
|||
bson (1.3.1)
|
||||
bson_ext (1.3.1)
|
||||
builder (3.0.0)
|
||||
carrierwave (0.5.6)
|
||||
carrierwave (0.5.4)
|
||||
activesupport (~> 3.0)
|
||||
chronic (0.6.2)
|
||||
ckeditor (3.6.1)
|
||||
|
@ -171,7 +171,7 @@ PLATFORMS
|
|||
|
||||
DEPENDENCIES
|
||||
bson_ext
|
||||
carrierwave (= 0.5.6)
|
||||
carrierwave (= 0.5.4)
|
||||
ckeditor
|
||||
coffee-rails (~> 3.1.0.rc)
|
||||
delorean
|
||||
|
|
|
@ -21,14 +21,11 @@ class Admin::PagesController < ApplicationController
|
|||
@item = Page.new
|
||||
@item.is_published = true
|
||||
@item.parent_id = @parent_item.id rescue nil
|
||||
@designs = Design.all.entries
|
||||
@default_design = @designs.detect {|d| d.title.to_s == 'Bob' }
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def create
|
||||
|
@ -51,19 +48,6 @@ class Admin::PagesController < ApplicationController
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def destroy
|
||||
|
|
|
@ -12,7 +12,6 @@ module Admin::ItemHelper
|
|||
ret << "<ul>"
|
||||
ret << "<li>"
|
||||
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_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')
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
class Theme < Stylesheet
|
||||
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
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class Page < Item
|
||||
|
||||
field :content
|
||||
field :design_name
|
||||
|
||||
validates_presence_of :design_name, :design_id
|
||||
validates_presence_of :design_id
|
||||
|
||||
belongs_to :design
|
||||
belongs_to :theme
|
||||
has_many :page_parts
|
||||
|
||||
def create_parts
|
||||
|
@ -27,15 +27,4 @@ class Page < Item
|
|||
Design.find(design_id)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def setup_default_value
|
||||
super
|
||||
|
||||
if self.design_id
|
||||
self.design_name = get_design.title
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -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 %>
|
|
@ -15,8 +15,14 @@
|
|||
<% end %>
|
||||
|
||||
<p>
|
||||
<%= f.label :design_id, t('admin.design_name') %>
|
||||
<%= f.select :design_id, Design.all.map{ |l| [l.title, l.id] } %>
|
||||
<%= t('admin.design_name') %>
|
||||
<%= f.select :design_id, @designs.collect { |d| [d.title, d.id] }, :selected => @default_design.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>
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
<%= f.error_messages %>
|
||||
|
||||
<%= f.text_area :content %>
|
|
@ -1,15 +0,0 @@
|
|||
<% 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 %>
|
|
@ -1 +0,0 @@
|
|||
$('#panel_main').html("<%= escape_javascript(render(:partial => @code ? 'edit_code' : 'edit')) %>");
|
|
@ -2,4 +2,4 @@
|
|||
<%= render 'admin/items/site_map_left_bar' %>
|
||||
<% end -%>
|
||||
|
||||
<%= render @code ? 'show_code' : 'show' %>
|
||||
<%= render 'show' %>
|
|
@ -1,2 +0,0 @@
|
|||
$('#panel_main').html("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>");
|
||||
history.pushState(null, document.title, "<%= escape_javascript(admin_page_url(@item)) %>");
|
|
@ -0,0 +1 @@
|
|||
/* Some css */
|
102
lib/parser.rb
102
lib/parser.rb
|
@ -105,12 +105,6 @@ module Parser
|
|||
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)
|
||||
if page._type == 'Page'
|
||||
layout_content = page.design.layout.content
|
||||
|
@ -214,33 +208,6 @@ module Parser
|
|||
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)
|
||||
content = layout.content
|
||||
|
@ -265,75 +232,6 @@ module Parser
|
|||
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)
|
||||
base.send :helper_method, :parse_page if base.respond_to? :helper_method
|
||||
|
|
|
@ -75,25 +75,47 @@ namespace :dev do
|
|||
#
|
||||
# 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.layout.file = File.open("#{Rails.root}/lib/fraisier/layout.html")
|
||||
|
||||
design.layout.save
|
||||
# theme.save
|
||||
theme.save
|
||||
theme_1.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')
|
||||
|
||||
|
||||
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.id, :name => 'home', :is_published => true )
|
||||
home.page_parts.create!( :name => 'header_1', :kind => 'text')
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue