felangel / mason

Tools which allow developers to create and consume reusable templates called bricks.
https://docs.brickhub.dev
964 stars 98 forks source link

fix: Creating a filename with slash for conditional bricks variables #850

Closed OldMetalmind closed 1 year ago

OldMetalmind commented 1 year ago

Description

Creating a file name for a conditional brick variable, with a slash ( aka: forward slash, Solidus, /) is not possible in linux based OSs since it is a reserved character.

Steps To Reproduce

  1. Use MacOS
  2. Run bash touch {{#createChangelog}}CHANGELOG.md{{/createChangelog}};
  3. Error No such file or directory;

Expected Behavior

I should be able to create a conditional brick template file.

Screenshots N/A

Additional Context Maybe we can use a different special caracter for the closing mustache conditional? Given / is reserved.

This is useful when we want to create a conditional for the file name ( https://docs.brickhub.dev/brick-syntax#-conditionals ) however even if we escape the special character forward slash with a backslash, it gives out the error No such file or directory. I also tried to create the file directly through the IDE but without success

None of the following work:


touch {{#createChangelog}}CHANGELOG.md{{/createChangelog}}
-> : No such file or directory

touch {{#createChangelog}}CHANGELOG.md{{\/createChangelog}}
-> : No such file or directory

touch \{\{\#createChangelog\}\}CHANGELOG.md\{\{/createChangelog\}\}
-> : No such file or directory

touch "\{\{\#createChangelog\}\}CHANGELOG.md\{\{/createChangelog\}\}"
-> : No such file or directory
felangel commented 1 year ago

Hi @OldMetalmind πŸ‘‹ I believe this is a duplicate of https://github.com/felangel/mason/issues/751. Let me know if that helps πŸ‘

OldMetalmind commented 1 year ago

The following comment helped https://github.com/felangel/mason/issues/751#issuecomment-1439412564

I wasn't aware slash and backslash could both be used in the closing tag of the conditional in the file name. Just tried out and it works.

Maybe we should have a note in the documentation https://docs.brickhub.dev/brick-syntax#-conditionals stating that? I don't mind preparing a PR for that if you so wish.

Feel free to close this issue :v:

felangel commented 1 year ago

Glad that helped!

I wasn't aware slash and backslash could both be used in the closing tag of the conditional in the file name. Just tried out and it works. Maybe we should have a note in the documentation https://docs.brickhub.dev/brick-syntax#-conditionals stating that?

I don’t think it works universally on all platforms/os so I’m hesitant to update the docs to recommend it.

felangel commented 1 year ago

Closing for now but feel free to comment with any follow ups and I'm happy to continue the conversation πŸ‘