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) ⇒ String
Resolve output path for generated filename.
-
#resolve_relative_output_path(filename) ⇒ String
Resolve relative output path for manifest storage.
-
#resolve_source_output_path(filename) ⇒ 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
110 111 112 113 114 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 110 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
120 121 122 123 124 125 126 127 128 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 120 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) ⇒ String
Resolve output path for generated filename
65 66 67 68 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 65 def resolve_output_path(filename) # Resolve output path relative to site destination File.join(@config.site.dest, @config.output, filename) end |
#resolve_relative_output_path(filename) ⇒ String
Resolve relative output path for manifest storage
81 82 83 84 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 81 def resolve_relative_output_path(filename) # Return path relative to site root (without leading /) File.join(@config.output, filename) end |
#resolve_source_output_path(filename) ⇒ String
Resolve output path to source directory for default images
73 74 75 76 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 73 def resolve_source_output_path(filename) # Default images go to source directory so Jekyll can copy them to _site File.join(@config.site.source, @config.output, filename) end |
#site_dest ⇒ String
Get site destination directory
88 89 90 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 88 def site_dest @config.site.dest end |
#temp_input_path(extension = "tmp") ⇒ String
Generate temporary input path
102 103 104 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 102 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
95 96 97 |
# File 'lib/jekyll-imgflow/path_resolver.rb', line 95 def temp_output_path(format) File.join(Dir.tmpdir, "imgflow-out-#{SecureRandom.hex}.#{format}") end |