create empty pages for folders (filesystem adapter)
did
committed May 12, 2015
commit 73ded64e99c298d768885abe20508f2b8f0f6bfb
Showing 3
changed files with
32 additions
and 14 deletions
locomotive/steam/adapters/filesystem/yaml_loaders/page.rb b/lib/locomotive/steam/adapters/filesystem/yaml_loaders/page.rb
+30
-8
| @@ | @@ -21,7 +21,7 @@ module Locomotive |
| def load_tree | |
| {}.tap do |hash| | |
| - | each_file do |filepath, relative_path, fullpath, locale| |
| + | each_file do |filepath, fullpath, locale| |
| if leaf = hash[fullpath] | |
| update(leaf, filepath, fullpath, locale) | |
| @@ | @@ -31,6 +31,10 @@ module Locomotive |
| hash[fullpath] = leaf | |
| end | |
| + | |
| + | each_directory do |filepath, fullpath, locale| |
| + | hash[fullpath] ||= build(filepath, fullpath, locale) |
| + | end |
| end.values | |
| end | |
| @@ | @@ -63,12 +67,20 @@ module Locomotive |
| end | |
| def get_attributes(filepath, fullpath) | |
| - | _load(filepath, true) do |attributes, template| |
| - | # make sure index/404 are the slugs of the index/404 pages |
| - | attributes.delete(:slug) if %w(index 404).include?(fullpath) |
| + | if File.directory?(filepath) |
| + | { |
| + | title: File.basename(filepath).humanize, |
| + | listed: false, |
| + | published: false |
| + | } |
| + | else |
| + | _load(filepath, true) do |attributes, template| |
| + | # make sure index/404 are the slugs of the index/404 pages |
| + | attributes.delete(:slug) if %w(index 404).include?(fullpath) |
| - | # trick to use the template of the default locale (if available) |
| - | attributes[:template_path] = false if template.blank? |
| + | # trick to use the template of the default locale (if available) |
| + | attributes[:template_path] = false if template.blank? |
| + | end |
| end | |
| end | |
| @@ | @@ -82,7 +94,17 @@ module Locomotive |
| locale = template_extensions.include?(extension_or_locale) ? default_locale : extension_or_locale | |
| - | yield(filepath, relative_path, fullpath, locale.to_sym) |
| + | yield(filepath, fullpath, locale.to_sym) |
| + | end |
| + | end |
| + | |
| + | def each_directory(&block) |
| + | Dir.glob(File.join(path, '**', '*')).each do |filepath| |
| + | next unless File.directory?(filepath) |
| + | |
| + | fullpath = get_relative_path(filepath) |
| + | |
| + | yield(filepath, fullpath, default_locale.to_sym) |
| end | |
| end | |
| @@ | @@ -91,7 +113,7 @@ module Locomotive |
| end | |
| def template_path(filepath, attributes, locale) | |
| - | if attributes.delete(:template_path) == false && locale != default_locale |
| + | if File.directory?(filepath) || (attributes.delete(:template_path) == false && locale != default_locale) |
| false | |
| else | |
| filepath | |
spec/fixtures/default/app/views/pages/songs.liquid
+0
-6
| @@ | @@ -1,6 +0,0 @@ |
| - | --- |
| - | title: Songs |
| - | listed: false |
| - | published: false |
| - | position: 14 |
| - | --- |
spec/unit/adapters/filesystem/yaml_loaders/page_spec.rb
+2
-0
| @@ | @@ -18,6 +18,8 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::Page do |
| expect(subject.size).to eq 24 | |
| expect(subject.first[:title]).to eq(en: 'Page not found') | |
| expect(subject[14][:slug]).to eq(en: 'music', fr: 'notre-musique') | |
| + | expect(subject[15][:_fullpath]).to eq 'songs' |
| + | expect(subject[15][:template_path]).to eq(en: false) |
| end | |
| end | |