Skip to content

Add pattern export all #601

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

Merged
merged 3 commits into from
Oct 29, 2019
Merged

Conversation

jwir3
Copy link
Contributor

@jwir3 jwir3 commented Jan 28, 2017

Use Case: We use pattern-lab to create a rough design, then export all of our styles and patterns to a rails web application. This PR seeks to make the export more user-friendly by:

  1. Allowing us to export raw patterns (.mustache files) which can be interpreted by the ruby mustache template engine.
  2. Preserving directory structure of our atoms/molecules/etc... such that we don't have too much directory hierarchy, but one level deeper than just a flat directory structure.
  3. Allowing us to easily specify that we want all patterns to be exported, rather than having to manually specify each one (as our designs are in flux constantly right now, and there are many changes).

Summary of changes:

  • Add capability to export all patterns via a flag in patternlab-config.json.
  • Add capability to preserve rough directory structure via a flag in patternlab-config.json.
  • Add capability to export raw patterns via flag in patternlab-config.json.

Note: This is a sort of rough start to a PR. I don't expect that it's going to be approved initially, but rather it's more of a starting point. It doesn't conform to the pattern-lab spec, although, I do know PHP, and would be willing to change the pattern-lab PHP code as well as the node code (node just happens to be what we use right now), but I'm not 100% sure how to go about adding this to the spec. Typically, a proof-of-concept/starting-point implementation tends to be required before modifying a specification, anyway, so this should serve as that. (This is the reason the documentation for the new flags added in patternlab-config.json wasn't added).

jwir3 added 3 commits January 27, 2017 19:22
Instead of prefixing patterns with "<category>-", we prefix the directory
path with "<category>/".
Exporting "raw" patterns means that the export task is little more than a
wrapper around a more condensed file naming method. Instead of outputting
rendered HTML, the exporter outputs the raw patterns, augmented to remove
any superfluous directory structure and prefixed ordering.
@bmuenzenmeyer bmuenzenmeyer self-requested a review January 30, 2017 02:27
@bmuenzenmeyer
Copy link
Member

First off - thank you SO much for your contribution. I greatly appreciate a thoughtful, thorough PR and look forward to working with y'all.

I am starting a review of this by comparing functionality against my build of PL PHP. Stay tuned.

@bmuenzenmeyer
Copy link
Member

bmuenzenmeyer commented Jan 30, 2017

A short while later...

It looks like export in PHP does the following, and is considered current spec:

  • exports patterns/ preserving the file structure of the patterns
  • exported patterns represent their finished - rendered, compiled HTML
  • exports most of the contents of source
    image
  • If you require your patterns to be exported without your global header and footer (e.g. to export a clean molecule) do the following... (see next comment)

So to me, that's the baseline we need to shoot for or address.

  • exports patterns/ preserving the file structure of the patterns

I think your flag covers the spirit of that feature, and feedback from the community can further determine if it needs to support pattern subgroup too. My thought would be most individuals would move them around to their liking in a production scenarion anyways.

  • exported patterns represent their finished - rendered, compiled HTML

Again, your flag covers this, and then some. Users can choose their own adventure with either raw or rendered patterns.

  • exports most of the contents of source

I am going to make a decsion say that this is not important. Modern toolchains make the copying of css/js/images/fonts from source/ to public/ or export/ trivial. PL doesn't need to do this in my opinion. Longterm, PL is going to get out of the business of moving assets around too much.

So, that being said, I am going to give this a 👍 conceptually, and it's a welcome addition to the capabilities of the library.

I will do some testing and then conduct a more formal review.

@bmuenzenmeyer bmuenzenmeyer self-assigned this Jan 30, 2017
@bmuenzenmeyer
Copy link
Member

bmuenzenmeyer commented Jan 30, 2017

I read through the docs and noticed one more thing:

  • If you require your patterns to be exported without your global header and footer (e.g. to export a clean molecule) do the following...

This will be something to strive for. Doing this will require either some ugly regex/substring work, a different core codepath, or something more creative. I will add it to the above. I still don't see this stopping the PR, as it's a step in the right direction.

I wonder then...

Allowing us to export raw patterns (.mustache files) which can be interpreted by the ruby mustache template engine.

Are you removing this somehow yourself?

EDIT Nevermind, I found out myself. With the current PR, the global head and foot are excluded. I suppose we could add another flag to include if a user wished. Might as well wait for feedback on that first.

