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

Example source code in Previews #504

Closed
AlecRust opened this issue Oct 15, 2020 · 8 comments
Closed

Example source code in Previews #504

AlecRust opened this issue Oct 15, 2020 · 8 comments

Comments

@AlecRust
Copy link

Feature request

In our Styleguide I would like to display example source code under each component, so it's quick and easy for other developers to understand how to use a component or one particular variant of a component.

Have you considered providing a helper method for this, or building it in to the Previews feature?

e.g. such a helper could output a string containing the contents of the associated method in:

test/components/previews/address_component_preview.rb

Or if the example was in a view file, it would output the contents of:

test/components/previews/address_component_preview/default.html.erb

This could then be used in a <pre> underneath the rendered version of each component preview.

Motivation

Every so often I revisit migrating our home-grown component styleguide over to view_component Previews. With recent developments I'm now close to taking the plunge but this is one hurdle that seems like it might be suited to being provided by this gem.

Here's an example of what we're currently doing:

screenshot

@joelhawksley
Copy link
Member

@AlecRust this is lovely! I'd love to see us provide something like this for ViewComponent. Would you like to pair on it? If so, send me an email: joelhawksley@github.com ❤️

@allmarkedup
Copy link
Contributor

@AlecRust We are currently doing this with ViewComponent using a patched version of the Method source gem. The patch is literally just to change one line to remove file caching - our fork is here: https://github.com/allmarkedup/method_source

Still a work in progress but it look like this:

Screenshot 2020-10-18 at 10 06 12

It's not perfect because often I find the rendering for the preview might use a few helpers for generating dummy data that I wouldn't use in a real-world example. So the next iteration will also hopefully have support for pulling in code examples from method-related comments in the preview files (or possibly the component files themselves) - something which should also be possible using that method source gem, I believe.

Of course I'd love if something like this was natively supported in ViewComponent but just a heads up that you can still hack it in there if you need it :-)

@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 25, 2020
@joelhawksley
Copy link
Member

@AlecRust @allmarkedup I'd love to see this added to ViewComponent if either of you'd be interested in taking it on!

@johannesengl
Copy link
Contributor

@joelhawksley Happy to help out on this one. What would be the best way to approach this? Should we quickly sync to refine the requirements for this feature?

@joelhawksley
Copy link
Member

@johannesengl sure thing! Email me: joelhawksley@github.com

@johannesengl
Copy link
Contributor

Created a first draft pr for this #667 which is still work in progress.

@johannesengl
Copy link
Contributor

The PR got merged. @Spone @joelhawksley Should we close this issue?

@Spone Spone closed this as completed Jun 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants