fix issue #226: generating a page with locales other than the default one

did committed Jan 21, 2015
commit 078f3d8b8c506ab1df02e06423f7eaacf4d5c3d5
Showing 4 changed files with 99 additions and 8 deletions
locomotive/wagon/generators/page.rb b/lib/locomotive/wagon/generators/page.rb +10 -5
@@ @@ -62,18 +62,23 @@ module Locomotive
end
def other_locales
- locales = options[:default_locales]
- locales.shift
-
+ # Rules:
# #1 default: [fr, en, es], asked: [en, de], result => [en]
# #2 default: [fr, en, de], asked: [es], result => []
# #1 default: [fr, en, es], asked: [fr, en, es], result => [en, es]
- locales & (options[:locales] || [])
+ _locales = options[:locales] || ''
+ separator = _locales.include?(',') ? ',' : ' '
+
+ _locales = _locales.split(separator)
+ locales = options[:default_locales]
+ locales.shift
+
+ locales & (_locales || [])
end
end
end
end
- end
\ No newline at end of file
+ end
spec/integration/generators/page_spec.rb +87 -0
@@ @@ -0,0 +1,87 @@
+ # encoding: utf-8
+
+ require File.dirname(__FILE__) + '/../integration_helper'
+
+ require 'locomotive/wagon'
+ require 'locomotive/wagon/cli'
+
+ describe 'Locomotive::Wagon::Generators::Page' do
+
+ before { make_working_copy_of_site(:blog) }
+ after { remove_working_copy_of_site(:blog) }
+
+ let(:path) { working_copy_of_site(:blog) }
+ let(:fullpath) { 'new-page' }
+ let(:default_locales) { ['en', 'fr'] }
+ let(:locales) { nil }
+ let(:page_options) { { haml: false, locales: locales, default_locales: default_locales } }
+ let(:options) { { 'force_color' => true, 'path' => path, 'quiet' => true }.merge(page_options) }
+
+ subject { Locomotive::Wagon.generate(:page, [fullpath, options.delete('path')], options) }
+
+ describe 'wrong parameters' do
+
+ describe 'empty locales' do
+
+ let(:locales) { '' }
+
+ it { lambda { subject }.should_not raise_error }
+
+ end
+
+ end
+
+ describe 'generating a page' do
+
+ before { subject }
+
+ it 'creates the page in the FS' do
+ File.exists?(page_path('new-page')).should be_true
+ end
+
+ it 'generates an header in YAML' do
+ read_page('new-page').should include <<-EXPECTED
+ ---
+ title: New-page
+ EXPECTED
+ end
+
+ describe 'other locales' do
+
+ let(:locales) { 'en fr' }
+
+ it 'creates the EN page in the FS' do
+ File.exists?(page_path('new-page')).should be_true
+ end
+
+ it 'creates the FR page in the FS' do
+ File.exists?(page_path('new-page.fr')).should be_true
+ end
+
+ describe 'separated by a comma' do
+
+ let(:locales) { 'en,fr' }
+
+ it 'creates the EN page in the FS' do
+ File.exists?(page_path('new-page')).should be_true
+ end
+
+ it 'creates the FR page in the FS' do
+ File.exists?(page_path('new-page.fr')).should be_true
+ end
+
+ end
+
+ end
+
+ end
+
+ def page_path(slug)
+ File.join(path, 'app', 'views', 'pages', "#{slug}.liquid")
+ end
+
+ def read_page(slug)
+ File.read(page_path(slug))
+ end
+
+ end
spec/integration/generators/relationship_spec.rb +1 -1
@@ @@ -92,7 +92,7 @@ EXPECTED
end
def read_content_type(name)
- File.read(File.join(path, 'app/content_types', "#{name}.yml"))
+ File.read(File.join(path, 'app', 'content_types', "#{name}.yml"))
end
end
spec/support/helpers.rb +1 -2
@@ @@ -30,8 +30,7 @@ module Spec
def remove_working_copy_of_site(name)
path = working_copy_of_site(name)
-
- # FileUtils.rm_rf(path)
+ FileUtils.rm_rf(path)
end
def run_server