beachio-hammer 0.1.0.pre2 → 0.1.0.pre3

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: 9ff203a27e8f29525a3120a073279ab2e8578f9d60a49a7f1c62c7ebf1a59253
4
+ data.tar.gz: e706eaee172b73d6abf8c14f7d936adb48144b2c4b2fc8ebdbf44fcfb9952f81
5
5
  SHA512:
6
- metadata.gz: 6ddf7826fd3a196ab07e5678a3735d3f9aeb236174f6c3deba61fc3c0594174eae7314ded5585aeb8a84c95de6bf35c741f71746106ff61920fe677166dae312
7
- data.tar.gz: 8c13c6e4cbc8c6c36453bdc0c3d0f393182d42e3521d310bf6771ffbdc4ce91e507dda1709521f61ca8caa9cf35537015db220a654374c659fc0b0ff6ef37435
6
+ metadata.gz: 47a316f9de1c74ec4c16881c2663ab8aa172256264fe6e7aa66aa84d95f7d26a8082bdf521bc998bcb26f5e8bc621b8b05c6301034ead326e2dbb8271e292185
7
+ data.tar.gz: 3c5cbc689cb680d0e3adf630adfc2add3f13285aebdd2f6dae258ea83deff4a7364dfe609ac816e638dab2b732ab2cf63404b9effe1d5424afb8ac182e7e35d0
data/PUBLISH.md CHANGED
@@ -38,7 +38,13 @@ 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.pre3`**
42
+
43
+ ### 0.1.0.pre3 changes (nested @path resolution)
44
+
45
+ - Resolve `@path` using full path segments (not basename only)
46
+ - Resolve directory paths via `index.html` lookup
47
+ - Always emit context-aware relative URLs (Swift parity)
42
48
 
43
49
  ### 0.1.0.pre2 changes (Beachio / Linux fixes)
44
50
 
@@ -52,7 +58,7 @@ Prerelease pin for executor team: **`beachio-hammer` `0.1.0.pre2`**
52
58
  Pin the published gem version in the executor Dockerfile:
53
59
 
54
60
  ```dockerfile
55
- RUN gem install beachio-hammer -v 0.1.0.pre2
61
+ RUN gem install beachio-hammer -v 0.1.0.pre3
56
62
  ```
57
63
 
58
64
  Build step in the agent:
@@ -349,34 +349,58 @@ 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).tr(" ", "%20")
375
+ relative_path = "#{relative_path}/" if preserve_slash && !relative_path.end_with?("/")
376
+
377
+ @delegate&.warning(@current_file_path, "File not found: #{ref}") if paths.empty?
378
+
379
+ generate_context_aware_path(relative_path, preserve_trailing_slash: preserve_slash)
380
+ .tr("%20", " ")
381
+ .gsub(" ", "%20")
382
+ end
383
+
384
+ def root_relative_path
385
+ return "./" unless @current_file_path
386
+
387
+ current_dir = current_directory_components
388
+ return "./" if current_dir.empty?
389
+
390
+ "#{"../" * current_dir.length}"
391
+ end
392
+
372
393
  def find_file(filename)
373
394
  found = []
395
+ direct_path = File.join(@source_directory, filename)
396
+ found << filename if File.file?(direct_path)
397
+
374
398
  dirs = %w[assets/img assets/images assets/media images img media]
375
399
  dirs.each do |dir|
376
400
  path = "#{dir}/#{filename}"
377
401
  found << path if File.file?(File.join(@source_directory, path))
378
402
  end
379
- found << filename if File.file?(File.join(@source_directory, filename))
403
+ found.uniq!
380
404
 
381
405
  if found.empty? || found.length > 1
382
406
  Dir.glob(File.join(@source_directory, "**", "*")).each do |f|
@@ -384,7 +408,9 @@ module Hammer
384
408
  rel = f.delete_prefix("#{@source_directory}/")
385
409
  next if skip_scan_path?(rel)
386
410
 
387
- found << rel if File.basename(f) == filename && !found.include?(rel)
411
+ if rel == filename || File.basename(f) == filename
412
+ found << rel unless found.include?(rel)
413
+ end
388
414
  end
389
415
  end
390
416
 
@@ -394,26 +420,37 @@ module Hammer
394
420
  [found, nil]
395
421
  end
396
422
 
397
- def generate_context_aware_path(file_path)
423
+ def current_directory_components
424
+ @current_file_path.split("/")[0...-1].reject { |part| part == "." || part.empty? }
425
+ end
426
+
427
+ def generate_context_aware_path(file_path, preserve_trailing_slash: file_path.end_with?("/"))
398
428
  return "./#{file_path}" unless @current_file_path
399
429
 
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 == "." }
430
+ path_for_processing = preserve_trailing_slash ? file_path.chomp("/") : file_path
431
+ current_dir = current_directory_components
402
432
  target_parts = path_for_processing.split("/")
403
433
  common = 0
404
434
  common += 1 while common < current_dir.length && common < target_parts.length && current_dir[common] == target_parts[common]
405
435
 
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]}"
436
+ if current_dir == target_parts
437
+ result = "./"
414
438
  else
415
- parts.join("/")
416
- end.tap { |r| r << "/" if file_path.end_with?("/") && !r.end_with?("/") }
439
+ levels_up = current_dir.length - common
440
+ remaining = target_parts[common..]
441
+ parts = ([".."] * levels_up) + remaining
442
+
443
+ result = if parts.empty?
444
+ "./#{target_parts.last}"
445
+ elsif levels_up.zero? && remaining.length == 1
446
+ "./#{remaining[0]}"
447
+ else
448
+ parts.join("/")
449
+ end
450
+ end
451
+
452
+ result << "/" if preserve_trailing_slash && !result.end_with?("/")
453
+ result
417
454
  end
418
455
 
419
456
  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.pre3"
5
5
  end
@@ -0,0 +1,26 @@
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
+ 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.pre3
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: