Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sections & snippets within subfolders #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/locomotive/steam/adapters/filesystem/yaml_loaders/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ def load(scope)
private

def load_list
Dir.glob(File.join(path, "*.{#{template_extensions.join(',')}}")).map do |filepath|
slug = File.basename(filepath).split('.').first
build(filepath, slug.permalink)
Dir.glob(File.join(path, "**", "*.{#{template_extensions.join(',')}}")).map do |filepath|
basename = File.basename(filepath)
subfolder = filepath.sub(path, '').sub(/^\//, '').sub(basename, '')
slug = basename.split('.').first.permalink

if subfolder != ''
slug.prepend(subfolder)
end

build(filepath, slug)
end
end

Expand Down
20 changes: 16 additions & 4 deletions lib/locomotive/steam/adapters/filesystem/yaml_loaders/snippet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,23 @@ def update(element, filepath, locale)
end

def each_file(&block)
Dir.glob(File.join(path, "*.{#{template_extensions.join(',')}}")).each do |filepath|
slug, locale = File.basename(filepath).split('.')[0..1]
locale = default_locale if template_extensions.include?(locale)
Dir.glob(File.join(path, "**", "*.{#{template_extensions.join(',')}}")).each do |filepath|
basename = File.basename(filepath)
subfolder = filepath.sub(path, '').sub(/^\//, '').sub(basename, '')

yield(filepath, slug.permalink, locale.to_sym)
slug, locale = basename.split('.')[0..1]

if template_extensions.include?(locale)
locale = default_locale
end

slug = slug.permalink

if subfolder != ''
slug.prepend(subfolder)
end

yield(filepath, slug, locale.to_sym)
end
end

Expand Down