add i18n for layout and snippet
This commit is contained in:
		
							parent
							
								
									28612514e3
								
							
						
					
					
						commit
						ff2dffaeb4
					
				| 
						 | 
				
			
			@ -36,7 +36,10 @@ class Admin::SnippetsController < ApplicationController
 | 
			
		|||
        end
 | 
			
		||||
      end
 | 
			
		||||
      
 | 
			
		||||
      @snippet.content = "<ul>\n#{lis}</ul>"
 | 
			
		||||
      VALID_LOCALES.each do |locale|
 | 
			
		||||
        @snippet.write_attribute( "content_#{locale}", "<ul>\n#{lis}</ul>" )
 | 
			
		||||
      end
 | 
			
		||||
      
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    respond_to do |format|
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,7 +14,7 @@ class ApplicationController < ActionController::Base
 | 
			
		|||
      @layout = @page.layout
 | 
			
		||||
      @page_options ||= {}
 | 
			
		||||
      @page_content = Liquid::Template.parse( @page.read_attribute( "content_#{I18n.locale}" ) ).render(@page_options)
 | 
			
		||||
      @layout_content = (@page.layout)? @layout.content : "{{page_content}}"
 | 
			
		||||
      @layout_content = (@page.layout)? @layout.read_attribute( "content_#{I18n.locale}" ) : "{{page_content}}"
 | 
			
		||||
      render :text => Liquid::Template.parse(@layout_content).render( 'page_content' => @page_content )
 | 
			
		||||
    else
 | 
			
		||||
      render :text => '404 Not Found'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,8 +13,8 @@ class PagesController < ApplicationController
 | 
			
		|||
    @page = Page.find_by_name(params[:page_name])
 | 
			
		||||
    
 | 
			
		||||
    if @page && !@page.external_link.blank?
 | 
			
		||||
      redirect_to @page.external_link
 | 
			
		||||
    elsif @page && @page.use_engine
 | 
			
		||||
    #  redirect_to @page.external_link
 | 
			
		||||
    elsif @page && !@page.use_engine.blank?
 | 
			
		||||
      #model_class = Kernel.const_get( "Announcement" ) # page.use_engine
 | 
			
		||||
      redirect_to announcements_path
 | 
			
		||||
    else
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +1,9 @@
 | 
			
		|||
require 'couch_foo'
 | 
			
		||||
class Announcement < CouchFoo::Base
 | 
			
		||||
  
 | 
			
		||||
   property :title, String
 | 
			
		||||
   property :content, String
 | 
			
		||||
   property_i18n :title, String
 | 
			
		||||
   property_i18n :content, String
 | 
			
		||||
   
 | 
			
		||||
   validates_presence_of :title
 | 
			
		||||
    
 | 
			
		||||
   def to_liquid
 | 
			
		||||
     { "id" => self.id, "title" => self.title, "content" => self.content }
 | 
			
		||||
   end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,6 @@
 | 
			
		|||
class Layout < CouchFoo::Base
 | 
			
		||||
  
 | 
			
		||||
   property :name, String
 | 
			
		||||
   property :content, String #remove later
 | 
			
		||||
   property_i18n :content, String
 | 
			
		||||
   
 | 
			
		||||
   validates_presence_of :name
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,6 @@
 | 
			
		|||
class Snippet < CouchFoo::Base
 | 
			
		||||
  
 | 
			
		||||
   property :name, String
 | 
			
		||||
   property :content, String # remove later
 | 
			
		||||
   property_i18n :content, String
 | 
			
		||||
    
 | 
			
		||||
   validates_presence_of :name
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,7 +4,7 @@ module SnippetFilter
 | 
			
		|||
    snippet = Snippet.find_by_name(snippet_name)
 | 
			
		||||
    
 | 
			
		||||
    if snippet
 | 
			
		||||
      return Liquid::Template.parse(snippet.content).render
 | 
			
		||||
      return Liquid::Template.parse( snippet.read_attribute( "content_#{I18n.locale}" ) ).render
 | 
			
		||||
    else
 | 
			
		||||
      return "nothing"
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,25 @@
 | 
			
		|||
<p>
 | 
			
		||||
<%= f.label :name, "Name" %>
 | 
			
		||||
<%= f.text_field :name, :class => 'text' %>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
<p id="content_zh_tw_block">
 | 
			
		||||
<%= f.label "content_zh_tw", "Content (zh_tw)" %>
 | 
			
		||||
<%= f.text_area "content_zh_tw", :size => '100x30' %>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
<p><a href="#" id="toggle_content_en_block">Edit english</a></p>
 | 
			
		||||
 | 
			
		||||
<p id="content_en_block">
 | 
			
		||||
<%= f.label "content_en", "Content (en)" %>
 | 
			
		||||
<%= f.text_area "content_en", :size => '100x30' %>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
<% content_for :page_specific_javascript do %>
 | 
			
		||||
<script type="text/javascript" charset="utf-8">
 | 
			
		||||
  $('#content_en_block').hide();
 | 
			
		||||
  $('#toggle_content_en_block').click(function(){
 | 
			
		||||
    $('#content_en_block').toggle();
 | 
			
		||||
  });
 | 
			
		||||
</script>
 | 
			
		||||
<% end -%>
 | 
			
		||||
| 
						 | 
				
			
			@ -3,16 +3,7 @@
 | 
			
		|||
