Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Input or SymLinks #81

Open
Shikakka opened this issue Mar 23, 2024 · 2 comments
Open

File Input or SymLinks #81

Shikakka opened this issue Mar 23, 2024 · 2 comments
Assignees

Comments

@Shikakka
Copy link

Thanks for making this library!
I previously used Spritezero in Javascript. Not the Spritezero-CLI version.

Here I could input a list of files instead of pointing to a folder.
Would it be possible to implement something like this?

I probably have a weird use case, where I can upload to 3 different folders, for example:
/sprites/public
/sprites/version-a
/sprites/version-a/part-b

where I want to generate a spritesheet for part-b, but including the sprites in public and version-a.
But not including /sprites/version-a/part-a.

I tried to use Symbolic Links to create a new directory first /sprites/temp then create symbolic links to all .svgs.
They work in other programs correctly.

But this gives me the error:

Error: cannot make a valid sprite name from "/sprites/temp/new-sprite.svg"

When i copy the files to the same folder, so no symlinks, they work correctly.

@Shikakka
Copy link
Author

It would very much be a "nice to have" for now I just copy the files.
What another option would be is input multiple folders.

Something like a comma seperation:

spreet --retina /sprites/public,/sprites/version-a,/sprites/version-a/part-b my_style@2x

But again it is a "nice to have" but probably not in scope of this project because of this very uncommon usecase.

flother added a commit that referenced this issue Aug 23, 2024
This addresses an issue creating valid sprite names for symlinks, as
detailed in issue #81. Symlinked files were being canonicalised, which
caused a problem if the target was outside the base path. This change
replaces the canonicalisation step with `std::path::absolute()`, which
doesn't resolve symlinks and so they remain within the base path.

The change has two side-effects:

- It allows sprite names to be generated for non-existent files (a good
  thing, since there's no need for names to be linked to the
  filesystem)
- It modifies the `spreet::sprite_name()` function to return a
  `PathError` instead of an `IoError` when the `abs_path` argument is
  not an ancestor of the `path` argument.

Use of `std::path::absolute()` means the minimum supported Rust version
(MSRV) is now 1.74.
@flother flother self-assigned this Aug 23, 2024
@flother
Copy link
Owner

flother commented Aug 23, 2024

Sorry for the slow reply, I haven’t had a chance to look at Spreet for a while.

I previously used Spritezero in Javascript. Not the Spritezero-CLI version.

Here I could input a list of files instead of pointing to a folder.
Would it be possible to implement something like this?

If it helps, Spreet can be used as a library too, just as Spritezero can — but of course you need to write Rust rather than JavaScript. If that’s something you’re comfortable with then it’s quite possible to build a spritesheet from SVGs spread across multiple directories. You can use the same pattern as Spreet itself does (start with the code, for example).

I tried to use Symbolic Links to create a new directory first /sprites/temp then create symbolic links to all .svgs.
They work in other programs correctly.

But this gives me the error:

Error: cannot make a valid sprite name from "/sprites/temp/new-sprite.svg"

Oops! This is a bug. It should definitely be possible to use symlinked files. I’ve fixed this in 014ce64 and I’ll include it in the upcoming 0.12.0 release.

What another option would be is input multiple folders.

I’ve been thinking about this, and I think an interesting generic solution would be for Spreet to support using a config file. I like the idea of having a TOML file that would allow you to define multiple spritesheets that could be generated in one go. Hypothetically, something like:

[[sheets]]
ratio = 1
unique = true
minify-index-file = false
sprites = ["sprites/public", "sprites/version-a", "sprites/version-a/part-b"]
output = "[email protected]"

[[sheets]]
ratio = 2
unique = true
minify-index-file = false
sprites = ["sprites/public", "sprites/version-a", "sprites/version-a/part-b"]
output = "[email protected]"

Then you could perhaps run Spreet like:

spreet --config sprites.toml

But that’s for another time 😄. Until then, I hope 014ce64 fixes your immediate problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants