HTML code can be modify (paser: update)

This commit is contained in:
chris2tof committed 2011-06-10 10:31:50 +08:00
1 parent dda4b30d67
commit 247b8ec4dc
12 files changed
+127 -13

No files matched your search

+93
View File
@@ -184,9 +184,102 @@ module Parser
end
end
def parse_page_code(page)
layout_content = page.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)
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 }
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_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
base.send :helper_method, :parse_page_code if base.respond_to? :helper_method
end
end
+1 -2
View File
@@ -1,5 +1,4 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>