-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
PatternEngines: support multiple template engines, v2 #191
PatternEngines: support multiple template engines, v2 #191
Conversation
dependence on pattern engines
object. The pattern_engines module returns an instance, but I now realize that this is a terrible idea.
Conflicts: builder/object_factory.js builder/pattern_assembler.js builder/pseudopattern_hunter.js
…rototype in the ES5 Object.create style
time that powers a real implementation of getEngineNameForPattern!
…pattern-engines Conflicts: builder/object_factory.js builder/parameter_hunter.js builder/pattern_assembler.js builder/patternlab.js
don't render at all, and are missing in the menu. The quest continues...
Thanks @geoffp will try to look at this soon! |
Hi @geoffp I am going to look at this next, specifically to have this as part of 1.0 or to kick off a post 1.0 world. Can you make sure the TODO list above it up to date? console logs are fine as they might be helpful to me yet. |
Sure thing. I made some more progress factoring out mustache-specific regexes and beefed up a bunch of unit tests yesterday that I'll be checking in today. Here's how it's shaking out: This architecture depends on oPattern objects getting smart about what kind of template they are, so an oPattern figures out when its get created what PatternEngine it needs to be able to render itself, based on file extension, then goes and looks for a PatternEngine plugin that reports that it handles that file extension. If it finds one, it retains a reference to that plugin. Methods on the oPattern's prototype (findPartials, findPartialsWithStyleModifiers, etc.) then delegate to functions provided by the pattern engine. The overall goal of this is that the bulk of the application doesn't need to care what the backing PatternEngine is; oPattern provides a uniform API and delegates functionality to the appropriate plugin. There are multiple "safeties" that fall back to Mustache in the event that anything gets weird or is unaccounted for. I expect that as the gaps start to close we won't need those much anymore, but it helps with the transition. |
@geoffp and @bmuenzenmeyer For what it's worth, I'm also checking this out right now to see how straightforward it's going to be to add in new rendering engines (like Twig) with this direction you guys are heading. Already got a good bit of experience dealing with the new PL2 setup so I'm just reviewing to see how I might be able to help out with this as well. |
Right on. I'll push the latest after lunch so you can review. I think I only have a couple list item hunter unit tests left to fix up before I pass again. |
Also note - I keep updating As of right now I see this PR as out of scope for a v1.0.0 release but I'd love to see it there! |
I'll pull the latest dev and see what's what. I wouldn't want to rush this work or gloss over consensus just to get into Question: am I right in thinking that pattern parameters are essentially an On Wed, Nov 25, 2015 at 12:06 PM Brian Muenzenmeyer <
|
cc @ajfuller |
@geoffp Yes patternParameters and styleModifiers are really extensions/hacks/patternlab-special-sauce applied before vanilla mustache parsing. As long a templating engine supports variables, a plugin for that language should be able to support pattern parameters that make since for them. Handlebars is obvious (I think) since it's relationship to mustache
Twig (before mentioned) seems to have this too, but with more flavor:
Thinking about this quickly, I agree that the mustache plugin should be responsible for how to parse these, as it wouldn't know what to do with I am also in agreement that this shouldn't be rushed into 1.0.0 - 1.0.0 as it currently stands is not too far off, and getting pattern engines fully baked and tested requires robust thought. I really, REALLY, REALLY appreciate everyone's bandwidth on this. Cannot emphasize enough how energizing it is 🚀 |
Naive git question, should I accept this PR so others can work on it easier, or can everyone just as effectively add a remote to |
I'm fine either or, so long as we can keep track where the latest patternengine code is living (although merging the PR into this branch would probably make the most sense using the Git Flow model of feature development). Small update from my end: I'm still working out some bugs (like why the lineage logic isn't showing up) but just wanted to mention that using @geoffp's "old" code from about a week ago, I was able to get a few test twig templates to render properly! Still lots of work to do but things are looking really promising. |
Yeah, that makes perfect sense. That's what it looked like from reading the code, so it's good to confirm. That also explains the oPattern.template/oPattern.extendedTemplate split. So then, the .extendedTemplate copy is the Mustache with all of that secret sauce sort of desugared and ready to be passed to the Mustache renderer? I'm not sure what the best Git thing to do is. If people clone my geoffp:pattern-engines, then I think they'd be submitting pull requests to me, and then I'd periodically send them to you. I think if you give me push access (if you're comfortable with that) this repo/branch can be the main line of development, and anyone else who wants to contribute can submit pull requests against this branch. There would just need to be an understanding that I never push to anything but feature branches, and you're the guy in the middle who merges PRs. |
oPatterns that delegate to PatternEngines. Remove requests to the pattern_assembler functions from hunters and replace them with calls to methods on oPattern. Also add new factory methods for oPatterns to be able to produce empty oPatterns and oPatterns with custom contents, which is useful both for unit testing and other internal use. This helps to cut down on usage of "bare" mustache strings.
faking oPatterns with incomplete object literals. This is a nice way to do it because it gives us a more accurate model of what happens at runtime, but also because we now really need oPatterns to be able to detect PatternEngines based on their file extensions for accurate testing.
@sghoweri that's awesome! I just checked in the code that "should" make stuff like lineage work, though I haven't fully tested it. But it's much closer to complete, and I'm passing all the unit tests, including some new ones, except for the list item hunter stuff, which looks like it's going to be tricky (seems tightly coupled to Mustache). All the regexes that hunt for that stuff are factored out into the Mustache plugin. I see no problem with merging the pull request and going from there, except for the fact that this PR is a nice place to talk. But there's always another PR. |
I am in favor of merging. Will do so after this comment. I like the notion of attempt to push smaller changes to this branch during development. I am also super pumped that you are all interested in unit tests. These came later in the total port process and that's why not everything is well structured for them - some, especially in pattern_assembler, are more akin to integration tests, but useful nonetheless. If you could keep in mind any coverage you are adding against this list please let me know!
I did this to keep the template a pristine copy of actual file contents, and then in the case of templates with partials, the extendedTemplate is a place that "unfurls" or glues everything together before one big render. It seemed like the best way to negotiate some of the data.son and pattern.json requirements that are inherent in pattern lab functionality - but does make some things interesting indeed. Let me know if this doesn't make sense. |
PatternEngines: support multiple template engines, v2
No, that makes total sense; I probably would have done it the same way. Though, I remember some parts of the code that depend explicitly on extendedTemplate, and I can't remember if all patterns are guaranteed to have an extendedTemplate. I think they are. One more question: the list item hunter is a challenge -- it seems pretty bound up with Mustache syntax, and I'm not 100% clear on what the syntax is right now, or what it should be in other template engines. What do you think about that? |
To my knowledge all patterns should have an extendedTemplate, even if it's just a straight copy of the template, for consistency's sake. This is most prominently illustrated here: patternlab-node/builder/pattern_assembler.js Line 191 in e8f060f
where the template is copied to the specific instance of the pattern (before anything else really happens) so it may start anew and not be tainted by previous runs of the partial.
http://patternlab.io/docs/data-listitems.html is the authoritative resource on how these function as far as I am concerned, and it was quite the challenge for me to create this (probably my own failing). I did it in isolation and my best interpretation of what Dave did over in PHP. These are, perhaps, the biggest of the extensions or pre-parsings of mustache, as we scrape the template for a listitem string, and then copy the contents N number of times into the extended template. I could see both the implementation and the syntax being flexible (even across engines), as long as we can do something approachable to users of each template syntax and hopefully read the same |
PatternEngines: support multiple template engines, v2
PatternEngines: support multiple template engines, v2
PatternEngines: support multiple template engines, v2
PatternEngines: support multiple template engines, v2
PatternEngines: support multiple template engines, v2
PatternEngines: support multiple template engines, v2
NOT READY FOR MERGE YET, this PR is only for review.
Hey, @bmuenzenmeyer -- this one is merged and up to date as of the time you created the pattern-engines branch, which this PR is pointed at. It should merge, build, and it passes all the tests now, though it silently fails to build pseudo-patterns. I'm looking in to that today.
Once again -- there's kind of a lot here, and it's WIP, so if there's anything I can do to make this more reviewable, let me know.
TODO:
Generate pseudo-patternsfinders in pattern_assemblerMigrate unit tests to use "real" instantiated oPatternsMachinery to create empty/custom oPatterns programaticallyReplace object-literal fake oPatterns in unit tests with real oPatterns