fix bugs with the nav tag + when adding a new locale + other minor stuff
This commit is contained in:
parent
ad68826e84
commit
e1c2687681
@ -1,5 +1,3 @@
|
||||
require 'ruby-debug'
|
||||
|
||||
module Extensions
|
||||
module Page
|
||||
module Render
|
||||
|
51
app/models/extensions/site/i18n.rb
Normal file
51
app/models/extensions/site/i18n.rb
Normal file
@ -0,0 +1,51 @@
|
||||
module Extensions
|
||||
module Site
|
||||
module I18n
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
|
||||
## fields ##
|
||||
field :locales, :type => Array, :default => []
|
||||
|
||||
## callbacks ##
|
||||
after_validation :add_missing_locales_for_all_pages
|
||||
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def locales=(array)
|
||||
array = [] if array.blank?; super(array)
|
||||
end
|
||||
|
||||
def default_locale
|
||||
self.locales.first || Locomotive.config.site_locales.first
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def add_missing_locales_for_all_pages
|
||||
if self.locales_changed?
|
||||
list = self.pages.to_a
|
||||
|
||||
while !list.empty? do
|
||||
page = list.pop
|
||||
begin
|
||||
page.send(:set_slug_and_fullpath_for_all_locales, self.locales)
|
||||
|
||||
page.save
|
||||
|
||||
rescue TypeError => e
|
||||
list.insert(0, page)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
@ -33,6 +33,7 @@ class Page
|
||||
after_initialize :set_default_raw_template
|
||||
before_validation :normalize_slug
|
||||
before_save { |p| p.fullpath = p.fullpath(true) }
|
||||
before_create :set_slug_and_fullpath_for_all_locales
|
||||
before_destroy :do_not_remove_index_and_404_pages
|
||||
|
||||
## validations ##
|
||||
@ -121,4 +122,14 @@ class Page
|
||||
self.raw_template ||= I18n.t('attributes.defaults.pages.other.body')
|
||||
end
|
||||
|
||||
def set_slug_and_fullpath_for_all_locales(locales = nil)
|
||||
(locales || self.site.locales).each do |locale|
|
||||
I18n.with_site_locale(locale) do
|
||||
%w(slug fullpath).each do |meth|
|
||||
self.send(:"#{meth}=", self.send(meth.to_sym))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -6,12 +6,12 @@ class Site
|
||||
## Extensions ##
|
||||
extend Extensions::Site::SubdomainDomains
|
||||
extend Extensions::Site::FirstInstallation
|
||||
include Extensions::Site::I18n
|
||||
include Extensions::Shared::Seo
|
||||
|
||||
## fields ##
|
||||
field :name
|
||||
field :robots_txt
|
||||
field :locales, :type => Array, :default => []
|
||||
|
||||
## associations ##
|
||||
references_many :pages, :validate => false
|
||||
@ -34,10 +34,6 @@ class Site
|
||||
|
||||
## methods ##
|
||||
|
||||
def default_locale
|
||||
self.locales.first || Locomotive.config.site_locales.first
|
||||
end
|
||||
|
||||
def all_pages_in_once
|
||||
Page.quick_tree(self)
|
||||
end
|
||||
|
6
doc/TODO
6
doc/TODO
@ -25,10 +25,12 @@ BOARD:
|
||||
- liquid tags:
|
||||
x locale switcher
|
||||
x nav
|
||||
- link_to (new)
|
||||
(- others ?) -
|
||||
(- link_to (new)
|
||||
- others ?) -
|
||||
- other problems to solve:
|
||||
x If you create a new page it shall always be created in the default_language, not depending on the used language in the backend.
|
||||
- set the page slug for all the site locales
|
||||
- default site locale even if the i18n feature is disabled (the disable procedure is missing btw)
|
||||
- redirect for the default site locale if urls like /<default_site_locale>/....
|
||||
- inline editing
|
||||
|
||||
|
@ -56,14 +56,15 @@ module Locomotive
|
||||
|
||||
# Determines root node for the list
|
||||
def fetch_entries(context)
|
||||
@current_site = context.registers[:site]
|
||||
@current_page = context.registers[:page]
|
||||
|
||||
children = (case @source
|
||||
when 'site' then context.registers[:site].pages.root.minimal_attributes.first # start from home page
|
||||
when 'site' then @current_site.pages.root.minimal_attributes.first # start from home page
|
||||
when 'parent' then @current_page.parent || @current_page
|
||||
when 'page' then @current_page
|
||||
else
|
||||
context.registers[:site].pages.fullpath(@source).minimal_attributes.first
|
||||
@current_site.pages.fullpath(@source).minimal_attributes.first
|
||||
end).children_with_minimal_attributes.to_a
|
||||
|
||||
children.delete_if { |p| !include_page?(p) }
|
||||
@ -73,6 +74,8 @@ module Locomotive
|
||||
def render_entry_link(page, css, depth)
|
||||
selected = @current_page.fullpath =~ /^#{page.fullpath}/ ? ' on' : ''
|
||||
|
||||
page.site = @current_site
|
||||
|
||||
icon = @options[:icon] ? '<span></span>' : ''
|
||||
label = %{#{icon if @options[:icon] != 'after' }#{page.title}#{icon if @options[:icon] == 'after' }}
|
||||
|
||||
|
@ -31,6 +31,13 @@ namespace :locomotive do
|
||||
|
||||
desc 'Prepare for i18n'
|
||||
task :prepare_for_i18n => :environment do
|
||||
Site.all.each do |site|
|
||||
if site.locales.empty?
|
||||
site.locales = [Locomotive.config.site_locales.first]
|
||||
site.save
|
||||
end
|
||||
end
|
||||
|
||||
Page.skip_callback(:validate, :before)
|
||||
Page.skip_callback(:save, :after)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user