Uniformized: @page and @ link in @item
Change parser for page edition.
This commit is contained in:
		
							parent
							
								
									3d97c5bfda
								
							
						
					
					
						commit
						d971a8ecbe
					
				| 
						 | 
					@ -13,7 +13,6 @@ class Admin::ItemsController < ApplicationController
 | 
				
			||||||
      @item = Item.find(params[:item_id])
 | 
					      @item = Item.find(params[:item_id])
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      @item = Item.first(:conditions => {:parent_id => nil})
 | 
					      @item = Item.first(:conditions => {:parent_id => nil})
 | 
				
			||||||
      @page = @item
 | 
					 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,60 +7,60 @@ class Admin::LinksController < ApplicationController
 | 
				
			||||||
  before_filter :is_admin?
 | 
					  before_filter :is_admin?
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  def show
 | 
					  def show
 | 
				
			||||||
    @link ||= Link.find(params[:id])
 | 
					    @item ||= Link.find(params[:id])
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  def new
 | 
					  def new
 | 
				
			||||||
    @link = Link.new
 | 
					    @item = Link.new
 | 
				
			||||||
    @link.is_published = true
 | 
					    @item.is_published = true
 | 
				
			||||||
    @link.parent_id = Page.find(params[:parent_id]).id rescue nil
 | 
					    @item.parent_id = Page.find(params[:parent_id]).id rescue nil
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def edit
 | 
					  def edit
 | 
				
			||||||
    @link = Link.find(params[:id])
 | 
					    @item = Link.find(params[:id])
 | 
				
			||||||
    @i18n_variable = @link.i18n_variable
 | 
					    @i18n_variable = @item.i18n_variable
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def create
 | 
					  def create
 | 
				
			||||||
    @link = Link.new(params[:link])
 | 
					    @item = Link.new(params[:link])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if @link.save
 | 
					    if @item.save
 | 
				
			||||||
      flash.now[:notice] = t('admin.create_success_link')
 | 
					      flash.now[:notice] = t('admin.create_success_link')
 | 
				
			||||||
      respond_to do |format|
 | 
					      respond_to do |format|
 | 
				
			||||||
        format.html { 
 | 
					        format.html { 
 | 
				
			||||||
          redirect_to admin_link_url(@link) 
 | 
					          redirect_to admin_link_url(@item) 
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        format.js  {}
 | 
					        format.js  {}
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      flash.now[:error] = t('admin.create_error_link')
 | 
					      flash.now[:error] = t('admin.create_error_link')
 | 
				
			||||||
      @i18n_variable = @link.i18n_variable
 | 
					      @i18n_variable = @item.i18n_variable
 | 
				
			||||||
      render :action => "new"
 | 
					      render :action => "new"
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def update
 | 
					  def update
 | 
				
			||||||
    @link = Link.find(params[:id])
 | 
					    @item = Link.find(params[:id])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if @link.update_attributes(params[:link])
 | 
					    if @item.update_attributes(params[:link])
 | 
				
			||||||
      flash.now[:notice] = t('admin.update_success_link')
 | 
					      flash.now[:notice] = t('admin.update_success_link')
 | 
				
			||||||
      respond_to do |format|
 | 
					      respond_to do |format|
 | 
				
			||||||
        format.html { 
 | 
					        format.html { 
 | 
				
			||||||
          redirect_to admin_link_url(@link) 
 | 
					          redirect_to admin_link_url(@item) 
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        format.js  {}
 | 
					        format.js  {}
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      flash.now[:error] = t('admin.update_error_link')
 | 
					      flash.now[:error] = t('admin.update_error_link')
 | 
				
			||||||
      @i18n_variable = @link.i18n_variable
 | 
					      @i18n_variable = @item.i18n_variable
 | 
				
			||||||
      render :action => "edit"
 | 
					      render :action => "edit"
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def destroy
 | 
					  def destroy
 | 
				
			||||||
    @link = Link.find(params[:id])
 | 
					    @item = Link.find(params[:id])
 | 
				
			||||||
    @link.destroy
 | 
					    @item.destroy
 | 
				
			||||||
    @link.destroy_i18n_variable
 | 
					    @item.destroy_i18n_variable
 | 
				
			||||||
    respond_to do |format|
 | 
					    respond_to do |format|
 | 
				
			||||||
      format.html { 
 | 
					      format.html { 
 | 
				
			||||||
        redirect_to admin_items_url
 | 
					        redirect_to admin_items_url
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,54 @@
 | 
				
			||||||
 | 
					class Admin::PagePartsController < ApplicationController
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  layout "content"
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  before_filter :authenticate_user!
 | 
				
			||||||
 | 
					  before_filter :is_admin?
 | 
				
			||||||
 | 
					  before_filter :set_current_item
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  def show
 | 
				
			||||||
 | 
					    @part = PagePart.find(params[:id])
 | 
				
			||||||
 | 
					    respond_to do |format|
 | 
				
			||||||
 | 
					      format.html { 
 | 
				
			||||||
 | 
					        render 'admin/items/index' 
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      format.js  {}
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def new
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def edit
 | 
				
			||||||
 | 
					    @part = PagePart.find(params[:id])
 | 
				
			||||||
 | 
					    #@part.content = parse_content(@part.content, {:locale => 'show'})
 | 
				
			||||||
 | 
					    # @part = @part.i18n_variable
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def create
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def update
 | 
				
			||||||
 | 
					    @part = PagePart.find(params[:id])
 | 
				
			||||||
 | 
					    parse_content(@part.content, {:locale => 'destroy'})
 | 
				
			||||||
 | 
					    if @part.update_attributes(params[:page])
 | 
				
			||||||
 | 
					      @part.content = parse_content(@part.content, {:locale => 'create'})
 | 
				
			||||||
 | 
					      @part.save!
 | 
				
			||||||
 | 
					      flash[:notice] = t('admin.update_success_page')
 | 
				
			||||||
 | 
					      redirect_to admin_items_url( :parent_id => @part.page_id )
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      render :action => "edit"
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def destroy
 | 
				
			||||||
 | 
					    @item = Page.find(params[:id])
 | 
				
			||||||
 | 
					    @item.destroy
 | 
				
			||||||
 | 
					    @item.destroy_i18n_variable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    redirect_to admin_items_url( :parent_id => @item.parent_id )
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
| 
						 | 
					@ -8,10 +8,9 @@ class Admin::PagesController < ApplicationController
 | 
				
			||||||
  before_filter :set_current_item
 | 
					  before_filter :set_current_item
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  def show
 | 
					  def show
 | 
				
			||||||
    @page = Page.find(params[:id])
 | 
					    @item = Page.find(params[:id])
 | 
				
			||||||
    respond_to do |format|
 | 
					    respond_to do |format|
 | 
				
			||||||
      format.html { 
 | 
					      format.html { 
 | 
				
			||||||
        @item = @page
 | 
					 | 
				
			||||||
        render 'admin/items/index' 
 | 
					        render 'admin/items/index' 
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      format.js  {}
 | 
					      format.js  {}
 | 
				
			||||||
| 
						 | 
					@ -19,47 +18,47 @@ class Admin::PagesController < ApplicationController
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def new
 | 
					  def new
 | 
				
			||||||
    @page = Page.new
 | 
					    @item = Page.new
 | 
				
			||||||
    @page.is_published = true
 | 
					    @item.is_published = true
 | 
				
			||||||
    @page.parent_id = @parent_item.id rescue nil
 | 
					    @item.parent_id = @parent_item.id rescue nil
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def edit
 | 
					  def edit
 | 
				
			||||||
    @page = Page.find(params[:id])
 | 
					    @item = Page.find(params[:id])
 | 
				
			||||||
    @page.content = parse_content(@page.content, {:locale => 'show'})
 | 
					    @item.content = parse_content(@item.content, {:locale => 'show'})
 | 
				
			||||||
    @i18n_variable = @page.i18n_variable
 | 
					    @i18n_variable = @item.i18n_variable
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def create
 | 
					  def create
 | 
				
			||||||
    @page = Page.new(params[:page])
 | 
					    @item = Page.new(params[:page])
 | 
				
			||||||
    @page.content = parse_content(@page.content, {:locale => 'create'})
 | 
					    @item.content = parse_content(@item.content, {:locale => 'create'})
 | 
				
			||||||
    if @page.save
 | 
					    if @item.save
 | 
				
			||||||
      flash[:notice] = t('admin.create_success_page')
 | 
					      flash[:notice] = t('admin.create_success_page')
 | 
				
			||||||
      redirect_to admin_items_url( :parent_id => @page.parent_id )
 | 
					      redirect_to admin_items_url( :parent_id => @item.parent_id )
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
     render :action => "new"
 | 
					     render :action => "new"
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def update
 | 
					  def update
 | 
				
			||||||
    @page = Page.find(params[:id])
 | 
					    @item = Page.find(params[:id])
 | 
				
			||||||
    parse_content(@page.content, {:locale => 'destroy'})
 | 
					    parse_content(@item.content, {:locale => 'destroy'})
 | 
				
			||||||
    if @page.update_attributes(params[:page])
 | 
					    if @item.update_attributes(params[:page])
 | 
				
			||||||
      @page.content = parse_content(@page.content, {:locale => 'create'})
 | 
					      @item.content = parse_content(@item.content, {:locale => 'create'})
 | 
				
			||||||
      @page.save!
 | 
					      @item.save!
 | 
				
			||||||
      flash[:notice] = t('admin.update_success_page')
 | 
					      flash[:notice] = t('admin.update_success_page')
 | 
				
			||||||
      redirect_to admin_items_url( :parent_id => @page.parent_id )
 | 
					      redirect_to admin_items_url( :parent_id => @item.parent_id )
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      render :action => "edit"
 | 
					      render :action => "edit"
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def destroy
 | 
					  def destroy
 | 
				
			||||||
    @page = Page.find(params[:id])
 | 
					    @item = Page.find(params[:id])
 | 
				
			||||||
    @page.destroy
 | 
					    @item.destroy
 | 
				
			||||||
    @page.destroy_i18n_variable
 | 
					    @item.destroy_i18n_variable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    redirect_to admin_items_url( :parent_id => @page.parent_id )
 | 
					    redirect_to admin_items_url( :parent_id => @item.parent_id )
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,8 +18,8 @@ class ApplicationController < ActionController::Base
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  # Render the page
 | 
					  # Render the page
 | 
				
			||||||
  def render_page
 | 
					  def render_page
 | 
				
			||||||
    if @page
 | 
					    if @item
 | 
				
			||||||
      render :text => parse_page(@page)
 | 
					      render :text => parse_page(@item)
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      render :text => '404 Not Found'
 | 
					      render :text => '404 Not Found'
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
| 
						 | 
					@ -53,7 +53,7 @@ class ApplicationController < ActionController::Base
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  def set_current_item
 | 
					  def set_current_item
 | 
				
			||||||
    session[:current_page] = params[:id] || @page.id || @link.id || @item.id rescue nil
 | 
					    session[:current_page] = params[:id] || @item.id rescue nil
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,8 +1,8 @@
 | 
				
			||||||
class PagesController < ApplicationController
 | 
					class PagesController < ApplicationController
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  def index
 | 
					  def index
 | 
				
			||||||
    @page = Page.find_by_name('home')
 | 
					    @item = Page.find_by_name('home')
 | 
				
			||||||
    if @page
 | 
					    if @item
 | 
				
			||||||
      render_page
 | 
					      render_page
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      render :text => 'You need a home page'
 | 
					      render :text => 'You need a home page'
 | 
				
			||||||
| 
						 | 
					@ -14,7 +14,7 @@ class PagesController < ApplicationController
 | 
				
			||||||
      item = Item.first(:conditions => {:full_name => params[:page_name]})
 | 
					      item = Item.first(:conditions => {:full_name => params[:page_name]})
 | 
				
			||||||
      case item._type
 | 
					      case item._type
 | 
				
			||||||
        when 'Page'
 | 
					        when 'Page'
 | 
				
			||||||
          @page = item
 | 
					          @item = item
 | 
				
			||||||
          render_page
 | 
					          render_page
 | 
				
			||||||
        when 'Link'
 | 
					        when 'Link'
 | 
				
			||||||
          redirect_to "http://#{item[:url]}"
 | 
					          redirect_to "http://#{item[:url]}"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,6 @@ switch ("<%= escape_javascript(@item._type)%>") {
 | 
				
			||||||
		$('#main').append("<%= escape_javascript(render(:partial => 'admin/links/show')) %>");
 | 
							$('#main').append("<%= escape_javascript(render(:partial => 'admin/links/show')) %>");
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
  case 'Page': 
 | 
					  case 'Page': 
 | 
				
			||||||
		$('#main').append("<%= escape_javascript(render(:partial => 'page')) %>");
 | 
							$('#main').append("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>");
 | 
				
			||||||
   	break;
 | 
					   	break;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<%= flash_messages %>
 | 
					<%= flash_messages %>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<%= form_for @link, :url => admin_link_path(@link), :html => { :class => 'form' } do |f| %>
 | 
					<%= form_for @item, :url => admin_link_path(@item), :html => { :class => 'form' } do |f| %>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <%= render :partial => "admin/links/form", :locals => { :f => f } %>
 | 
					  <%= render :partial => "admin/links/form", :locals => { :f => f } %>
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<%= flash_messages %>
 | 
					<%= flash_messages %>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<%= form_for @link, :url => admin_links_path, :html => { :class => 'form' } do |f| %>
 | 
					<%= form_for @item, :url => admin_links_path, :html => { :class => 'form' } do |f| %>
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  <%= render :partial => "admin/links/form", :locals => { :f => f } %>
 | 
					  <%= render :partial => "admin/links/form", :locals => { :f => f } %>
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,24 +1,24 @@
 | 
				
			||||||
<%= flash_messages %>
 | 
					<%= flash_messages %>
 | 
				
			||||||
<p>
 | 
					<p>
 | 
				
			||||||
  <b><%= t('admin.name') %></b>
 | 
					  <b><%= t('admin.name') %></b>
 | 
				
			||||||
  <%= @link.name %>
 | 
					  <%= @item.name %>
 | 
				
			||||||
</p>
 | 
					</p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<% @site_valid_locales.each do |locale| %>
 | 
					<% @site_valid_locales.each do |locale| %>
 | 
				
			||||||
  <p>
 | 
					  <p>
 | 
				
			||||||
		<b><%= "#{t('admin.title')} #{locale}" %></b>
 | 
							<b><%= "#{t('admin.title')} #{locale}" %></b>
 | 
				
			||||||
	  <%= @link.i18n_variable[locale] if @link.i18n_variable %>
 | 
						  <%= @item.i18n_variable[locale] if @item.i18n_variable %>
 | 
				
			||||||
  </p>
 | 
					  </p>
 | 
				
			||||||
<% end %>
 | 
					<% end %>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<p>
 | 
					<p>
 | 
				
			||||||
  <b><%= t('admin.is_published') %></b>
 | 
					  <b><%= t('admin.is_published') %></b>
 | 
				
			||||||
  <%= @link.is_published.to_s %>
 | 
					  <%= @item.is_published.to_s %>
 | 
				
			||||||
</p>
 | 
					</p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<p>
 | 
					<p>
 | 
				
			||||||
  <b><%= t('admin.url') %></b>
 | 
					  <b><%= t('admin.url') %></b>
 | 
				
			||||||
  <%= @link.url %>
 | 
					  <%= @item.url %>
 | 
				
			||||||
</p>
 | 
					</p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<%= link_to t(:edit), edit_admin_link_path(@link) %>
 | 
					<%= link_to t(:edit), edit_admin_link_path(@item) %>
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
<% form_for :link, :url => admin_link_path(@link), :html => { :method => :delete } do |f| %>
 | 
					<% form_for :link, :url => admin_link_path(@item), :html => { :method => :delete } do |f| %>
 | 
				
			||||||
  <h2><%= t('sure?') %></h2>
 | 
					  <h2><%= t('sure?') %></h2>
 | 
				
			||||||
  <p>
 | 
					  <p>
 | 
				
			||||||
    <%= submit_tag t(:delete) %>
 | 
					    <%= submit_tag t(:delete) %>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					<h1>EDIT</h1>
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,5 @@
 | 
				
			||||||
 | 
					<% content_for :sidebar do %>
 | 
				
			||||||
 | 
						<div id='sidebar'><%= render 'admin/items/site_map_left_bar' %></div>
 | 
				
			||||||
 | 
					<% end -%>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<%= render 'edit' %>
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					$('#main').html("<%= escape_javascript(render(:partial => 'edit')) %>");
 | 
				
			||||||
| 
						 | 
					@ -1 +1,10 @@
 | 
				
			||||||
<%= parse_page(@page).html_safe %>
 | 
					<%= parse_page_edit(@item).html_safe %>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<% content_for :page_specific_javascript do %>
 | 
				
			||||||
 | 
					  <script type="text/javascript" charset="utf-8">
 | 
				
			||||||
 | 
							$("div.editable").live("mouseenter mouseleave",
 | 
				
			||||||
 | 
						    function (event) {
 | 
				
			||||||
 | 
						      $(this).next('.edit_link').toggle();
 | 
				
			||||||
 | 
						    });
 | 
				
			||||||
 | 
					  </script>
 | 
				
			||||||
 | 
					<% end -%>
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
<h1><%= t('admin.editing_page') %></h1>
 | 
					<h1><%= t('admin.editing_page') %></h1>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<%= form_for @page, :url => admin_page_path(@page) do |f| %>
 | 
					<%= form_for @item, :url => admin_page_path(@item) do |f| %>
 | 
				
			||||||
  <%= f.error_messages %>
 | 
					  <%= f.error_messages %>
 | 
				
			||||||
  <%= render :partial => "form", :locals => { :f => f } %>
 | 
					  <%= render :partial => "form", :locals => { :f => f } %>
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,6 +18,15 @@
 | 
				
			||||||
</head>
 | 
					</head>
 | 
				
			||||||
<body>
 | 
					<body>
 | 
				
			||||||
  <div id="header">
 | 
					  <div id="header">
 | 
				
			||||||
 | 
							<ul id="nav">
 | 
				
			||||||
 | 
						    <li><%= link_to t('homepage'), root_path %></li>
 | 
				
			||||||
 | 
						    <li><%= link_to t('admin.item'), admin_items_path %></li>
 | 
				
			||||||
 | 
						    <li><%= link_to t('admin.layout'), admin_layouts_path %></li>
 | 
				
			||||||
 | 
						    <li><%= link_to t('admin.asset'), admin_assets_path %></li>
 | 
				
			||||||
 | 
						    <li><%= link_to t('admin.user_info'), admin_user_info_models_path %></li>
 | 
				
			||||||
 | 
						    <li><%= link_to t('admin.user_role'), admin_user_role_models_path %></li>
 | 
				
			||||||
 | 
								<li><%= link_to t('admin.translation'), admin_translations_path %></li>
 | 
				
			||||||
 | 
					 		</ul>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <div id="content" class="content">
 | 
					  <div id="content" class="content">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,6 +49,7 @@ PrototypeR4::Application.routes.draw do
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    resources :pages
 | 
					    resources :pages
 | 
				
			||||||
 | 
					    resources :page_parts
 | 
				
			||||||
    resources :homes
 | 
					    resources :homes
 | 
				
			||||||
    resources :snippets
 | 
					    resources :snippets
 | 
				
			||||||
    resources :translations
 | 
					    resources :translations
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -72,7 +72,7 @@ module Parser
 | 
				
			||||||
      c.define_tag 'layout_part' do |tag|
 | 
					      c.define_tag 'layout_part' do |tag|
 | 
				
			||||||
        ret = ''
 | 
					        ret = ''
 | 
				
			||||||
        ret << "<div id='#{tag.attr['name']}'>"
 | 
					        ret << "<div id='#{tag.attr['name']}'>"
 | 
				
			||||||
        ret << (page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }).content rescue ''
 | 
					        ret << page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }.content rescue ''
 | 
				
			||||||
        ret << tag.expand
 | 
					        ret << tag.expand
 | 
				
			||||||
        ret << '</div>'
 | 
					        ret << '</div>'
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
| 
						 | 
					@ -94,8 +94,104 @@ module Parser
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					  def parse_page_edit(page)
 | 
				
			||||||
 | 
					    if page._type == 'Page'
 | 
				
			||||||
 | 
					      layout_content = page.layout.content 
 | 
				
			||||||
 | 
					      context = parser_context_edit(page)
 | 
				
			||||||
 | 
					      parser = Radius::Parser.new(context, :tag_prefix => 'r')
 | 
				
			||||||
 | 
					      parser.parse(parser.parse(layout_content))
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  def parser_context_edit(page, attributes = {})
 | 
				
			||||||
 | 
					    Radius::Context.new do |c|
 | 
				
			||||||
 | 
					      c.define_tag 'snippet' do |tag|
 | 
				
			||||||
 | 
					        snippet = Snippet.first(:conditions => {:name => tag.attr['name']})
 | 
				
			||||||
 | 
					        if snippet
 | 
				
			||||||
 | 
					          snippet.content
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					          t('nothing')
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      c.define_tag 'language_bar' do
 | 
				
			||||||
 | 
					        @site.in_use_locales.map{ |locale|
 | 
				
			||||||
 | 
					          lang = I18nVariable.first(:conditions => {:key => locale})[locale]
 | 
				
			||||||
 | 
					          if I18n.locale.to_s.eql?(locale)
 | 
				
			||||||
 | 
					            lang
 | 
				
			||||||
 | 
					          else
 | 
				
			||||||
 | 
					            "<a href='?locale=#{locale}'>#{lang}</a>"
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					        }.join(' | ')
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      c.define_tag 'locale' do |tag|
 | 
				
			||||||
 | 
					        case attributes[:locale]
 | 
				
			||||||
 | 
					          when 'create'
 | 
				
			||||||
 | 
					            var = I18nVariable.new(:key => (tag.attr['name'] rescue nil), :document_class => 'Text')
 | 
				
			||||||
 | 
					            @site.valid_locales.each do |locale|
 | 
				
			||||||
 | 
					              var[locale] = tag.attr[locale] rescue nil
 | 
				
			||||||
 | 
					            end
 | 
				
			||||||
 | 
					            var.save!
 | 
				
			||||||
 | 
					            res = ''
 | 
				
			||||||
 | 
					            res << "<r:locale id='#{var.id}' " 
 | 
				
			||||||
 | 
					            res << "name='#{var.key}' " if var.key
 | 
				
			||||||
 | 
					            @site.valid_locales.each do |locale|
 | 
				
			||||||
 | 
					              res << "#{locale}='#{var[locale]}' "
 | 
				
			||||||
 | 
					            end
 | 
				
			||||||
 | 
					            res << '/>'
 | 
				
			||||||
 | 
					          when 'show'
 | 
				
			||||||
 | 
					            var = I18nVariable.find(tag.attr['id'])
 | 
				
			||||||
 | 
					            res = ''
 | 
				
			||||||
 | 
					            res << "<r:locale " 
 | 
				
			||||||
 | 
					            res << "name='#{var.key}' " if var.key
 | 
				
			||||||
 | 
					            @site.valid_locales.each do |locale|
 | 
				
			||||||
 | 
					              res << "#{locale}='#{var[locale]}' "
 | 
				
			||||||
 | 
					            end
 | 
				
			||||||
 | 
					            res << '/>'
 | 
				
			||||||
 | 
					          when 'destroy'
 | 
				
			||||||
 | 
					            var = I18nVariable.find(tag.attr['id'])
 | 
				
			||||||
 | 
					            var.destroy
 | 
				
			||||||
 | 
					          else
 | 
				
			||||||
 | 
					            tag.attr[I18n.locale.to_s] rescue nil
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      c.define_tag 'css' do |tag|
 | 
				
			||||||
 | 
					        assets = Asset.any_in(:filename => tag.attr['name'].split(',').map(&:strip))
 | 
				
			||||||
 | 
					        res = ''
 | 
				
			||||||
 | 
					        assets.each do |asset|
 | 
				
			||||||
 | 
					          res << "<link href='#{asset.data.file.url}' rel='stylesheet' type='text/css' /> " if asset.data.file.content_type.eql?('text/css')
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					        res
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      c.define_tag 'image' do |tag|
 | 
				
			||||||
 | 
					        asset = Asset.find(tag.attr['id'])
 | 
				
			||||||
 | 
					        if asset
 | 
				
			||||||
 | 
					          res = "<img src=#{asset.data.file.url} "
 | 
				
			||||||
 | 
					          tag.attr.each do |l|
 | 
				
			||||||
 | 
					            res << "#{l[0]}='#{l[1]}' "
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					          res << '>'
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      c.define_tag 'layout_part' do |tag|
 | 
				
			||||||
 | 
					        part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }
 | 
				
			||||||
 | 
					        ret = ''
 | 
				
			||||||
 | 
					        ret << "<div id='#{tag.attr['name']}'"
 | 
				
			||||||
 | 
					        ret << " part_id='#{part.id}'" if part
 | 
				
			||||||
 | 
					        ret << " class='editable'" if part
 | 
				
			||||||
 | 
					        ret << " style='border:solid 1px; margin:5px; padding:5px;'>"
 | 
				
			||||||
 | 
					        ret << "<div class='edit_link' style='display:block'>" if part
 | 
				
			||||||
 | 
					        ret << " <a href='#{edit_admin_page_part_path(part.id)}'>#{t(:edit)}</a>" if part
 | 
				
			||||||
 | 
					        ret << '</div>' if part
 | 
				
			||||||
 | 
					        ret << part.content rescue ''
 | 
				
			||||||
 | 
					        ret << tag.expand
 | 
				
			||||||
 | 
					        ret << '</div>'
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  def self.included(base)
 | 
					  def self.included(base)
 | 
				
			||||||
    base.send :helper_method, :parse_page if base.respond_to? :helper_method
 | 
					    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
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Loading…
	
		Reference in New Issue