implement feature #324

This commit is contained in:
Didier Lafforgue 2012-03-14 01:16:01 +01:00
parent 79f958c505
commit fbd945cf6d
13 changed files with 89 additions and 8 deletions

View File

@ -17,10 +17,10 @@ GIT
GIT GIT
remote: git://github.com/locomotivecms/custom_fields.git remote: git://github.com/locomotivecms/custom_fields.git
revision: ec157c3941d1530eb49d08ee385d25c3d3f34f15 revision: e54c3ddfce0e24668d02c372c6143a722718e215
branch: 2.0.0.rc branch: 2.0.0.rc
specs: specs:
custom_fields (2.0.0.rc7) custom_fields (2.0.0.rc8)
activesupport (~> 3.2.1) activesupport (~> 3.2.1)
carrierwave-mongoid (~> 0.1.3) carrierwave-mongoid (~> 0.1.3)
mongoid (~> 2.4.5) mongoid (~> 2.4.5)
@ -36,7 +36,7 @@ PATH
carrierwave-mongoid (~> 0.1.3) carrierwave-mongoid (~> 0.1.3)
cells (~> 3.8.0) cells (~> 3.8.0)
codemirror-rails (~> 2.21) codemirror-rails (~> 2.21)
custom_fields (~> 2.0.0.rc7) custom_fields (~> 2.0.0.rc8)
devise (~> 1.5.3) devise (~> 1.5.3)
dragonfly (~> 0.9.8) dragonfly (~> 0.9.8)
flash_cookie_session (~> 1.1.1) flash_cookie_session (~> 1.1.1)
@ -146,7 +146,7 @@ GEM
orm_adapter (~> 0.0.3) orm_adapter (~> 0.0.3)
warden (~> 1.1) warden (~> 1.1)
diff-lcs (1.1.3) diff-lcs (1.1.3)
dragonfly (0.9.10) dragonfly (0.9.11)
rack rack
ejs (1.0.0) ejs (1.0.0)
erubis (2.7.0) erubis (2.7.0)
@ -217,7 +217,7 @@ GEM
mongo (~> 1.3) mongo (~> 1.3)
tzinfo (~> 0.3.22) tzinfo (~> 0.3.22)
multi_json (1.0.4) multi_json (1.0.4)
multi_xml (0.4.1) multi_xml (0.4.2)
net-scp (1.0.4) net-scp (1.0.4)
net-ssh (>= 1.99.1) net-ssh (>= 1.99.1)
net-ssh (2.3.0) net-ssh (2.3.0)

View File

