-
Notifications
You must be signed in to change notification settings - Fork 485
Add Url helpers to previews #1765
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
Add Url helpers to previews #1765
Conversation
joelhawksley
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏🏻
|
|
||
| *Pasha Kalashnikov* | ||
|
|
||
| * Add URL helpers to previews |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Add URL helpers to previews | |
| * Add support for URL helpers to previews. |
|
Brilliant! Thanks for the clean PR ❤️ |
|
This change is causing me a bit of a headache when trying to use ViewComponent outside of Rails, specifically for building the guide for GOV.UK Components. See this PR. |
|
I think we can rework this to only include the helpers if |
A recent change to ViewComponent[0] makes it call Rails.application.routes.url_helpers which, until now, didn't exist. We can initialize a fake Rails application so it's at least present, despite being totally empty, which will allow the guide build to function. We're very much in the minority in terms of how we're building this guide Rails-free, so it's on us to make it work. [0] ViewComponent/view_component#1765
A recent change to ViewComponent[0] makes it call Rails.application.routes.url_helpers which, until now, didn't exist. We can initialize a fake Rails application so it's at least present, despite being totally empty, which will allow the guide build to function. We're very much in the minority in terms of how we're building this guide Rails-free, so it's on us to make it work. [0] ViewComponent/view_component#1765
|
Actually the fix isn't too bad - less involved than I thought half an hour ago! I totally realise we're using ViewComponent in a really unintended way to build the our guide so am happy to work around this on our end. Simply initialising a fake Rails app before kicking off the Nanoc build works for us. Consider this not a problem, thank you @Spone and @reeganviljoen :) |
|
This seems to have broken the I had to comment out the We could change the task to work around this, but I think @Spone's suggested approach of only including the helpers when inside a Rails application makes sense. |
|
I've opened a PR to do so here: #1795 |
* added url helpers to previews * updated changelog * fixed lint errors * fixed lint errors * fixed lint errors * fixed lint errors
* added url helpers to previews * updated changelog * fixed lint errors * fixed lint errors * fixed lint errors * fixed lint errors
closes #1764
What are you trying to accomplish?
Add Rails Url helpers to previews, for instance, if resources :items is defined in routes.rb, I may want to use items_path in the component preview method
What approach did you choose and why?
I added
include Rails.application.routes.url_helperstopreview.rbto add the helpers to the previews classA similar way to achieve this is by using the preview template which will have the URL helpers loaded but that seems like overkill just to get access to a helper
Anything you want to highlight for special attention from reviewers?