GithubHelp home page GithubHelp logo

Comments (12)

tylersticka avatar tylersticka commented on May 20, 2024 1

basically I may end up writing my own styleguide generator tool from scratch

That's how we ended up making Drizzle (forked Fabricator)!

Our team welcomes contributions and collaborations. If you have ideas, proposals or wish to discuss some aspect of the hack/fork/project you're working on to see if your ideas would be a good fit for Drizzle proper, please don't hesitate to create issues or ping any of us!

teamwork

from drizzle.

erikjung avatar erikjung commented on May 20, 2024

@giuseppeg

That's interesting. This is definitely not by design, so we'll look into it.

from drizzle.

erikjung avatar erikjung commented on May 20, 2024

@giuseppeg

Can you confirm that every instance of the partial in question is being invoked using the block syntax ({{#>)? In my testing, I got this same error, but realized that it was because I had used the partial multiple times (for different pattern variations), some with {{embed}}.

If you need to use either the block syntax or {{embed}} on a component partial, you can also try adding logic to check for @partial-block:

<div class="MyComponent">
  {{#if @partial-block}}    {{! <-------- for using the block syntax }}
    {{> @partial-block}}
  {{else}}
    {{#block "content"}}    {{! <-------- for using embed or extend }}
      Default content
    {{/block}}
  {{/if}}
</div>

from drizzle.

giuseppeg avatar giuseppeg commented on May 20, 2024

Sorry @erikjung I was out for the weekend.

Yes I've used the block syntax.

If you need to use either the block syntax or {{embed}} on a component partial, you can also try adding logic to check for @partial-block

Do you mean if I want to use a template as embed AND partial? If so, no it is not my case.

It seems that drizzle is just not looking at the patterns/ folder for partials.

from drizzle.

erikjung avatar erikjung commented on May 20, 2024

@giuseppeg

I looked into this a bit further, and it appears you can use {{>@partial-block}} as long as some care is taken for base patterns.

Here is an example that builds with no error:
https://github.com/cloudfour/drizzle/compare/debug-issue_87

This is not intuitive, but it kind of makes sense. All patterns are registered as partials, and they are also rendered as patterns unless you put hidden: true in the front matter. It is in this initial rendering that we encounter the error: @partial-block won't exist until that pattern is used as a partial with the block syntax.

So if you intend to make a "base" pattern to be extended, there are two options for using the partial block syntax:

  1. Make the base pattern hidden:

    ---
    hidden: true
    ---
    <div>{{>@partial-block}}</div>
  2. Use a condition to only output @partial-block if it exists:

    <div>
    {{#if @partial-block}}
      {{>@partial-block}}
    {{/if}}
    </div>

It's probably worth mentioning this in the docs :)

from drizzle.

giuseppeg avatar giuseppeg commented on May 20, 2024

@erikjung awesome man! Thank you so much for debugging this for me :)
I will try your suggestions tomorrow.

from drizzle.

giuseppeg avatar giuseppeg commented on May 20, 2024

@erikjung the approach seems to be working, however it explodes when I use it as simple partial without the block syntax:

---
hidden: true
---
<div>
  {{#if @partial-block}}
    {{>@partial-block}}
  {{else}}
     Default Content
  {{/if}}
</div>

Works

{{#>partial-name}}
{{/partial-name}}

Doesn't work: RangeError: Maximum call stack size exceeded

{{>partial-name}}

This should display the default content right?

from drizzle.

erikjung avatar erikjung commented on May 20, 2024

@giuseppeg

That should work fine. I added another example to this test branch to verify the plain partial usage, and I wasn't able to reproduce that error: https://github.com/cloudfour/drizzle/compare/debug-issue_87

Can you pull that branch and verify?

from drizzle.

giuseppeg avatar giuseppeg commented on May 20, 2024

Here is a diff of the part that cause the Maximum call stack size exceeded

If I remove

{{>"patterns.components.nav.item-link" href="#foo"}}

the build doesn't break

diff --git a/src/patterns/components/nav/example.hbs b/src/patterns/components/nav/example.hbs
new file mode 100644
index 0000000..7289bad
--- /dev/null
+++ b/src/patterns/components/nav/example.hbs
@@ -0,0 +1,14 @@
+{{#>patterns.components.nav.index}}
+
+  {{>"patterns.components.nav.item-link" href="#foo"}}
+
+  {{#>patterns.components.nav.item}}
+    {{#>patterns.components.nav.link href="#baz"}}
+      Link
+      <span class="SiteNav-wrapIcon">
+        <span class="Icon">🕶</span>
+      </span>
+    {{/patterns.components.nav.link}}
+  {{/patterns.components.nav.item}}
+
+{{/patterns.components.nav.index}}
diff --git a/src/patterns/components/nav/index.hbs b/src/patterns/components/nav/index.hbs
new file mode 100644
index 0000000..ed50b2c
--- /dev/null
+++ b/src/patterns/components/nav/index.hbs
@@ -0,0 +1,10 @@
+---
+hidden: true
+---
+<nav class="SiteNav" role="navigation">
+  {{#if @partial-block}}
+    {{>@partial-block}}
+  {{else}}
+    Nav List
+  {{/if}}
+</nav>
diff --git a/src/patterns/components/nav/item-link.hbs b/src/patterns/components/nav/item-link.hbs
new file mode 100644
index 0000000..a3ec35d
--- /dev/null
+++ b/src/patterns/components/nav/item-link.hbs
@@ -0,0 +1,12 @@
+---
+hidden: true
+---
+<span class="SiteNav-item">
+  <a class="SiteNav-link" href="{{href}}">
+    {{#if @partial-block}}
+      {{>@partial-block}}
+    {{else}}
+      Link
+    {{/if}}
+  </a>
+</span>
diff --git a/src/patterns/components/nav/item.hbs b/src/patterns/components/nav/item.hbs
new file mode 100644
index 0000000..ba6dc63
--- /dev/null
+++ b/src/patterns/components/nav/item.hbs
@@ -0,0 +1,10 @@
+---
+hidden: true
+---
+<span class="SiteNav-item">
+  {{#if @partial-block}}
+    {{>@partial-block}}
+  {{else}}
+    Item
+  {{/if}}
+</span>
diff --git a/src/patterns/components/nav/link.hbs b/src/patterns/components/nav/link.hbs
new file mode 100644
index 0000000..bbf8d23
--- /dev/null
+++ b/src/patterns/components/nav/link.hbs
@@ -0,0 +1,10 @@
+---
+hidden: true
+---
+<a class="SiteNav-link" href="{{href}}">
+  {{#if @partial-block}}
+    {{>@partial-block}}
+  {{else}}
+    Link
+  {{/if}}
+</a>

from drizzle.

erikjung avatar erikjung commented on May 20, 2024

@giuseppeg

Thanks for the additional info. It looks like this is an issue that affects Handlebars itself: https://tonicdev.com/erikjung/57c72b19ad12611300cb9f58

^ Same error conditions (no error when removing the patterns.components.nav.item-link partial)

from drizzle.

giuseppeg avatar giuseppeg commented on May 20, 2024

@erikjung I see, thanks for taking the time to dig into this issue!
I am using handlebars for the first time so I thought I was doing something wrong.

[unrelated] I am working (hacking) on a fork of drizzle that integrates suitcss and what I think is a great (better) folders structure, I am also considering to make a template-engine agnostic builder pkg that uses consolidate.js or metalsmith-layouts behind the scenes – basically I may end up writing my own styleguide generator tool from scratch 😂 let me know if you folks are interested in a collaboration or want to discuss about this in details.

from drizzle.

erikjung avatar erikjung commented on May 20, 2024

@giuseppeg We use SUIT on most of our projects, so that's great 👍

The template handling is also something we plan on improving for 1.0. We've received some good feedback on it, and using Consolidate seems to make a lot of sense.

from drizzle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.