Skip to content
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

[Feature Request] Resolver for NPM Modules #1136

Closed
oleersoy opened this issue Aug 20, 2018 · 1 comment
Closed

[Feature Request] Resolver for NPM Modules #1136

oleersoy opened this issue Aug 20, 2018 · 1 comment

Comments

@oleersoy
Copy link

Suppose we have a package installed like this:

`npm i -S @example/cards`

Now want to import from it like this within a template:

`{% import "@example/templates/birthday.html" as birthday %}`

Could the nunjucks resolver implement NPMs resolv alogrithm?

@oleersoy
Copy link
Author

I'm cancelling this request. It ended up being as easy as nunjucks.configure('node_modules'); I have implemented this for import and rendering in the SuperflyCSS CLI in case anyone wants to see a sample.

For example all the tests in @superflycss/component-navbox use nunjucks test templates from @superflycss/component-test for rendering.

Here's some sample markup where navbox tests import from @superflycss/component-test:

{% import "@superflycss/component-test/TestHead.njk" as TestHead %}
{% import "@superflycss/component-test/TestHeader.njk" as TestHeader %}
{% import "@superflycss/component-test/TestTemplate.njk" as Test %}

{{ TestHead.component( 'navbox' ) }}

<body>

{{ TestHeader.render( 'navbox' ) }}

<!-- START TEST -->
{% set when1 %}
<code class="u-text-color-md-pink-400">Navbox</code> is the container.
{% endset %}
{% call Test.component( 'Navbox', when1, 'Items are rendered in a column always regardless of viewport size.' ) %}
<nav class="Navbox">
    <a href="#">First item</a>
    <a href="#">Second item</a>
    <a href="#">Third item</a>
</nav>
{% endcall %}

If anyone wants to play around with it / see inner workings:

git clone https://github.com/superflycss/component-navbox.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant