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

Access helpers in examples #135

Open
4 tasks
hagenburger opened this issue May 10, 2015 · 7 comments
Open
4 tasks

Access helpers in examples #135

hagenburger opened this issue May 10, 2015 · 7 comments

Comments

@hagenburger
Copy link
Member

hagenburger commented May 10, 2015

Allow to add helper methods to style guide examples.

Example usage

app/helpers/form_helper.rb:

module FormHelper
  def primary_button(text, type: "button")
    content_tag(:button, text, class: "button primary", type: type)
  end
end

app/assets/index.html.lsg

@helpers FormHelper

```
@type erb
<form>
  <%= primary_button("Submit", type: "submit") %>
</form>
```

Same example using Haml:

@helpers FormHelper

```
@haml
%form
   = primary_button("Submit", type: "submit")
```

Implementation

  • If FormHelper is defined, it should load it into the scope of examples.
  • If FormHelper is not defined, it should try to require a form_helper.rb first.
  • It must be possible to load helpers globally, within a page, and within an example (by putting @helpers FormHelper into the corresponding place)

It might be useful to provide a way to load all helpers defined in a Rails application. This should not be done by default as some helpers might have dependencies that conflict in the style guide. As @myabc mentioned in the comments, this should be done in a separate Gem (livingstyleguide-rails). Using @helpers should not be limited to Rails environments.

Middleman provides a similar way to load helpers. It would be nice if this would automatically make them available to LivingStyleGuide examples.

Tasks

  • Implement loading of helpers
  • Require files if helpers are not defined
  • Add app/helpers to the load path if Rails is defined
  • Include helpers in Middleman
@hagenburger
Copy link
Member Author

Also for @head/@header/@footer

@myabc
Copy link
Member

myabc commented Aug 17, 2015

This is a nice-to-have feature, but should probably live in a separate livingstyleguide-rails project.

@hagenburger
Copy link
Member Author

I would like to do the split in into several Gems for v3.

@hagenburger hagenburger changed the title Access Rails helpers in examples Access helpers in examples Sep 28, 2016
@fredrivett
Copy link

+1 for this.

In rails a lot of the components we develop use helper methods so this would enable marrying up the actual implementation that we recommend with what's in the styleguide, rather than having to paste a helper methods output.

For example, we're using the inline_svg gem, and instead of one line of code, we currently have to paste the whole SVG output straight into the LSG header.

@hagenburger
Copy link
Member Author

As I’m not using Rails myself right now, I’m happy to accept contributions here. Also for version 3 the core will be written in JavaScript. It might be good to implement this on top of it.

@fredrivett
Copy link

Thanks for the swift reply @hagenburger. I'm not a Rails dev myself, stick to the front end, so might not be well placed to implement this. May be able to contribute on the front end, depending on what I've got on at the time.

@hagenburger
Copy link
Member Author

All fine, let me know if you want to help out. Feel free to join our Slack channel: https://join.slack.com/t/livingstyleguide/shared_invite/enQtMzA5NDkyOTQ0NjI2LWM0YWU5OWIxOTJhZjZjZTNjNDRiNjE0MTUwOWM4MDM2OTkwYjI0NTljZDdjYjg1NjVjZTk3NjlmMDgzYzBiZGY

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

3 participants