<% form_for @layout, :url => admin_layout_path(@layout) do |f| %>
 | 
			
		||||
  <%= f.error_messages %>
 | 
			
		||||
  
 | 
			
		||||
  <p>
 | 
			
		||||
  <%= f.label :name, "Name" %>
 | 
			
		||||
  <%= f.text_field :name, :class => 'text' %>
 | 
			
		||||
  </p>
 | 
			
		||||
    
 | 
			
		||||
  <p>
 | 
			
		||||
  <%= f.label :content, "Content" %>
 | 
			
		||||
  <%= f.text_area :content, :size => '100x30' %>
 | 
			
		||||
  </p>
 | 
			
		||||
  
 | 
			
		||||
  <%= render :partial => "form", :locals => { :f => f } %>
 | 
			
		||||
  <p>
 | 
			
		||||
    <%= f.submit 'Update' %>
 | 
			
		||||
  </p>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,15 +3,7 @@
 | 
			
		|||
<% form_for :layout, :url => admin_layouts_path do |f| %>
 | 
			
		||||
  <%= f.error_messages %>
 | 
			
		||||
 | 
			
		||||
  <p>
 | 
			
		||||
  <%= f.label :name, "Name" %>
 | 
			
		||||
  <%= f.text_field :name, :class => 'text' %>
 | 
			
		||||
  </p>
 | 
			
		||||
  
 | 
			
		||||
  <p>
 | 
			
		||||
  <%= f.label :content, "Content" %>
 | 
			
		||||
  <%= f.text_area :content, :size => '100x30' %>
 | 
			
		||||
  </p>
 | 
			
		||||
  <%= render :partial => "form", :locals => { :f => f } %>
 | 
			
		||||
  
 | 
			
		||||
  <p>
 | 
			
		||||
    <%= f.submit 'Create' %>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,25 @@
 | 
			
		|||
<p>
 | 
			
		||||
<%= f.label :name, "Name" %>
 | 
			
		||||
<%= f.text_field :name, :class => 'text' %>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
<p id="content_zh_tw_block">
 | 
			
		||||
<%= f.label "content_zh_tw", "Content (zh_tw)" %>
 | 
			
		||||
<%= f.text_area "content_zh_tw", :size => '100x30' %>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
<p><a href="#" id="toggle_content_en_block">Edit english</a></p>
 | 
			
		||||
 | 
			
		||||
<p id="content_en_block">
 | 
			
		||||
<%= f.label "content_en", "Content (en)" %>
 | 
			
		||||
<%= f.text_area "content_en", :size => '100x30' %>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
<% content_for :page_specific_javascript do %>
 | 
			
		||||
<script type="text/javascript" charset="utf-8">
 | 
			
		||||
  $('#content_en_block').hide();
 | 
			
		||||
  $('#toggle_content_en_block').click(function(){
 | 
			
		||||
    $('#content_en_block').toggle();
 | 
			
		||||
  });
 | 
			
		||||
</script>
 | 
			
		||||
<% end -%>
 | 
			
		||||
| 
						 | 
				
			
			@ -3,15 +3,7 @@
 | 
			
		|||
<% form_for @snippet, :url => admin_snippet_path(@snippet) do |f| %>
 | 
			
		||||
  <%= f.error_messages %>
 | 
			
		||||
  
 | 
			
		||||
  <p>
 | 
			
		||||
  <%= f.label :name, "Name" %>
 | 
			
		||||
  <%= f.text_field :name, :class => 'text' %>
 | 
			
		||||
  </p>
 | 
			
		||||
    
 | 
			
		||||
  <p>
 | 
			
		||||
  <%= f.label :content, "Content" %>
 | 
			
		||||
  <%= f.text_area :content, :size => '100x30' %>
 | 
			
		||||
  </p>
 | 
			
		||||
  <%= render :partial => "form", :locals => { :f => f } %>
 | 
			
		||||
  
 | 
			
		||||
  <p>
 | 
			
		||||
    <%= f.submit 'Update' %>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,15 +3,7 @@
 | 
			
		|||
<% form_for :snippet, :url => admin_snippets_path do |f| %>
 | 
			
		||||
  <%= f.error_messages %>
 | 
			
		||||
 | 
			
		||||
  <p>
 | 
			
		||||
  <%= f.label :name, "Name" %>
 | 
			
		||||
  <%= f.text_field :name, :class => 'text' %>
 | 
			
		||||
  </p>
 | 
			
		||||
  
 | 
			
		||||
  <p>
 | 
			
		||||
  <%= f.label :content, "Content" %>
 | 
			
		||||
  <%= f.text_area :content, :size => '100x30' %>
 | 
			
		||||
  </p>
 | 
			
		||||
  <%= render :partial => "form", :locals => { :f => f } %>
 | 
			
		||||
  
 | 
			
		||||
  <p>
 | 
			
		||||
    <%= f.submit 'Create' %>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -49,7 +49,7 @@ class CouchFoo::Base
 | 
			
		|||
  
 | 
			
		||||
  def self.property_i18n(property_name, property_type)
 | 
			
		||||
    VALID_LOCALES.each do |locale|
 | 
			
		||||
       property "#{property_name.to_s}_#{locale}", property_type
 | 
			
		||||
       property "#{property_name.to_s}_#{locale}".to_sym, property_type
 | 
			
		||||
     end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue