locomotivecms_steam 1.1.0.rc1 → 1.1.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/locomotive/steam/liquid/drops/content_entry_collection.rb +11 -1
- data/lib/locomotive/steam/liquid/drops/metafields.rb +6 -2
- data/lib/locomotive/steam/version.rb +1 -1
- data/spec/unit/liquid/drops/content_entry_collection_spec.rb +12 -2
- data/spec/unit/liquid/drops/metafields_spec.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c17c4a04bf43a0773bfe7862cc8a0b8b6f4cc1df
|
4
|
+
data.tar.gz: 5f42f142c5e32e216aaaddb71e664297b1946d25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 839e0df868a0fe863513d9b9d772810825a632b1a8abdaca54c3a803b8c08261e1c85b2b696a6ccc0b856b4682581c62e94d2922fc7449fa96b1777d81f94652
|
7
|
+
data.tar.gz: 8ebed488b272103bc81bddd06e387663ddb44fb93a62b35b62cc1caecb7851c4a2ffa25d60532caaf9f11228207d8d5e679b2c37ff5e09045a3bd060af7648a8
|
data/Gemfile.lock
CHANGED
@@ -42,7 +42,7 @@ module Locomotive
|
|
42
42
|
if (meth.to_s =~ /^group_by_(.+)$/) == 0
|
43
43
|
repository.group_by_select_option(@content_type, $1)
|
44
44
|
elsif (meth.to_s =~ /^(.+)_options$/) == 0
|
45
|
-
|
45
|
+
select_options($1)
|
46
46
|
else
|
47
47
|
Locomotive::Common::Logger.warn "[Liquid template] trying to call #{meth} on a content_type object"
|
48
48
|
nil
|
@@ -76,6 +76,16 @@ module Locomotive
|
|
76
76
|
@repository || services.repositories.content_entry.with(@content_type)
|
77
77
|
end
|
78
78
|
|
79
|
+
def select_options(name)
|
80
|
+
locale = @context.registers[:locale]
|
81
|
+
default_locale = @context.registers[:site].try(:default_locale)
|
82
|
+
|
83
|
+
(content_type_repository.select_options(@content_type, name) || []).map do |option|
|
84
|
+
_option = Locomotive::Steam::Decorators::I18nDecorator.new(option, locale, default_locale)
|
85
|
+
_option.name
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
79
89
|
end
|
80
90
|
|
81
91
|
end
|
@@ -22,7 +22,7 @@ module Locomotive
|
|
22
22
|
|
23
23
|
def find_value(name)
|
24
24
|
if field = fields[name]
|
25
|
-
t(values[name], field['localized'])
|
25
|
+
safe_value(t(values[name], field['localized']))
|
26
26
|
else
|
27
27
|
Locomotive::Common::Logger.warn "[Liquid template] unknown site metafield \"#{name}\" under #{@namespace['name']}"
|
28
28
|
nil
|
@@ -45,7 +45,7 @@ module Locomotive
|
|
45
45
|
{
|
46
46
|
'name' => field['name'],
|
47
47
|
'label' => t(field['label']) || field['name'].humanize,
|
48
|
-
'value' => t(value, localized)
|
48
|
+
'value' => safe_value(t(value, localized))
|
49
49
|
}
|
50
50
|
end
|
51
51
|
end
|
@@ -66,6 +66,10 @@ module Locomotive
|
|
66
66
|
value[key]
|
67
67
|
end
|
68
68
|
|
69
|
+
def safe_value(value)
|
70
|
+
value.blank? ? nil : value
|
71
|
+
end
|
72
|
+
|
69
73
|
end
|
70
74
|
|
71
75
|
class Metafields < Base
|
@@ -5,7 +5,7 @@ describe Locomotive::Steam::Liquid::Drops::ContentEntryCollection do
|
|
5
5
|
let(:assigns) { {} }
|
6
6
|
let(:content_type) { instance_double('ContentType', slug: 'articles') }
|
7
7
|
let(:services) { Locomotive::Steam::Services.build_instance }
|
8
|
-
let(:context) { ::Liquid::Context.new(assigns, {}, { services: services }) }
|
8
|
+
let(:context) { ::Liquid::Context.new(assigns, {}, { services: services, locale: :en }) }
|
9
9
|
let(:drop) { described_class.new(content_type).tap { |d| d.context = context } }
|
10
10
|
|
11
11
|
before { allow(services).to receive(:current_site).and_return(nil) }
|
@@ -74,8 +74,11 @@ describe Locomotive::Steam::Liquid::Drops::ContentEntryCollection do
|
|
74
74
|
|
75
75
|
describe 'get options of a select field' do
|
76
76
|
|
77
|
+
let(:option_a) { build_select_option(en: 'a') }
|
78
|
+
let(:option_b) { build_select_option('b') }
|
79
|
+
|
77
80
|
before do
|
78
|
-
expect(services.repositories.content_type).to receive(:select_options).with(content_type, 'category').and_return([
|
81
|
+
expect(services.repositories.content_type).to receive(:select_options).with(content_type, 'category').and_return([option_a, option_b])
|
79
82
|
end
|
80
83
|
|
81
84
|
it { expect(drop.before_method(:category_options)).to eq ['a', 'b'] }
|
@@ -98,4 +101,11 @@ describe Locomotive::Steam::Liquid::Drops::ContentEntryCollection do
|
|
98
101
|
|
99
102
|
end
|
100
103
|
|
104
|
+
def build_select_option(name)
|
105
|
+
_name = Locomotive::Steam::Models::I18nField.new('name', name)
|
106
|
+
Locomotive::Steam::ContentTypeField::SelectOption.new(name: _name).tap do |option|
|
107
|
+
option.localized_attributes = [:name]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
101
111
|
end
|
@@ -54,8 +54,17 @@ describe Locomotive::Steam::Liquid::Drops::Metafields do
|
|
54
54
|
|
55
55
|
it { is_expected.to eq '42' }
|
56
56
|
|
57
|
+
context 'the value exists but is an empty string' do
|
58
|
+
|
59
|
+
let(:metafields) { { 'my_namespace' => { 'analytics_id' => { 'default' => '' }, 'street' => { 'en' => '7 Albert Camus Alley', 'fr' => '7 allée Albert Camus' } } } }
|
60
|
+
it { is_expected.to eq nil }
|
61
|
+
|
62
|
+
end
|
63
|
+
|
57
64
|
end
|
58
65
|
|
66
|
+
|
67
|
+
|
59
68
|
context "the value doesn't exist" do
|
60
69
|
|
61
70
|
subject { namespace.before_method(:country) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locomotivecms_steam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.0.
|
4
|
+
version: 1.1.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Didier Lafforgue
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-03-
|
14
|
+
date: 2016-03-17 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|