bullet-train-co / bullet_train-base

MIT License
10 stars 16 forks source link

Add error handling for unresolved partials, resolve partials with literal path strings #115

Closed gazayas closed 1 year ago

gazayas commented 2 years ago

Closes #114.

Error handling for unresolved partials

Whenever the partial resolver couldn't find the file passed by the developer, we would just get the partial resolver template itself:

app/views/bullet_train/partial_resolver.html.erb

Instead of just returning this string, I typed out a message telling the developer to make sure they have the package name in the string to help us resolve it for them, or they could use the --interactive flag and pass the annotated path (in case they weren't aware of it already).

Resolve partials with literal path strings

With that being said, if the developer passes the entire path starting from the package name, we can grab the package with the bundler so I added this feature to the script:

> bin/resolve bullet_train-themes-1.0.23/app/views/themes/base/attributes/_code.html.erb

Absolute path:
  /home/gazayas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bullet_train-themes-1.0.23/app/views/themes/base/attributes/_code.html.erb

Package name:
  bullet_train-themes-1.0.23

However, if it's something short like shared/attributes/_code.html.erb, then the script changes the string to shared/attributes/code and defaults to the behavior we already had in place for resolving the partial:

> bin/resolve shared/attributes/_code.html.erb

Absolute path:
  /home/gazayas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bullet_train-themes-1.0.23/app/views/themes/base/attributes/_code.html.erb

Package name:
  bullet_train-themes-1.0.23

Resolving shorthand partials

I added a TODO here because I set up things to resolve the shorthand string if it's made up of 3 parts or less, i.e.:

shared/attributes/code
OR
shared/box

I'm thinking we should have another way of determining these though. Should we flag them if they start with shared? Any other strings? I'm not sure about this part, but at I least wrote the TODO in case we need to handle it sooner than later.