the label of a metafield namespace can also be a String
did
committed Feb 11, 2016
commit a28c3a50bf0dbacb44354965330f5db26e1c66d1
Showing 2
changed files with
20 additions
and 2 deletions
locomotive/steam/adapters/filesystem/sanitizers/site.rb b/lib/locomotive/steam/adapters/filesystem/sanitizers/site.rb
+9
-1
| @@ | @@ -19,7 +19,7 @@ module Locomotive::Steam |
| schema.each_with_index.map do |(namespace, definitions), position| | |
| { | |
| name: namespace.to_s, | |
| - | label: { default: namespace.to_s }.merge(definitions.delete(:label) || {}), |
| + | label: localized_label(definitions.delete(:label), namespace.to_s), # { default: namespace.to_s }.merge(definitions.delete(:label) || {}), |
| fields: parse_metafields(definitions.delete(:fields)), | |
| position: definitions.delete(:position) || position | |
| }.merge(definitions) | |
| @@ | @@ -36,6 +36,14 @@ module Locomotive::Steam |
| end | |
| end | |
| + | def localized_label(label, default) |
| + | case label |
| + | when Hash then label |
| + | when String then { default: label } |
| + | else { default: default} |
| + | end |
| + | end |
| + | |
| end | |
| end | |
| end | |
spec/unit/adapters/filesystem/sanitizers/site_spec.rb
+11
-1
| @@ | @@ -31,7 +31,7 @@ describe Locomotive::Steam::Adapters::Filesystem::Sanitizers::Site do |
| it 'loads the full schema' do | |
| # First namespace | |
| expect(subject[0]['name']).to eq 'social' | |
| - | expect(subject[0]['label']).to eq('default' => 'social', 'fr' => 'Social (FR)') |
| + | expect(subject[0]['label']).to eq('fr' => 'Social (FR)') |
| expect(subject[0]['position']).to eq 1 | |
| expect(subject[0]['fields']).to eq([{ 'name' => 'facebook_id', 'position' => 0 }, { 'name' => 'google_id', 'position' => 1 }]) | |
| @@ | @@ -42,6 +42,16 @@ describe Locomotive::Steam::Adapters::Filesystem::Sanitizers::Site do |
| expect(subject[1]['fields'][0]).to eq('name' => 'api_url', 'position' => 0, 'label' => { 'default' => 'API Url' }, 'type' => 'string', 'hint' => { 'default' => 'API endpoint' }) | |
| end | |
| + | context 'label is a string instead of a hash' do |
| + | |
| + | let(:schema) { {:social=>{:label=>"Social", :position=>1, :fields=>["facebook_id", "google_id"]}, :github=>{:position=>0, :fields=>{:api_url=>{:label=>"API Url", :type=>"string", :hint=>"API endpoint"}, :expires_in=>{:label=>{:en=>"Expires in", :fr=>"Expire dans"}, :hint=>{:en=>"Cache - In milliseconds", :fr=>"Cache - En millisecondes"}, :type=>"integer", :min=>0, :max=>3600}}}} } |
| + | |
| + | it 'loads the full schema' do |
| + | expect(subject[0]['label']).to eq('default' => 'Social') |
| + | end |
| + | |
| + | end |
| + | |
| end | |
| end | |