#!/usr/bin/env ruby # Generates vorlagen-manifest.json in the given templates folder - lists all # .docx/.odt files found there so the methoden-set tool (methoden-set/, see # the Methoden-Set chapter on the project website) can offer them automatically as template choices, # including files someone copied manually straight onto the server (not # just the ones from this repo). Runs in the deploy hook AFTER the rsync of # methoden-set/ into the docroot (see the installation guide on the project website) and # therefore deliberately scans the docroot itself, not the git worktree - # rsync runs there without --delete, so manually added files survive # across deploys and show up here too. require 'json' verzeichnis = ARGV[0] or abort "Verwendung: #{$0} " dateien = Dir.glob(File.join(verzeichnis, '*.{docx,odt}')).map { |pfad| File.basename(pfad) }.sort # Derive the label from the filename (without extension, hyphens/ # underscores turned into spaces, each word capitalized) - no additional # metadata field to maintain, the filename itself is the only source. eintraege = dateien.map do |datei| format = File.extname(datei).delete_prefix('.') name = File.basename(datei, '.*') label = name.gsub(/[-_]+/, ' ').strip.split(' ').map { |w| w.empty? ? w : w[0].upcase + w[1..] }.join(' ') { 'datei' => datei, 'format' => format, 'label' => label } end File.write(File.join(verzeichnis, 'vorlagen-manifest.json'), JSON.pretty_generate(eintraege)) puts "vorlagen-manifest.json geschrieben: #{eintraege.length} Vorlage(n)"