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

dynamic includes plugin request #2558

Closed
acidjazz opened this issue Sep 24, 2016 · 6 comments
Closed

dynamic includes plugin request #2558

acidjazz opened this issue Sep 24, 2016 · 6 comments

Comments

@acidjazz
Copy link
Contributor

acidjazz commented Sep 24, 2016

ex:

.menu
  each item in ['dashboard','users','clients','structures','entities']
    .item(class='item_' + item)
      .icon
        include "../../vector/" + item + ".svg"
      .label=item

more information can be found here

@lagden
Copy link

lagden commented Nov 10, 2016

@acidjazz could be:

style
  each s in styles
    include-dyn `../public/css/${s}`

Add include-dyn on Pug API...

@lagden
Copy link

lagden commented Nov 10, 2016

Take a look...
https://github.com/pugjs/pug-plugin-dynamic-include

@acidjazz
Copy link
Contributor Author

@lagden have you gotten this working? it looks abandoned w/ a failing build.

@ForbesLindesay
Copy link
Member

It may need some small updates, but should be approximately working. If you get it set up, you could submit a pull request.

@lagden
Copy link

lagden commented Jan 23, 2017

@acidjazz and @ForbesLindesay

I did a workaround using datasource method...

Example using Koa.js

The server side module
const {readFileSync} = require('fs')
const {join} = require('path')
const pugEngine = require('pug')
const Pug = require('koa-pug')

function datasource(file, type, data = {}) {
	const content = readFileSync(file, 'utf8')
	switch (type) {
		case 'json':
			return JSON.parse(content)
		case 'pug':
			return pugEngine.renderFile(content, data)
		default:
			return content
	}
}

const isDev = process.env.NODE_ENV === 'development'
const viewPath = join(__dirname, '..', 'views')
const dataPath = join(__dirname, '..', 'data')
const pug = new Pug({
	locals: {isDev, datasource, viewPath, dataPath},
	pretty: isDev,
	viewPath
})

module.exports = pug
The template
extends ../../layout/main
block content
	.icon
		each item in ['hamburguer','user']
			- const svg = datasource(`${viewPath}/shared/icons/${item}.svg`)
			!= svg

@geoidesic
Copy link

I don't understand what the resolution was here. Was this merged in or not?

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

4 participants