-
Notifications
You must be signed in to change notification settings - Fork 405
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
Conversation
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.
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. |
I read through the docs and noticed one more thing:
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...
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. |
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.
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++) { |
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.
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]); |
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.
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; |
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.
I have no idea what that JSON.parse is doing in there.
pattern.patternExtension
suffices.
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.
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.
@bmuenzenmeyer Sure thing. Thanks for the review, I'll look at it as soon as I have a chance. |
@jwir3 how is it going? Any chance this work could be picked back up - or would you like me to take the baton? |
@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. |
hello @jwir3 - still interested in finishing this? Just let me know if you would like me to pick it up |
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. |
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. |
@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! |
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! |
@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! |
1005 days later.... this is good work @jwir3 - glad it will finally see the light of day! |
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:
Summary of changes:
patternlab-config.json
.patternlab-config.json
.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).