Copy link
Member

@bmuenzenmeyer bmuenzenmeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments which need to be addressed.

It would also be nice if this had some unit test coverage - but that's just extra credit.

}

return;
}

//find the chosen patterns to export
for (var i = 0; i < exportPartials.length; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot think of a need to loop through a provided array if the user has chosen to export all. I suggest making these mutually exclusive. Should be simple to add this as an else block as part of the exportAll check

if (exportAll) {
for (var i = 0; i < patternlab.patterns.length; i++) {
if (!patternlab.patterns[i].patternPartial.startsWith('-')) {
exportSinglePattern(patternlab, patternlab.patterns[i]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest adding a check for to make sure patternlab.patterns[i].isPattern === true before calling exportSinglePattern() to avoid having the meta head and meta foot from being exported.


if (patternlab.config.patternExportRaw) {
patternCode = pattern.extendedTemplate;
patternFileExtension = "." + JSON.parse(pattern.patternData).patternExtension;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what that JSON.parse is doing in there.

pattern.patternExtension suffices.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no pattern.patternExtension - "patternExtension" only lives within pattern.patternData - which does seem lto be a stringified JSON object (hence the parse @jwir3 added).

We do have a pattern.fileExtension available (which shows up with the period in it, such as .hbs. I'm guessing we could use this to clean it up, but I'm not sure to why we have this difference between fileExtension and patternExtension, and why patternExtension is only available in that weird string JSON patternData.

@jwir3
Copy link
Contributor Author

jwir3 commented Feb 18, 2017

@bmuenzenmeyer Sure thing. Thanks for the review, I'll look at it as soon as I have a chance.

@stale stale bot closed this Oct 2, 2017
@bmuenzenmeyer bmuenzenmeyer reopened this Oct 2, 2017
@stale stale bot removed the needs response label Oct 2, 2017
@bmuenzenmeyer
Copy link
Member

@jwir3 how is it going? Any chance this work could be picked back up - or would you like me to take the baton?

@jwir3
Copy link
Contributor Author

jwir3 commented Oct 2, 2017

@bmuenzenmeyer My apologies. I got distracted and forgot about this. I should have some time this week to finish this up. I'll get it to a point we discussed. Sorry for the delay.

@bmuenzenmeyer
Copy link
Member

hello @jwir3 - still interested in finishing this? Just let me know if you would like me to pick it up

@stale
Copy link

stale bot commented Jan 14, 2018

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 needs response label Jan 14, 2018
@stale stale bot closed this Jan 21, 2018
@bmuenzenmeyer bmuenzenmeyer reopened this Jan 22, 2018
@stale stale bot removed the needs response label Jan 22, 2018
@bmuenzenmeyer bmuenzenmeyer added the pinned 📌 Don't let stalebot clean this up label Jan 22, 2018
@J-Gonzalez
Copy link

This PR allows us to actually export our handlebars templates in a smart fashion that allows them to be consumable by our applications in the same way they are used within PL. The directory structure works perfectly in allowing us to register all of our partials and add the directory name in order to mimic the naming structure used in PL ("atoms-button" or "molecules-card").

I think this approach (or something similar) would work great when thinking about #834 as it gives us a path towards exporting partials in the same way they are documented in PL.

@bmuenzenmeyer
Copy link
Member

@J-Gonzalez thanks for the feedback. This PR remains important to me, but it's been waiting on response from the OP for a bit. I will likely take up the comments soon to get it into the codebase proper.

Glad its of value to you!

@bmuenzenmeyer bmuenzenmeyer self-assigned this Aug 21, 2018
@jwir3
Copy link
Contributor Author

jwir3 commented Aug 21, 2018

Yeah, I'm really sorry. I've been remiss in keeping this up to date. I just don't think I have the time to spend on it to really push it over the finish line. I would appreciate any help you guys could give!

@bmuenzenmeyer
Copy link
Member

@jwir3 no worries. believe me, I understand we all operate at the speed of open source (make what you will of that).

Your initial work is already of value, and it's good to hear from you again!

@bmuenzenmeyer bmuenzenmeyer merged commit 436dd99 into pattern-lab:dev Oct 29, 2019
@bmuenzenmeyer
Copy link
Member

1005 days later....

this is good work @jwir3 - glad it will finally see the light of day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pinned 📌 Don't let stalebot clean this up
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants