beachio-hammer 0.1.0.pre2 → 0.1.0.pre4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 341e9e0b4490d2d81d9bde191b50a864433452053f9045abf61ce6bf4ef8b8b4
4
- data.tar.gz: 68c2e73b72fef89934937920211fdb35ccdb224d6e02c4ccf75b993e43aa1d9e
3
+ metadata.gz: 3470eba02cbe963f2f12e5b4d9cc94c2cb7d2b770ada0e7ca90de6c3a57e74a8
4
+ data.tar.gz: 336084edab3f5528a9dc6171b8b5fb363e1e6d05ab456d10fb15905583752b2e
5
5
  SHA512:
6
- metadata.gz: 6ddf7826fd3a196ab07e5678a3735d3f9aeb236174f6c3deba61fc3c0594174eae7314ded5585aeb8a84c95de6bf35c741f71746106ff61920fe677166dae312
7
- data.tar.gz: 8c13c6e4cbc8c6c36453bdc0c3d0f393182d42e3521d310bf6771ffbdc4ce91e507dda1709521f61ca8caa9cf35537015db220a654374c659fc0b0ff6ef37435
6
+ metadata.gz: 2dd5e1d16f62a38b7bde783e30313ef54d10c17dd001abbcd1a9ddf374f1255dac772f7f312a0312c28d44da1c8d781dd312d1b915ebe4af95f7a7a22bebd41d
7
+ data.tar.gz: 49089ebfa731d5c58a7f5d91634cf726eb44c320c7dc84782fcf374b4ef9a4eec97745533cb962c8c3ef2f6fbbf7be575b170f8b63c32fa9a548dc55b1bf4970
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- beachio-hammer (0.1.0.pre2)
4
+ beachio-hammer (0.1.0.pre4)
5
5
  json (~> 2.7)
6
6
 
7
7
  GEM
data/PUBLISH.md CHANGED
@@ -38,7 +38,17 @@ gem build beachio-hammer.gemspec
38
38
  gem push beachio-hammer-*.gem
39
39
  ```
40
40
 
41
- Prerelease pin for executor team: **`beachio-hammer` `0.1.0.pre2`**
41
+ Prerelease pin for executor team: **`beachio-hammer` `0.1.0.pre4`**
42
+
43
+ ### 0.1.0.pre4 changes (filename digit corruption)
44
+
45
+ - Fix `@path` URL encoding: stop using `tr("%20", " ")` which mangled filenames containing `2` (e.g. `forge-2.jpg` → `forge-%20.jpg`)
46
+
47
+ ### 0.1.0.pre3 changes (nested @path resolution)
48
+
49
+ - Resolve `@path` using full path segments (not basename only)
50
+ - Resolve directory paths via `index.html` lookup
51
+ - Always emit context-aware relative URLs (Swift parity)
42
52
 
43
53
  ### 0.1.0.pre2 changes (Beachio / Linux fixes)
44
54
 
@@ -52,7 +62,7 @@ Prerelease pin for executor team: **`beachio-hammer` `0.1.0.pre2`**
52
62
  Pin the published gem version in the executor Dockerfile:
53
63
 
54
64
  ```dockerfile
