const fs = require( 'fs' )
const path = require( 'path' )
const data = {}
const dir = 'src/modules/'
try {
const modules = fs.readdirSync( dir )
modules.forEach( item => {
const module = path.join( dir, item )
if ( ! fs.lstatSync( module ).isDirectory() ) return
const jsons = fs.readdirSync( module ).filter( item => path.extname( item ) === '.json' )
jsons.forEach( json => {
const name = path.basename( json, path.extname( json ) )
const file = path.join( dir, item, json )
data[name] = JSON.parse( fs.readFileSync( file ) )
})
})
} catch (e) {
console.log(e)
}
// далее отправляем данные в PUG (будет глобальный объект jsons)
gulp.task("html", function() {
return gulp.src("src/pages/*.pug")
.pipe(plumber())
.pipe(pug({locals: {jsons: data}}))
.pipe(gulp.dest("dist"))
});
mixin tovar(name, list, kg)
.tovar__item.tovar__item--basis
.tovar__main
.tovar__info
.tovar__title Нямушка #[span= name]
ul.list
each item in list
li
if item.num
span= item.num
| #{item.text}
button.button #[span= kg] кг
// call
+tovar('Название', [{num: 10, text: "порций"}, {text: 'мышь в подарок'}, ], '0.5')
//
.product--production-wrapper
each item in [ {image: 'bed-1.jpg', price: '1999', name: 'Название продукта 1'}, {image: 'bed-2.jpg', price: '345', name: 'Название продукта 2'}, {image: 'bed-3.jpg', price: '2329', name: 'Название продукта 3'} ]
article.bed.card
.product--image
a(href="#"): img(src=`assets/img/product-image/${item.image}`)
.product--desc-wrapper
.product--name-href
h5= item.name
a(href="#") Кровати
a(href="#").price= item.price