Revert "Clean code and add 'name' in theme.rb"

This reverts commit 608180646b.
This commit is contained in:
chris2tof committed 2011-08-24 02:04:54 +08:00
1 parent 608180646b
commit 00813c9060
16 files changed
+177 -59

No files matched your search

-1
View File
@@ -1 +0,0 @@
/* Some css */
+103 -1
View File
@@ -105,6 +105,12 @@ 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
@@ -208,6 +214,33 @@ 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
@@ -232,7 +265,76 @@ 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
base.send :helper_method, :parse_page_edit if base.respond_to? :helper_method
+7 -29
View File
@@ -75,47 +75,25 @@ 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/themes/default.css"))
theme_1 = design.themes.build(:file => File.open("#{Rails.root}/lib/fraisier/themes/red.css"))
# 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
theme_1.save
# theme.save
# image.save
# js.save
design.save
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
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', :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