-
Notifications
You must be signed in to change notification settings - Fork 26
Use partial and content_for to wrap components in style guide #88
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
0155f14
14c3ac2
15dbc51
aa09f5a
c545a5c
619f132
5ab322d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,7 +247,7 @@ To customize the styleguide, override the style guide layout by adding `mountain | |
|
|
||
| ### Custom meta data for stub examples | ||
|
|
||
| You can customize the title, description for each example in the stub, as well as the classes that surround the stub example. In order to override the default title, add a `title` key to the `mv_stub_meta` hash. Additional special keys include `description` which will add a description under the title for a given example and `classes` which will add classes for a specific example. | ||
| You can customize the title, description for each example in the stub, as well as the classes that surround the stub example. In order to override the default title, add a `title` key to the `mv_stub_meta` hash. Additional special keys include `description` which will add a description under the title for a given example, `classes` which will add classes for a specific example, and `partial` which will allow ou to embed the component in a partial (see below for details). | ||
|
|
||
| E.g: `app/components/card/card.yml` | ||
| ```yml | ||
|
|
@@ -256,6 +256,7 @@ E.g: `app/components/card/card.yml` | |
| :title: "Specific Example" | ||
| :description: "Instructions for use case or other UX considerations" | ||
| :classes: "black-background" | ||
| :partial: "card/card_styleguide_partial.html.erb" | ||
| :title: "Aspen Snowmass" | ||
| :description: "Aspen Snowmass is a winter resort complex located in Pitkin County in western Colorado in the United States. Owned and operated by the Aspen Skiing Company it comprises four skiing/snowboarding areas on four adjacent mountains in the vicinity of the towns of Aspen and Snowmass Village." | ||
| :link: "http://google.com" | ||
|
|
@@ -268,7 +269,11 @@ E.g: `app/components/card/card.yml` | |
| :title: "Depth" | ||
| :number: '71"' | ||
| ``` | ||
| ### Wrapping Components in the Style Guide | ||
|
|
||
| Sometimes you may want to wrap extra content around the component in the style guide. For example, you may want to include a form tag around a custom form component without including the form tag in the component itself. You can do this by adding the key `partial` in the `mv_stub_meta`. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be rewritten |
||
|
|
||
| To include the component in the partial, you reference `<%= content_for :"#{mv_content_for_name}" %>` | ||
|
|
||
| ## Improving performance | ||
| Rendering a large amount of partials in a request can lead to a performance bottleneck, usually this is caused by the parsing and rendering of template code such as ERB or HAML. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,14 @@ | |
| <h2><%= component_stub.meta_title(@component.title, index) %></h2> | ||
| <div class="mv-component"> | ||
| <div class="mv-component__item <%= component_stub.meta_classes %>"> | ||
| <%= render_component @component.name, component_stub.properties.clone %> | ||
| <% if component_stub.meta_partial.blank? %> | ||
| <%= render_component @component.name, component_stub.properties.clone %> | ||
| <% else %> | ||
| <% content_for_name = "mv_#{@component.name}_#{index}" %> | ||
| <% content_for :"#{content_for_name}", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could theoretically use a layout with yield as well... for some reason I can't use a block though... my server crashes if I use a block with content_for or render layout...
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting... Yes, that would look much better, IMO. Passing a Ideally this would be something like: And we could generalize it more if we returned an empty partial (with just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that idea a lot... but I have to figure out why using the render with a block, as above, causes the server to crash. Have you heard anything about that? I lean toward blaming windows :/ But it probably needs to work on windows, so I'd have to figure it out.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't heard anything about that :( |
||
| render_component(@component.name, component_stub.properties.clone) %> | ||
| <%= render component_stub.meta_partial, mv_content_for_name: content_for_name %> | ||
| <% end %> | ||
| </div> | ||
| <div class="mv-component__description"> | ||
| <h3><%= t('mountain_view.show.instruction_heading') %></h3> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,5 +25,9 @@ def meta_description | |
| def meta_classes | ||
| @meta[:classes] | ||
| end | ||
|
|
||
| def meta_partial | ||
| @meta[:partial] | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <div class="test_partial" style="background-color: pink"> | ||
| Custom Partial around style use | ||
| <%= content_for :"#{mv_content_for_name}" %> | ||
| </div> |
Uh oh!
There was an error while loading. Please reload this page.