55
- RUN gem install beachio-hammer -v 0.1.0.pre2
65
+ RUN gem install beachio-hammer -v 0.1.0.pre4
56
66
  ```
57
67
 
58
68
  Build step in the agent:
@@ -349,34 +349,57 @@ module Hammer
349
349
  ref = get_variable(ref[1..]) || ref
350
350
  end
351
351
 
352
- if ref == "/"
353
- generate_context_aware_path(".")
354
- else
355
- preserve_slash = ref.end_with?("/")
356
- filename = preserve_slash ? ref.chomp("/") : ref
357
- paths, error = find_file(File.basename(filename))
358
- raise TagError, error if error
359
-
360
- if paths.empty?
361
- @delegate&.warning(@current_file_path, "File not found: #{ref}")
362
- ref
363
- else
364
- path = paths.first
365
- path = "#{path}/" if preserve_slash
366
- generate_context_aware_path(path).gsub("%20", " ").gsub(" ", "%20")
367
- end
368
- end
352
+ resolve_path_reference(ref)
369
353
  end
370
354
  end
371
355
 
356
+ def resolve_path_reference(ref)
357
+ if ref == "/"
358
+ return root_relative_path
359
+ end
360
+
361
+ preserve_slash = ref.end_with?("/")
362
+ search_path = preserve_slash ? ref.chomp("/") : ref
363
+ paths, error = find_file(search_path)
364
+ raise TagError, error if error
365
+
366
+ if preserve_slash && paths.empty?
367
+ index_path = "#{search_path}/index.html"
368
+ index_paths, index_error = find_file(index_path)
369
+ raise TagError, index_error if index_error
370
+
371
+ paths = [search_path] unless index_paths.empty?
372
+ end
373
+
374
+ relative_path = paths.first || search_path
375
+ relative_path = relative_path.gsub(" ", "%20")
376
+ relative_path = "#{relative_path}/" if preserve_slash && !relative_path.end_with?("/")
377
+
378
+ @delegate&.warning(@current_file_path, "File not found: #{ref}") if paths.empty?
379
+
380
+ generate_context_aware_path(relative_path, preserve_trailing_slash: preserve_slash)
381
+ end
382
+
383
+ def root_relative_path
384
+ return "./" unless @current_file_path
385
+
386
+ current_dir = current_directory_components
387
+ return "./" if current_dir.empty?
388
+
389
+ "#{"../" * current_dir.length}"
390
+ end
391
+
372
392
  def find_file(filename)
373
393
  found = []
394
+ direct_path = File.join(@source_directory, filename)
395
+ found << filename if File.file?(direct_path)
396
+
374
397
  dirs = %w[assets/img assets/images assets/media images img media]
375
398
  dirs.each do |dir|
376
399
  path = "#{dir}/#{filename}"
377
400
  found << path if File.file?(File.join(@source_directory, path))
378
401
  end
379
- found << filename if File.file?(File.join(@source_directory, filename))
402
+ found.uniq!
380
403
 
381
404
  if found.empty? || found.length > 1
382
405
  Dir.glob(File.join(@source_directory, "**", "*")).each do |f|
@@ -384,7 +407,9 @@ module Hammer
384
407
  rel = f.delete_prefix("#{@source_directory}/")
385
408
  next if skip_scan_path?(rel)
386
409
 
387
- found << rel if File.basename(f) == filename && !found.include?(rel)
410
+ if rel == filename || File.basename(f) == filename
411
+ found << rel unless found.include?(rel)
412
+ end
388
413
  end
389
414
  end
390
415
 
@@ -394,26 +419,37 @@ module Hammer
394
419
  [found, nil]
395
420
  end
396
421
 
397
- def generate_context_aware_path(file_path)
422
+ def current_directory_components
423
+ @current_file_path.split("/")[0...-1].reject { |part| part == "." || part.empty? }
424
+ end
425
+
426
+ def generate_context_aware_path(file_path, preserve_trailing_slash: file_path.end_with?("/"))
398
427
  return "./#{file_path}" unless @current_file_path
399
428
 
400
- path_for_processing = file_path.end_with?("/") ? file_path.chomp("/") : file_path
401
- current_dir = File.dirname(@current_file_path).split("/").reject { |p| p == "." }
429
+ path_for_processing = preserve_trailing_slash ? file_path.chomp("/") : file_path
430
+ current_dir = current_directory_components
402
431
  target_parts = path_for_processing.split("/")
403
432
  common = 0
404
433
  common += 1 while common < current_dir.length && common < target_parts.length && current_dir[common] == target_parts[common]
405
434
 
406
- levels_up = current_dir.length - common
407
- remaining = target_parts[common..]
408
- parts = ([".."] * levels_up) + remaining
409
-
410
- if parts.empty?
411
- "./#{target_parts.last}"
412
- elsif levels_up.zero? && remaining.length == 1
413
- "./#{remaining[0]}"
435
+ if current_dir == target_parts
436
+ result = "./"
414
437
  else
415
- parts.join("/")
416
- end.tap { |r| r << "/" if file_path.end_with?("/") && !r.end_with?("/") }
438
+ levels_up = current_dir.length - common
439
+ remaining = target_parts[common..]
440
+ parts = ([".."] * levels_up) + remaining
441
+
442
+ result = if parts.empty?
443
+ "./#{target_parts.last}"
444
+ elsif levels_up.zero? && remaining.length == 1
445
+ "./#{remaining[0]}"
446
+ else
447
+ parts.join("/")
448
+ end
449
+ end
450
+
451
+ result << "/" if preserve_trailing_slash && !result.end_with?("/")
452
+ result
417
453
  end
418
454
 
419
455
  def process_navigation_helpers(content)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hammer
4
- VERSION = "0.1.0.pre2"
4
+ VERSION = "0.1.0.pre4"
5
5
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Hammer::TagParser do
6
+ let(:source_directory) { File.expand_path("../../Test Projects/classic-fixture", __dir__) }
7
+ let(:parser) { described_class.new(source_directory: source_directory) }
8
+
9
+ it "resolves nested @path references relative to the output page" do
10
+ parser.current_file_path = "work/mixfit/index.html"
11
+ content = '<a href="<!-- @path products/gleo/ -->">'
12
+
13
+ result = parser.send(:parse, content)
14
+
15
+ expect(result).to include('href="../../products/gleo/"')
16
+ end
17
+
18
+ it "resolves root @path references from nested pages" do
19
+ parser.current_file_path = "work/mixfit/index.html"
20
+ content = '<a href="<!-- @path / -->">'
21
+
22
+ result = parser.send(:parse, content)
23
+
24
+ expect(result).to include('href="../../"')
25
+ end
26
+
27
+ it "does not corrupt digits in image filenames when resolving @path" do
28
+ parser.current_file_path = "products/forge/index.html"
29
+ content = '<img src="<!-- @path assets/images/products/forge-2.jpg -->" />'
30
+
31
+ result = parser.send(:parse, content)
32
+
33
+ expect(result).to include('src="../../assets/images/products/forge-2.jpg"')
34
+ expect(result).not_to include("forge-%20.jpg")
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beachio-hammer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre2
4
+ version: 0.1.0.pre4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beach.io
@@ -80,6 +80,7 @@ files:
80
80
  - spec/encoding_spec.rb
81
81
  - spec/parity/classic_spec.rb
82
82
  - spec/parity/content_spec.rb
83
+ - spec/path_resolution_spec.rb
83
84
  - spec/spec_helper.rb
84
85
  homepage: https://github.com/beachio/hammer-swift
85
86
  licenses: