Skip to content

Commit

Permalink
Filename override via -O command-line option (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
edemaine committed Sep 20, 2022
1 parent a0fca2c commit 61ad1d7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,9 @@ that SVG Tiler also accepts:
* You can change where to put converted files via the
`--op`/`--output-pdf` and `--oP`/`--output-png` command-line options.
In addition, SVG Tiler supports `--os`/`--output-svg` to control where
to put generated SVG files, and `-o`/`--output` to control the default
place to put all generated/converted files.
to put generated SVG files, `-o`/`--output` to control the default
place to put all generated/converted files, and `-O`/`--output-stem`
to override the generated/converted filenames for the next drawing.
* If Inkscape isn't on your PATH, you can specify its location via
`-i`/`--inkscape`.

Expand Down Expand Up @@ -736,6 +737,7 @@ Optional arguments:
-t / --tex Move <text> from SVG to accompanying LaTeX file.svg_tex
-f / --force Force SVG/TeX/PDF/PNG creation even if deps older
-o DIR / --output DIR Write all output files to directory DIR
-O STEM / --output-stem STEM Write next output to STEM.{svg,svg_tex,pdf,png}
--os DIR / --output-svg DIR Write all .svg files to directory DIR
--op DIR / --output-pdf DIR Write all .pdf files to directory DIR
--oP DIR / --output-png DIR Write all .png files to directory DIR
Expand Down
16 changes: 4 additions & 12 deletions examples/mario/Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
all: castle underground underwater overworld

castle:
svgtiler -f -P palette_castle.js mario.coffee door.tsv
mv door.svg door_castle.svg
mv door.png door_castle.png
svgtiler -f -P palette_castle.js -O door_castle mario.coffee door.tsv

overworld:
svgtiler -f -P palette_overworld.js mario.coffee door.tsv
mv door.svg door_overworld.svg
mv door.png door_overworld.png
svgtiler -f -P palette_overworld.js -O door_overworld mario.coffee door.tsv

underground:
svgtiler -f -P palette_underground.js mario.coffee door.tsv
mv door.svg door_underground.svg
mv door.png door_underground.png
svgtiler -f -P palette_underground.js -O door_underground mario.coffee door.tsv

underwater:
svgtiler -f -P palette_underwater.js mario.coffee door.tsv
mv door.svg door_underwater.svg
mv door.png door_underwater.png
svgtiler -f -P palette_underwater.js -O door_underwater mario.coffee door.tsv
13 changes: 12 additions & 1 deletion src/svgtiler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ defaultSettings =
keepHidden: false
## Don't delete blank extreme rows/columns.
keepMargins: false
## Override for output file's stem (basename without extension).
outputStem: null
## Directories to output all or some files.
## Can also include stem overrides like "prefix_*_suffix".
outputDir: null ## default: same directory as input
outputDirExt: ## by extension; default is to use outputDir
'.svg': null
Expand Down Expand Up @@ -785,7 +788,9 @@ class Input extends HasSettings
filenameSeparator: '_'
generateFilename: (ext, filename = @filename, subname = @subname) ->
filename = path.parse filename
delete filename.base
delete filename.base # force generation from filename.name & filename.ext
if (outputStem = @getSetting 'outputStem')?
filename.name = outputStem
if subname
filename.name += (@filenameSeparator ? '') + subname
if filename.ext == ext
Expand Down Expand Up @@ -1773,6 +1778,7 @@ Optional arguments:
-t / --tex Move <text> from SVG to accompanying LaTeX file.svg_tex
-f / --force Force SVG/TeX/PDF/PNG creation even if deps older
-o DIR / --output DIR Write all output files to directory DIR
-O STEM / --output-stem STEM Write next output to STEM.{svg,svg_tex,pdf,png}
--os DIR / --output-svg DIR Write all .svg files to directory DIR
--op DIR / --output-pdf DIR Write all .pdf files to directory DIR
--oP DIR / --output-png DIR Write all .png files to directory DIR
Expand Down Expand Up @@ -1876,6 +1882,9 @@ main = (args = process.argv[2..]) ->
when '-o', '--output'
skip = 1
settings.outputDir = args[i+1]
when '-O', '--output-stem'
skip = 1
settings.outputStem = args[i+1]
when '--os', '--output-svg'
skip = 1
settings.outputDirExt['.svg'] = args[i+1]
Expand Down Expand Up @@ -1924,6 +1933,8 @@ main = (args = process.argv[2..]) ->
## change, we may not have done these conversions before or in the
## last run of SVG Tiler, so let svgink compare mod times and decide.
convert filenames, formats, settings
## Reset -O output filename stem override.
settings.outputStem = null
else if input instanceof SVGFile
convert input.filename, formats, settings
unless files
Expand Down

0 comments on commit 61ad1d7

Please sign in to comment.