@ -78,6 +78,12 @@ ul.list {
outline: none; outline: none;
} }
span.untranslated {
@include label;
top: -1px;
left: 5px;
}
div.more { div.more {
position: absolute; position: absolute;
top: 0px; top: 0px;
@ -212,6 +218,12 @@ ul.list {
&.hidden a { font-style: italic; font-weight: normal; } &.hidden a { font-style: italic; font-weight: normal; }
span.untranslated {
@include label;
top: 3px;
left: 5px;
}
.more { .more {
position: absolute; position: absolute;
top: 0px; top: 0px;

View File

@ -55,3 +55,18 @@
border-bottom: 1px dotted #efe4a5; border-bottom: 1px dotted #efe4a5;
} }
} }
@mixin label {
display: inline-block;
position: relative;
background-color: #858585;
@include border-radius(3px);
padding: 1px 3px 2px;
line-height: 16px;
font-size: 11px;
font-weight: bold;
color: #fff;
@include single-text-shadow(rgba(0, 0, 0, 0.6), 0px, -1px, 0px);
}

View File

@ -48,6 +48,14 @@ module Locomotive
value.respond_to?(:to_label) ? value.to_label : value value.respond_to?(:to_label) ? value.to_label : value
end end
def translated?
if self.respond_to?(:"#{self._label_field_name}_translations")
self.send(:"#{self._label_field_name}_translations").key?(::Mongoid::Fields::I18n.locale.to_s) #rescue false
else
true
end
end
def next def next
next_or_previous :gt next_or_previous :gt
end end

View File

@ -12,7 +12,6 @@ module Locomotive
## callbacks ## ## callbacks ##
after_validation :add_default_locale after_validation :add_default_locale
# after_validation :add_missing_locales_for_all_pages
end end

View File

@ -71,6 +71,10 @@ module Locomotive
self.cache_strategy != 'none' self.cache_strategy != 'none'
end end
def translated?
self.title_translations.key?(::Mongoid::Fields::I18n.locale.to_s) rescue false
end
def to_liquid def to_liquid
Locomotive::Liquid::Drops::Page.new(self) Locomotive::Liquid::Drops::Page.new(self)
end end

View File

@ -6,7 +6,11 @@
%li.item{ :id => "entry-#{entry._id}" } %li.item{ :id => "entry-#{entry._id}" }
%span.handle %span.handle
= image_tag 'locomotive/form/icons/drag.png' = image_tag 'locomotive/form/icons/drag.png'
%strong= link_to entry_label(content_type, entry), edit_content_entry_url(content_type.slug, entry) %strong= link_to entry_label(content_type, entry), edit_content_entry_url(content_type.slug, entry)
- unless entry.translated?
%span.untranslated= t('locomotive.shared.list.untranslated')
.more .more
%span %span
!= t('locomotive.content_entries.index.updated_at') != t('locomotive.content_entries.index.updated_at')

View File

@ -17,6 +17,9 @@
= link_to truncate(page.title, :length => 80), edit_page_url(page) = link_to truncate(page.title, :length => 80), edit_page_url(page)
- unless page.translated?
%span.untranslated= t('locomotive.shared.list.untranslated')
.more .more
%span!= t('.updated_at') %span!= t('.updated_at')
= l page.updated_at, :format => :short = l page.updated_at, :format => :short

View File

@ -48,6 +48,8 @@ en:
create: Create create: Create
update: Save update: Save
send: Send send: Send
list:
untranslated: untranslated
footer: footer:
who_is_behind: "LocomotiveCMS is developed by %{development} and designed by <a href=\"http://www.sachagreif.com\">Sacha Greif</a> &mdash; <small>version</small> %{version}" who_is_behind: "LocomotiveCMS is developed by %{development} and designed by <a href=\"http://www.sachagreif.com\">Sacha Greif</a> &mdash; <small>version</small> %{version}"

View File

@ -48,6 +48,8 @@ fr:
account: Mon compte account: Mon compte
site: Site site: Site
theme_assets: Fichiers Thème theme_assets: Fichiers Thème
list:
untranslated: non traduit
footer: footer:
who_is_behind: "Produit développé par %{development} et désigné par <a href=\"http://www.sachagreif.com\">Sacha Greif</a> &mdash; <small>version</small> %{version}" who_is_behind: "Produit développé par %{development} et désigné par <a href=\"http://www.sachagreif.com\">Sacha Greif</a> &mdash; <small>version</small> %{version}"
form_actions: form_actions:

View File

@ -30,7 +30,7 @@ Gem::Specification.new do |s|
s.add_dependency 'mongoid', '~> 2.4.5' s.add_dependency 'mongoid', '~> 2.4.5'
s.add_dependency 'locomotive-mongoid-tree', '~> 0.6.2' s.add_dependency 'locomotive-mongoid-tree', '~> 0.6.2'
s.add_dependency 'custom_fields', '~> 2.0.0.rc7' s.add_dependency 'custom_fields', '~> 2.0.0.rc8'
s.add_dependency 'kaminari', '~> 0.13.0' s.add_dependency 'kaminari', '~> 0.13.0'

View File

@ -67,6 +67,27 @@ describe Locomotive::ContentEntry do
end end
end end
context '#i18n' do
before(:each) do
localize_content_type @content_type
::Mongoid::Fields::I18n.locale = 'en'
@content_entry = build_content_entry(:title => 'Hello world')
::Mongoid::Fields::I18n.locale = 'fr'
end
after(:all) do
::Mongoid::Fields::I18n.locale = 'en'
end
it 'tells if an entry has been translated or not' do
@content_entry.translated?.should be_false
@content_entry.title = 'Bonjour'
@content_entry.translated?.should be_true
end
end
describe "#navigation" do describe "#navigation" do
before(:each) do before(:each) do
@content_type.save @content_type.save
@ -214,8 +235,13 @@ describe Locomotive::ContentEntry do
end end
def localize_content_type(content_type)
content_type.entries_custom_fields.first.localized = true
content_type.save
end
def build_content_entry(options = {}) def build_content_entry(options = {})
@content_type.entries.build({ :title => 'Locomotive', :description => 'Lorem ipsum....' }.merge(options)) @content_type.entries.build({ :title => 'Locomotive', :description => 'Lorem ipsum....', :_label_field_name => 'title' }.merge(options))
end end
def fake_bson_id(id) def fake_bson_id(id)

View File

@ -74,6 +74,12 @@ describe Locomotive::Page do
@page.errors[:title].should == ["can't be blank"] @page.errors[:title].should == ["can't be blank"]
end end
it 'tells if a page has been translated or not' do
@page.translated?.should be_false
@page.title = 'Hello world'
@page.translated?.should be_true
end
end end
end end