diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index c5ab9907..d6992c71 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -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 diff --git a/app/helpers/admin/item_helper.rb b/app/helpers/admin/item_helper.rb index c0472f17..98dae928 100644 --- a/app/helpers/admin/item_helper.rb +++ b/app/helpers/admin/item_helper.rb @@ -11,6 +11,7 @@ module Admin::ItemHelper end ret << "
+ <%= f.submit t(:update) %> <%= link_back %> +
+<% end %> \ No newline at end of file diff --git a/app/views/admin/pages/_form_code.html.erb b/app/views/admin/pages/_form_code.html.erb new file mode 100644 index 00000000..ad0e55ed --- /dev/null +++ b/app/views/admin/pages/_form_code.html.erb @@ -0,0 +1,3 @@ +<%= f.error_messages %> + +<%= f.text_area :content %> \ No newline at end of file diff --git a/app/views/admin/pages/create.js.erb b/app/views/admin/pages/create.js.erb index 5d59fd1d..9c4b31c7 100644 --- a/app/views/admin/pages/create.js.erb +++ b/app/views/admin/pages/create.js.erb @@ -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')) %>"); \ No newline at end of file +$('#main').html("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>"); +history.pushState(null, document.title, "<%= escape_javascript(admin_page_url(@item)) %>"); \ No newline at end of file diff --git a/app/views/admin/pages/edit.js.erb b/app/views/admin/pages/edit.js.erb new file mode 100644 index 00000000..c0761ed6 --- /dev/null +++ b/app/views/admin/pages/edit.js.erb @@ -0,0 +1 @@ +$('#main').html("<%= escape_javascript(render(:partial => @code ? 'edit_code' : 'edit')) %>"); \ No newline at end of file diff --git a/app/views/admin/pages/show.html.erb b/app/views/admin/pages/show.html.erb index 3e1160c7..5371ccde 100644 --- a/app/views/admin/pages/show.html.erb +++ b/app/views/admin/pages/show.html.erb @@ -1 +1 @@ -<%= render 'show' %> \ No newline at end of file +<%= render @code ? 'show_code' : 'show' %> \ No newline at end of file diff --git a/app/views/admin/pages/update.js.erb b/app/views/admin/pages/update.js.erb new file mode 100644 index 00000000..6c6a1630 --- /dev/null +++ b/app/views/admin/pages/update.js.erb @@ -0,0 +1,2 @@ +$('#main').html("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>"); +history.pushState(null, document.title, "<%= escape_javascript(admin_page_url(@item)) %>"); \ No newline at end of file diff --git a/lib/parser.rb b/lib/parser.rb index 51580e48..7f24c8a8 100644 --- a/lib/parser.rb +++ b/lib/parser.rb @@ -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 << "