locomotivecms_steam 0.1.1 → 0.1.2.pre.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/CHANGELOG.md +5 -0
- data/Gemfile +10 -2
- data/Gemfile.lock +37 -49
- data/Rakefile +5 -10
- data/example/server.rb +10 -6
- data/lib/locomotive/steam.rb +46 -0
- data/lib/locomotive/steam/configuration.rb +13 -0
- data/lib/locomotive/steam/decorators.rb +1 -0
- data/lib/locomotive/steam/decorators/page_decorator.rb +50 -0
- data/lib/locomotive/steam/entities/content_type.rb +11 -0
- data/lib/locomotive/steam/entities/page.rb +136 -0
- data/lib/locomotive/steam/entities/site.rb +30 -0
- data/lib/locomotive/steam/initializers/dragonfly.rb +3 -4
- data/lib/locomotive/steam/liquid.rb +1 -12
- data/lib/locomotive/steam/liquid/drops/base.rb +1 -1
- data/lib/locomotive/steam/liquid/drops/content_entry.rb +3 -2
- data/lib/locomotive/steam/liquid/drops/content_types.rb +4 -2
- data/lib/locomotive/steam/liquid/drops/page.rb +4 -3
- data/lib/locomotive/steam/liquid/drops/site.rb +3 -2
- data/lib/locomotive/steam/liquid/patches.rb +4 -8
- data/lib/locomotive/steam/liquid/tags/nav.rb +19 -17
- data/lib/locomotive/steam/loaders/yml/pages_loader.rb +193 -0
- data/lib/locomotive/steam/loaders/yml/site_loader.rb +49 -0
- data/lib/locomotive/steam/loaders/yml/utils/localized_tree.rb +33 -0
- data/lib/locomotive/steam/loaders/yml/utils/yaml_front_matters_template.rb +66 -0
- data/lib/locomotive/steam/loaders/yml_loader.rb +33 -0
- data/lib/locomotive/steam/mapper.rb +86 -0
- data/lib/locomotive/steam/middlewares/base.rb +12 -10
- data/lib/locomotive/steam/middlewares/locale.rb +3 -4
- data/lib/locomotive/steam/middlewares/page.rb +18 -18
- data/lib/locomotive/steam/middlewares/renderer.rb +41 -15
- data/lib/locomotive/steam/middlewares/stack.rb +1 -1
- data/lib/locomotive/steam/monkey_patches.rb +1 -2
- data/lib/locomotive/steam/monkey_patches/haml.rb +1 -1
- data/lib/locomotive/steam/repositories/content_types_repository.rb +14 -0
- data/lib/locomotive/steam/repositories/pages_repository.rb +23 -0
- data/lib/locomotive/steam/repositories/sites_repository.rb +16 -0
- data/lib/locomotive/steam/server.rb +14 -11
- data/lib/locomotive/steam/services/external_api.rb +2 -1
- data/lib/locomotive/steam/services/markdown.rb +3 -12
- data/lib/locomotive/steam/standalone_server.rb +2 -2
- data/lib/locomotive/steam/version.rb +4 -1
- data/locomotivecms_steam.gemspec +11 -5
- data/spec/fixtures/default/app/views/pages/basic.liquid.haml +13 -0
- data/spec/fixtures/default/config/site.yml +2 -2
- data/spec/integration/server/basic_spec.rb +22 -17
- data/spec/integration/server/contact_form_spec.rb +1 -1
- data/spec/integration/server/liquid_spec.rb +2 -2
- data/spec/integration/server/with_scope_spec.rb +2 -2
- data/spec/spec_helper.rb +15 -4
- data/spec/support/helpers.rb +26 -8
- data/spec/unit/decorators/page_decorator_spec.rb +55 -0
- data/spec/unit/entities/page_spec.rb +50 -0
- data/spec/unit/entities/site_spec.rb +12 -0
- data/spec/unit/liquid/tags/nav_spec.rb +159 -0
- data/spec/unit/loaders/pages_loader_spec.rb +42 -0
- data/spec/unit/loaders/site_loader_spec.rb +21 -0
- data/spec/unit/loaders/utils/localized_tree_spec.rb +33 -0
- data/spec/unit/loaders/utils/yaml_front_matters_template_spec.rb +39 -0
- data/spec/unit/middlewares/base_spec.rb +20 -0
- data/spec/unit/middlewares/page_spec.rb +51 -0
- data/spec/unit/repositories/pages_spec.rb +11 -0
- metadata +128 -23
- data/bin/publish +0 -28
- data/lib/locomotive/steam/misc.rb +0 -10
- data/lib/locomotive/steam/monkey_patches/mounter.rb +0 -54
- data/lib/steam.rb +0 -3
data/spec/support/helpers.rb
CHANGED
@@ -1,9 +1,26 @@
|
|
1
|
-
require 'common'
|
1
|
+
require 'locomotive/common'
|
2
|
+
require 'locomotive/models'
|
3
|
+
require 'locomotive/adapters/memory_adapter'
|
2
4
|
require_relative '../../lib/locomotive/steam/initializers'
|
5
|
+
require_relative '../../lib/locomotive/steam/loaders/yml_loader'
|
3
6
|
|
4
7
|
module Spec
|
5
8
|
module Helpers
|
6
9
|
|
10
|
+
|
11
|
+
def bootstrap_site_content
|
12
|
+
Locomotive::Steam::Loader::YmlLoader.new(default_fixture_site_path, mapper).load!
|
13
|
+
end
|
14
|
+
|
15
|
+
def mapper
|
16
|
+
@mapper ||= begin
|
17
|
+
adapter = Locomotive::Adapters::MemoryAdapter
|
18
|
+
Locomotive::Mapper.load_from_file! adapter, File.join(File.expand_path('lib/locomotive/steam/mapper.rb'))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
alias :bootstrap_models :mapper
|
23
|
+
|
7
24
|
def reset!
|
8
25
|
FileUtils.rm_rf(File.expand_path('../../../site', __FILE__))
|
9
26
|
end
|
@@ -15,17 +32,18 @@ module Spec
|
|
15
32
|
def run_server
|
16
33
|
Locomotive::Common.reset
|
17
34
|
Locomotive::Common.configure do |config|
|
18
|
-
path = File.join(
|
35
|
+
path = File.join(default_fixture_site_path, 'log/locomotivecms.log')
|
19
36
|
config.notifier = Locomotive::Common::Logger.setup(path)
|
20
37
|
end
|
21
38
|
|
22
|
-
|
23
|
-
|
24
|
-
reader = Locomotive::Mounter::Reader::FileSystem.instance
|
25
|
-
reader.run!(path: 'spec/fixtures/default')
|
39
|
+
bootstrap_site_content
|
26
40
|
|
27
|
-
Locomotive::
|
41
|
+
Locomotive::Common::Logger.info 'Server started...'
|
42
|
+
Locomotive::Steam::Server.new(path: default_fixture_site_path)
|
28
43
|
end
|
29
44
|
|
45
|
+
def default_fixture_site_path
|
46
|
+
File.expand_path('../../fixtures/default/', __FILE__)
|
47
|
+
end
|
30
48
|
end
|
31
|
-
end
|
49
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Locomotive::Steam::Decorators::PageDecorator' do
|
4
|
+
let(:locale) { :en }
|
5
|
+
|
6
|
+
it 'builds an empty decorator' do
|
7
|
+
build_page.should_not be_nil
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#safe_fullpath' do
|
11
|
+
let(:index_page) { build_page(fullpath: { en: 'index' }) }
|
12
|
+
let(:not_found_page) { build_page(fullpath: { en: '404' }) }
|
13
|
+
let(:about_page) { build_page(fullpath: { en: 'about_me'}, parent: index_page) }
|
14
|
+
let(:products_page) { build_page(fullpath: { en: 'products'}, parent: index_page, templatized: true) }
|
15
|
+
|
16
|
+
context 'not templatized' do
|
17
|
+
context 'index or 404' do
|
18
|
+
it { decorated(index_page).safe_fullpath.should eq 'index' }
|
19
|
+
it { decorated(not_found_page).safe_fullpath.should eq '404' }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'other' do
|
23
|
+
it { decorated(about_page).safe_fullpath.should eq 'about-me' }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'templatized' do
|
28
|
+
subject { decorated build_page(fullpath: { en: 'products' }, parent: index_page, templatized: true) }
|
29
|
+
its(:safe_fullpath) { should eq '*' }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'templatized with not templatized parent' do
|
33
|
+
subject { decorated build_page(fullpath: { en: 'about_me/contact' }, parent: about_page, templatized: true) }
|
34
|
+
its(:safe_fullpath) { should eq 'about-me/*' }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'templatized parent' do
|
38
|
+
subject { decorated build_page(fullpath: { en: 'products/detail' }, parent: products_page) }
|
39
|
+
its(:safe_fullpath) { should eq '*/detail' }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def decorated(page)
|
44
|
+
Locomotive::Steam::Decorators::PageDecorator.new(
|
45
|
+
Locomotive::Decorators::I18nDecorator.new(
|
46
|
+
page, locale
|
47
|
+
)
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def build_page(attributes = {})
|
52
|
+
Locomotive::Steam::Entities::Page.new(attributes)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Locomotive::Steam::Entities::Page' do
|
4
|
+
|
5
|
+
it 'builds an empty page' do
|
6
|
+
build_page.should_not be_nil
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#index?' do
|
10
|
+
it { build_page(fullpath: {en: 'index'}).should be_index }
|
11
|
+
it { build_page(fullpath: {en: 'about'}).should_not be_index }
|
12
|
+
it { build_page(fullpath: {en: 'products/index'}).should_not be_index }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#index_or_404?' do
|
16
|
+
it { build_page(fullpath: {en: 'index'}).should be_index_or_404 }
|
17
|
+
it { build_page(fullpath: {en: 'about'}).should_not be_index_or_404 }
|
18
|
+
it { build_page(fullpath: {en: 'products/index'}).should_not be_index_or_404 }
|
19
|
+
it { build_page(fullpath: {en: 'products/404'}).should_not be_index_or_404 }
|
20
|
+
it { build_page(fullpath: {en: '404'}).should be_index_or_404 }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#depth' do
|
24
|
+
it { build_page(fullpath: {en: 'index'}).depth.should eq 0 }
|
25
|
+
it { build_page(fullpath: {en: '404'}).depth.should eq 0 }
|
26
|
+
it { build_page(fullpath: {en: 'about'}).depth.should eq 1 }
|
27
|
+
it { build_page(fullpath: {en: 'about/me'}).depth.should eq 2 }
|
28
|
+
it { build_page(fullpath: {en: 'about/index'}).depth.should eq 2 }
|
29
|
+
it { build_page(fullpath: {en: 'about/the/team'}).depth.should eq 3 }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#fullpath=' do
|
33
|
+
context 'when the page has no slug yet' do
|
34
|
+
it 'also sets the slug' do
|
35
|
+
build_page(fullpath: {en: 'this/is/the/page_full_path'}).slug[:en].should eq 'page_full_path'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when the slug is already set' do
|
40
|
+
it 'keeps the original slug' do
|
41
|
+
build_page(fullpath: {en: 'this/is/the/page_full_path'}, slug: {en: 'the_slug'}).slug[:en].should eq 'the_slug'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_page(attributes = {})
|
47
|
+
Locomotive::Steam::Entities::Page.new(attributes)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Locomotive::Steam::Entities::Site' do
|
4
|
+
|
5
|
+
describe '#default_locale' do
|
6
|
+
subject { Locomotive::Steam::Entities::Site.new attributes }
|
7
|
+
let(:attributes) { { locales: [:wk, :fr, :es] } }
|
8
|
+
it 'uses the first locale as default locale' do
|
9
|
+
expect(subject.default_locale).to eq :wk
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Steam::Liquid::Tags::Nav do
|
4
|
+
|
5
|
+
subject { Locomotive::Steam::Liquid::Tags::Nav }
|
6
|
+
let(:entity_class) { Locomotive::Steam::Entities::Page }
|
7
|
+
let(:site_class) { Locomotive::Steam::Entities::Site }
|
8
|
+
let(:home) { new_page fullpath: { en: 'index' }}
|
9
|
+
let(:site) { site_class.new locales: %w(en fr) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
home_children = [
|
13
|
+
new_page(title: { en: 'Child #1' }, fullpath: { en: 'child_1' }, slug: { en: 'child_1' }, published: true, listed: true),
|
14
|
+
new_page(title: { en: 'Child #2' }, fullpath: { en: 'child_2' }, slug: { en: 'child_2' }, published: true, listed: true)
|
15
|
+
]
|
16
|
+
home.stub(children: home_children)
|
17
|
+
|
18
|
+
other_children = [
|
19
|
+
new_page(title: { en: 'Child #2.1' }, fullpath: { en: 'child_2/sub_child_1' }, slug: { en: 'sub_child_1' }, published: true, listed: true),
|
20
|
+
new_page(title: { en: 'Child #2.2' }, fullpath: { en: 'child_2/sub_child_2' }, slug: { en: 'sub_child_2' }, published: true, listed: true),
|
21
|
+
new_page(title: { en: 'Unpublished #2.2' }, fullpath: { en: 'child_2/sub_child_unpublishd_2' }, slug: { en: 'sub_child_unpublished_2' }, published: false, listed: true),
|
22
|
+
new_page(title: { en: 'Templatized #2.3' }, fullpath: { en: 'child_2/sub_child_template_3' }, slug: { en: 'sub_child_template_3' }, published: true, templatized: true, listed: true),
|
23
|
+
new_page(title: { en: 'Unlisted #2.4' }, fullpath: { en: 'child_2/sub_child_unlisted_4' }, slug: { en: 'sub_child_unlisted_4' }, published: true, listed: false)
|
24
|
+
]
|
25
|
+
home.children.last.stub(children: other_children)
|
26
|
+
|
27
|
+
pages = [home]
|
28
|
+
Locomotive::Models['pages'].stub(root: pages)
|
29
|
+
Locomotive::Models['pages'].stub(all: pages)
|
30
|
+
Locomotive::Models['pages'].stub(:[]).with('index').and_return home
|
31
|
+
end
|
32
|
+
|
33
|
+
context '#rendering' do
|
34
|
+
|
35
|
+
it 'renders from site' do
|
36
|
+
render_nav.should == '<nav id="nav"><ul><li id="child-1-link" class="link first"><a href="/child_1">Child #1</a></li><li id="child-2-link" class="link last"><a href="/child_2">Child #2</a></li></ul></nav>'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'renders from page' do
|
40
|
+
render_nav('page').should == '<nav id="nav"><ul><li id="child-1-link" class="link first"><a href="/child_1">Child #1</a></li><li id="child-2-link" class="link last"><a href="/child_2">Child #2</a></li></ul></nav>'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'renders from parent' do
|
44
|
+
(page = home.children.last.children.first).stub(parent: home.children.last)
|
45
|
+
output = render_nav 'parent', { page: page }
|
46
|
+
output.should == '<nav id="nav"><ul><li id="sub-child-1-link" class="link on first"><a href="/child_2/sub_child_1">Child #2.1</a></li><li id="sub-child-2-link" class="link last"><a href="/child_2/sub_child_2">Child #2.2</a></li></ul></nav>'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'renders children to depth' do
|
50
|
+
output = render_nav('site', {}, 'depth: 2')
|
51
|
+
|
52
|
+
output.should match(/<nav id="nav">/)
|
53
|
+
output.should match(/<ul>/)
|
54
|
+
output.should match(/<li id="child-1-link" class="link first">/)
|
55
|
+
output.should match(/<\/a><ul id="nav-child-2">/)
|
56
|
+
output.should match(/<li id="sub-child-1-link" class="link first">/)
|
57
|
+
output.should match(/<li id="sub-child-2-link" class="link last">/)
|
58
|
+
output.should match(/<\/a><\/li><\/ul><\/li><\/ul><\/nav>/)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'does not render templatized pages' do
|
62
|
+
output = render_nav('site', {}, 'depth: 2')
|
63
|
+
|
64
|
+
output.should_not match(/sub-child-template-3/)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'does not render unpublished pages' do
|
68
|
+
output = render_nav('site', {}, 'depth: 2')
|
69
|
+
|
70
|
+
output.should_not match(/sub-child-unpublished-3/)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'does not render unlisted pages' do
|
74
|
+
output = render_nav('site', {}, 'depth: 2')
|
75
|
+
|
76
|
+
output.should_not match(/sub-child-unlisted-3/)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'does not render nested excluded pages' do
|
80
|
+
output = render_nav('site', {}, 'depth: 2, exclude: "child_2/sub_child_2"')
|
81
|
+
|
82
|
+
output.should match(/<li id="child-2-link" class="link last">/)
|
83
|
+
output.should match(/<li id="sub-child-1-link" class="link first last">/)
|
84
|
+
output.should_not match(/sub-child-2/)
|
85
|
+
|
86
|
+
output = render_nav('site', {}, 'depth: 2, exclude: "child_2"')
|
87
|
+
|
88
|
+
output.should match(/<li id="child-1-link" class="link first last">/)
|
89
|
+
output.should_not match(/child-2/)
|
90
|
+
output.should_not match(/sub-child/)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'adds an icon before the link' do
|
94
|
+
render_nav('site', {}, 'icon: true')
|
95
|
+
.should match(/<li id="child-1-link" class="link first"><a href="\/child_1"><span><\/span> Child #1<\/a>/)
|
96
|
+
render_nav('site', {}, 'icon: before')
|
97
|
+
.should match(/<li id="child-1-link" class="link first"><a href="\/child_1"><span><\/span> Child #1<\/a>/)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'adds an icon after the link' do
|
101
|
+
render_nav('site', {}, 'icon: after')
|
102
|
+
.should match(/<li id="child-1-link" class="link first"><a href="\/child_1">Child #1 <span><\/span><\/a><\/li>/)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'renders a snippet for the title' do
|
106
|
+
render_nav('site', {}, 'snippet: "-{{page.title}} {{ foo.png | theme_image_tag }}-"')
|
107
|
+
.should match( /<li id="child-1-link" class="link first"><a href="\/child_1">-Child #1 <img src=\"\" \/>-<\/a><\/li>/)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'assigns a different dom id' do
|
111
|
+
render_nav('site', {}, 'id: "main-nav"')
|
112
|
+
.should match(/<nav id="main-nav">/)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'assigns a class' do
|
116
|
+
render_nav('site', {}, 'class: "nav"')
|
117
|
+
.should match(/<nav id="nav" class="nav">/)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'assigns a class other than "on" for a selected item', pending: true do
|
121
|
+
(page = @home.children.last.children.first).stubs(:parent).returns(@home.children.last)
|
122
|
+
output = render_nav 'parent', { page: page }, 'active_class: "active"'
|
123
|
+
output.should match(/<li id="sub-child-1-link" class="link active first">/)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'excludes entries based on a regexp' do
|
127
|
+
render_nav('page', {}, 'exclude: "child_1"').should == '<nav id="nav"><ul><li id="child-2-link" class="link first last"><a href="/child_2">Child #2</a></li></ul></nav>'
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'does not render the parent ul' do
|
131
|
+
render_nav('site', {}, 'no_wrapper: true')
|
132
|
+
.should_not match(/<ul id="nav">/)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'localizes the links' do
|
136
|
+
I18n.with_locale('fr') do
|
137
|
+
render_nav.should == '<nav id="nav"><ul><li id="child-1-link" class="link first"><a href="/fr/child_1">Child #1</a></li><li id="child-2-link" class="link last"><a href="/fr/child_2">Child #2</a></li></ul></nav>'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
def new_page attributes
|
144
|
+
Locomotive::Steam::Decorators::PageDecorator.new(
|
145
|
+
Locomotive::Decorators::I18nDecorator.new(
|
146
|
+
entity_class.new(attributes), :en
|
147
|
+
)
|
148
|
+
)
|
149
|
+
end
|
150
|
+
|
151
|
+
def render_nav(source = 'site', registers = {}, template_option = '')
|
152
|
+
registers = { site: site, page: home }.merge(registers)
|
153
|
+
liquid_context = ::Liquid::Context.new({}, {}, registers)
|
154
|
+
|
155
|
+
output = Liquid::Template.parse("{% nav #{source} #{template_option} %}").render(liquid_context)
|
156
|
+
output.gsub(/\n\s{0,}/, '')
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Steam::Loader::Yml::PagesLoader do
|
4
|
+
|
5
|
+
|
6
|
+
let(:path) { default_fixture_site_path }
|
7
|
+
let(:loader) { Locomotive::Steam::Loader::Yml::PagesLoader.new path, mapper }
|
8
|
+
subject { loader }
|
9
|
+
before { Locomotive::Models[:pages].current_locale = :en }
|
10
|
+
|
11
|
+
describe '#initialize' do
|
12
|
+
it { should be_kind_of Object }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#load!' do
|
16
|
+
before { loader.load! }
|
17
|
+
it 'loads pages in the pages Repository' do
|
18
|
+
Locomotive::Models[:pages].all.size.should > 0
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'creates only one Entity for all locales' do
|
22
|
+
Locomotive::Models[:pages].matching_paths(['index']).all.size.should eq 1
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'records content' do
|
26
|
+
subject { Locomotive::Models[:pages]['index'] }
|
27
|
+
it { subject.title[:en].should eql 'Home page' }
|
28
|
+
it { subject.title[:fr].should eql 'Page d\'accueil' }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'records template' do
|
32
|
+
subject { Locomotive::Models[:pages]['basic'] }
|
33
|
+
it { subject.template[:en].source.should =~ /<title>{{ page.title }}<\/title>/ }
|
34
|
+
it { subject.template[:en].raw_source.should =~ /%title {{ page.title }}/ }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'fills in non localized data with default locale values', pending: 'not sure if the right behaviour' do
|
38
|
+
subject { Locomotive::Models[:pages]['basic'] }
|
39
|
+
it { subject.title[:fr].should eql 'Basic page' }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Steam::Loader::Yml::SiteLoader do
|
4
|
+
|
5
|
+
let(:path) { default_fixture_site_path }
|
6
|
+
let(:loader) { Locomotive::Steam::Loader::Yml::SiteLoader.new path, mapper }
|
7
|
+
|
8
|
+
before { loader.load! }
|
9
|
+
|
10
|
+
subject { Locomotive::Models[:sites].all.first }
|
11
|
+
|
12
|
+
it { should be_kind_of Locomotive::Steam::Entities::Site }
|
13
|
+
its(:name) { should eql 'Sample website' }
|
14
|
+
its(:domains) { should eql ['example.org', 'sample.example.com', '0.0.0.0'] }
|
15
|
+
context 'localized fields' do
|
16
|
+
it do
|
17
|
+
subject.seo_title[:en].should eq 'A simple LocomotiveCMS website'
|
18
|
+
subject.seo_title[:fr].should eq 'Un simple LocomotiveCMS site web'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Steam::Utils::LocalizedTree do
|
4
|
+
|
5
|
+
describe '#to_hash' do
|
6
|
+
let(:tree) { [ 'a.fr.haml', 'a.haml', 'b.xml', 'b.fr.haml', 'z.txt' ] }
|
7
|
+
let(:extensions) { ['haml','xml'] }
|
8
|
+
subject { Locomotive::Steam::Utils::LocalizedTree.new(tree, extensions).to_hash }
|
9
|
+
|
10
|
+
|
11
|
+
it { should be_kind_of Hash }
|
12
|
+
|
13
|
+
it 'has root as key' do
|
14
|
+
subject.keys.should eq ['a', 'b']
|
15
|
+
end
|
16
|
+
|
17
|
+
it { should eql ({
|
18
|
+
'a' => {fr: 'a.fr.haml', default: 'a.haml'},
|
19
|
+
'b' => {default: 'b.xml', fr: 'b.fr.haml'}
|
20
|
+
})
|
21
|
+
}
|
22
|
+
|
23
|
+
context 'multiple extensions' do
|
24
|
+
let(:tree) { [ 'a.fr.haml.xml', 'a.haml', 'b.xml.haml', 'b.fr.haml'] }
|
25
|
+
it { should eql ({
|
26
|
+
'a' => {fr: 'a.fr.haml.xml', default: 'a.haml'},
|
27
|
+
'b' => {default: 'b.xml.haml', fr: 'b.fr.haml'}
|
28
|
+
})
|
29
|
+
}
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Steam::Utils::YAMLFrontMattersTemplate do
|
4
|
+
|
5
|
+
let(:regular_content) do
|
6
|
+
<<YAMLRAW
|
7
|
+
%p Content
|
8
|
+
YAMLRAW
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:attributes_content) do
|
12
|
+
<<YAMLRAW
|
13
|
+
---
|
14
|
+
data: value 1
|
15
|
+
other: value 2
|
16
|
+
---
|
17
|
+
%p Content
|
18
|
+
YAMLRAW
|
19
|
+
end
|
20
|
+
|
21
|
+
subject { Locomotive::Steam::Utils::YAMLFrontMattersTemplate.new('dummy_path.haml') }
|
22
|
+
before { subject.stub(data: content) }
|
23
|
+
|
24
|
+
context 'regular data' do
|
25
|
+
let(:content) { regular_content }
|
26
|
+
its(:source) { should eql "<p>Content</p>\n" }
|
27
|
+
its(:line_offset) { should eql 0 }
|
28
|
+
its(:attributes) { should eql({}) }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'data with attributes' do
|
32
|
+
let(:content) { attributes_content }
|
33
|
+
its(:source) { should eql "<p>Content</p>\n" }
|
34
|
+
its(:line_offset) { should eql 4 }
|
35
|
+
its(:attributes) { should eql 'data' => 'value 1', 'other' => 'value 2' }
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|