Map output file to content file inside a custom check?

5 views
Skip to first unread message

jmf...@gmail.com

unread,
Nov 26, 2025, 4:19:19 PM (2 days ago) Nov 26
to nanoc
Inside a custom nanoc check I built, I would like the error message to point to the input file that contains the problem, not just the output file. 

There is a collection of @items available inside the checks, as well as the "output_filenames" collection but there does not seem to be an easy way to get a mapping from one to the other? I was hoping to use @item.path or something. I assume nanoc has that information somewhere in its innards. Am I overlooking something?

Denis Defreyne

unread,
Nov 27, 2025, 3:15:52 AM (yesterday) Nov 27
to na...@googlegroups.com
Hey Jan,

That information is indeed (mostly) available. Here is an example check that bases itself off @items:

Nanoc::Check.define(:sample) do
  all_item_reps = @items.flat_map { |i| i.reps.to_a }

  all_item_reps.each do |rep|
    path = rep.raw_path
    next unless path # some reps have no paths (are not written)

    add_issue(
      "something is rotten",
      subject: "#{path} --- #{rep.item.identifier}",
    )
  end
end

There is one limitation here: it only looks at the :default snapshot of item representations. That is fine if you 1) don’t have rules that have multiple `write` instructions, and 2) don’t have routing rules that apply to specific non-default snapshots.

There is currently no way to request the list of snapshot names of an item representation. I’ll look into making that possible. Then, the code would look like this:

  all_item_reps.each do |rep|
    # DOES NOT WORK YET:
    rep.snapshot_names.each do |snapshot_name|
      path = rep.raw_path(snapshot: snapshot_name)
      next unless path # some reps have no paths (are not written)

Hope this helps,

On 2025-11-26 at 22:19, jmf...@gmail.com wrote:
Inside a custom nanoc check I built, I would like the error message to point to the input file that contains the problem, not just the output file. 

There is a collection of @items available inside the checks, as well as the "output_filenames" collection but there does not seem to be an easy way to get a mapping from one to the other? I was hoping to use @item.path or something. I assume nanoc has that information somewhere in its innards. Am I overlooking something?


--
You received this message because you are subscribed to the Google Groups "nanoc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nanoc+un...@googlegroups.com.

jmf...@gmail.com

unread,
Nov 27, 2025, 3:21:23 AM (yesterday) Nov 27
to nanoc
Thanks, I'll give that a try. Not sure why ChatGPT wasn't able to tell me that :-) 
Reply all
Reply to author
Forward
0 new messages