HTML code can be modify (paser: update)
This commit is contained in:
parent
dda4b30d67
commit
247b8ec4dc
|
@ -25,8 +25,10 @@ class Admin::PagesController < ApplicationController
|
|||
|
||||
def edit
|
||||
@item = Page.find(params[:id])
|
||||
@item.content = parse_content(@item.content, {:locale => 'show'})
|
||||
# @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
|
||||
|
@ -39,7 +41,7 @@ class Admin::PagesController < ApplicationController
|
|||
format.html {
|
||||
redirect_to admin_page_url(@item)
|
||||
}
|
||||
format.js {}
|
||||
format.js {}
|
||||
end
|
||||
else
|
||||
flash.now[:error] = t('admin.create_error_page')
|
||||
|
@ -50,12 +52,15 @@ class Admin::PagesController < ApplicationController
|
|||
|
||||
def update
|
||||
@item = Page.find(params[:id])
|
||||
parse_content(@item.content, {:locale => 'destroy'})
|
||||
if @item.update_attributes(params[:page])
|
||||
@item.content = parse_content(@item.content, {:locale => 'create'})
|
||||
@item.save!
|
||||
parse_content_update_code(@item, params[:page][:content])
|
||||
if @item.update_attributes(params[:item])
|
||||
flash[:notice] = t('admin.update_success_page')
|
||||
redirect_to admin_items_url( :parent_id => @item.parent_id )
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
redirect_to admin_page_url(@item)
|
||||
}
|
||||
format.js {}
|
||||
end
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
|
|
|
@ -11,6 +11,7 @@ module Admin::ItemHelper
|
|||
end
|
||||
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)) if node._type.eql?('Page')
|
||||
ret << ' | ' << (link_to t('admin.new_link'), new_admin_link_path(:parent_id => node.id)) 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')
|
||||
|
|
|
@ -20,7 +20,7 @@ class PagePart
|
|||
if self.i18n_variable_id
|
||||
self.i18n_variable.update_attributes(attr)
|
||||
else
|
||||
var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class, :parent_id => self.page.i18n_variable_id}))
|
||||
var = I18nVariable.new(attr.merge({:key => self.name, :document_class => self.class, :parent_id => self.page.i18n_variable_id}))
|
||||
var.save
|
||||
self.i18n_variable_id = var.id
|
||||
end
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
$('#sidebar').html("<%= escape_javascript(render(:partial => 'admin/items/site_map_left_bar')) %>");
|
||||
$('#main').html("<%= escape_javascript(render(:partial => 'admin/links/show')) %>");
|
||||
$('#main').html("<%= escape_javascript(render(:partial => 'admin/links/show')) %>");
|
||||
history.pushState(null, document.title, "<%= escape_javascript(admin_link_url(@item)) %>");
|
|
@ -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 %>
|
|
@ -0,0 +1,3 @@
|
|||
<%= f.error_messages %>
|
||||
|
||||
<%= f.text_area :content %>
|
|
@ -1,2 +1,3 @@
|
|||
$('#sidebar').html("<%= escape_javascript(render(:partial => 'admin/items/site_map_left_bar')) %>");
|
||||
$('#main').html("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>");
|
||||
$('#main').html("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>");
|
||||
history.pushState(null, document.title, "<%= escape_javascript(admin_page_url(@item)) %>");
|
|
@ -0,0 +1 @@
|
|||
$('#main').html("<%= escape_javascript(render(:partial => @code ? 'edit_code' : 'edit')) %>");
|
|
@ -1 +1 @@
|
|||
<%= render 'show' %>
|
||||
<%= render @code ? 'show_code' : 'show' %>
|
|
@ -0,0 +1,2 @@
|
|||
$('#main').html("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>");
|
||||
history.pushState(null, document.title, "<%= escape_javascript(admin_page_url(@item)) %>");
|
|
@ -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,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>
|
||||
|
|
Reference in New Issue