Class: Sourcerer::Jekyll::Liquid::FileSystem
- Inherits:
-
Liquid::LocalFileSystem
- Object
- Liquid::LocalFileSystem
- Sourcerer::Jekyll::Liquid::FileSystem
- Defined in:
- lib/sourcerer/jekyll/liquid/file_system.rb
Overview
A custom Liquid file system that extends `Liquid::LocalFileSystem` to support
multiple root paths for template lookups. This allows templates to be
resolved from a prioritized list of directories.
Instance Method Summary collapse
-
#full_path(template_path) ⇒ String
Finds the full path of a template, searching through multiple roots if configured.
-
#initialize(roots_or_root) ⇒ FileSystem
constructor
Initializes the file system with one or more root paths.
-
#read_template_file(template_path) ⇒ String
Reads the content of a template file.
Constructor Details
#initialize(roots_or_root) ⇒ FileSystem
Initializes the file system with one or more root paths.
rubocop:disable Lint/MissingSuper
Intentional: Custom implementation that doesn't need parent's initialization
17 18 19 20 21 22 23 24 25 |
# File 'lib/sourcerer/jekyll/liquid/file_system.rb', line 17 def initialize roots_or_root if roots_or_root.is_a?(Array) @roots = roots_or_root.map { |root| File.(root) } @multi_root = true else @root = File.(roots_or_root) @multi_root = false end end |
Instance Method Details
#full_path(template_path) ⇒ String
Finds the full path of a template, searching through multiple roots if configured.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sourcerer/jekyll/liquid/file_system.rb', line 33 def full_path template_path if @multi_root @roots.each do |root| full = File.(File.join(root, template_path)) return full if File.exist?(full) && full.start_with?(root) end raise ::Liquid::FileSystemError, "Template not found: '#{template_path}' in paths: #{@roots}" else full = File.(File.join(@root, template_path)) validate_path(full) end end |
#read_template_file(template_path) ⇒ String
Reads the content of a template file.
50 51 52 53 |
# File 'lib/sourcerer/jekyll/liquid/file_system.rb', line 50 def read_template_file template_path path = full_path(template_path) File.read(path) end |