Class: JekyllImgFlow::PathResolver
- Inherits:
-
Object
- Object
- JekyllImgFlow::PathResolver
- Defined in:
- lib/jekyll-imgflow/path_resolver.rb
Overview
PathResolver - centralized path management for all image operations
Instance Method Summary collapse
-
#build_url(relative_path, site) ⇒ String
Build public URL for image.
-
#cli_path(image_name) ⇒ Object
Get CLI path (convenience method).
-
#http_path(image_name) ⇒ Object
Get HTTP path (convenience method).
-
#initialize(config) ⇒ PathResolver
constructor
A new instance of PathResolver.
-
#paths_for(image_name) ⇒ Hash
Get path information for an image.
-
#relative_from_dest(full_path, site) ⇒ String
Get relative path from site destination.
-
#resolve_original_path(image_name) ⇒ String
Resolve original path with validation.
-
#resolve_output_path(filename, subdir = nil) ⇒ String
Resolve output path for generated filename.
-
#resolve_relative_output_path(filename, subdir = nil) ⇒ String
Resolve relative output path for manifest storage.
-
#resolve_source_output_path(filename, subdir = nil) ⇒ String
Resolve output path to source directory for default images.
-
#site_dest ⇒ String
Get site destination directory.
-
#temp_input_path(extension = "tmp") ⇒ String
Generate temporary input path.
-
#temp_output_path(format) ⇒ String
Generate temporary output path.
Constructor Details
#initialize(config) ⇒ PathResolver
Returns a new instance of PathResolver.
9 10 11 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 9 def initialize(config) @config = config end |
Instance Method Details
#build_url(relative_path, site) ⇒ String
Build public URL for image
113 114 115 116 117 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 113 def build_url(relative_path, site) base_url = site.config["url"] || "http://localhost:4000" baseurl = site.config["baseurl"] || "" "#{base_url}#{baseurl}/#{relative_path}" end |
#cli_path(image_name) ⇒ Object
Get CLI path (convenience method)
25 26 27 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 25 def cli_path(image_name) paths_for(image_name)[:cli] end |
#http_path(image_name) ⇒ Object
Get HTTP path (convenience method)
30 31 32 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 30 def http_path(image_name) paths_for(image_name)[:http] end |
#paths_for(image_name) ⇒ Hash
Get path information for an image
16 17 18 19 20 21 22 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 16 def paths_for(image_name) { cli: File.join(@config.site.source, @config.originals, image_name), # Full filesystem path http: File.join(@config.originals, image_name), # Relative path for URLs name: image_name # Just the filename } end |
#relative_from_dest(full_path, site) ⇒ String
Get relative path from site destination
123 124 125 126 127 128 129 130 131 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 123 def relative_from_dest(full_path, site) # Simple path manipulation - remove site.dest prefix and leading slash if full_path.start_with?(site.dest) relative = full_path[site.dest.length..] relative.start_with?("/") ? relative[1..] : relative else full_path end end |
#resolve_original_path(image_name) ⇒ String
Resolve original path with validation
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 38 def resolve_original_path(image_name) full_path = cli_path(image_name) # Validate path exists and is readable raise ArgumentError, "Cannot resolve image path: #{image_name} (not found: #{full_path})" unless File.exist?(full_path) raise ArgumentError, "Image path is not a file: #{image_name} (path: #{full_path})" unless File.file?(full_path) raise ArgumentError, "Image path not readable: #{image_name} (path: #{full_path})" unless File.readable?(full_path) # Validate input file format against config file_extension = File.extname(full_path).delete(".").downcase input_formats = @config.input_formats raise ArgumentError, "No input_formats configured in unified config" unless input_formats unless input_formats.include?(file_extension) raise ArgumentError, "Invalid input format: '#{file_extension}'. Must be one of: #{input_formats.join(', ')}." end full_path end |
#resolve_output_path(filename, subdir = nil) ⇒ String
Resolve output path for generated filename
66 67 68 69 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 66 def resolve_output_path(filename, subdir = nil) # Resolve output path relative to site destination File.join([@config.site.dest, @config.output, subdir, filename].compact) end |
#resolve_relative_output_path(filename, subdir = nil) ⇒ String
Resolve relative output path for manifest storage
84 85 86 87 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 84 def resolve_relative_output_path(filename, subdir = nil) # Return path relative to site root (without leading /) File.join([@config.output, subdir, filename].compact) end |
#resolve_source_output_path(filename, subdir = nil) ⇒ String
Resolve output path to source directory for default images
75 76 77 78 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 75 def resolve_source_output_path(filename, subdir = nil) # Default images go to source directory so Jekyll can copy them to _site File.join([@config.site.source, @config.output, subdir, filename].compact) end |
#site_dest ⇒ String
Get site destination directory
91 92 93 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 91 def site_dest @config.site.dest end |
#temp_input_path(extension = "tmp") ⇒ String
Generate temporary input path
105 106 107 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 105 def temp_input_path(extension = "tmp") File.join(Dir.tmpdir, "imgflow-in-#{SecureRandom.hex}.#{extension}") end |
#temp_output_path(format) ⇒ String
Generate temporary output path
98 99 100 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 98 def temp_output_path(format) File.join(Dir.tmpdir, "imgflow-out-#{SecureRandom.hex}.#{format}") end |