Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
38 changes: 29 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,32 @@ src src

Somewhere in gulpfile.js:
```javascript
const gulp = require('gulp');
const plugins = require('gulp-load-plugins')();
const jsonLoaderFactory = require('./lib/gulp-json-loader');
const jsonLoader = jsonLoaderFactory({
// sourcePath: __dirname,
// It is optional now, but you able to tune it as you wish.
// You can pass the settings by an object, or you can pass it using package.json
const jsonLoaderSettings = {
// Chose where the source files are located.
// Use sourcePath or the pare of pathHtml and pathData

// sourcePath: 'src',
pathHtml: 'src/html',
pathData: 'src/data',

// The namespace where the Data is located.
// To get some loaded data from the JSON in a PUG context use syntax:
// $.href or $.imports.menu
dataEntry: '$',

// It needs for the Date object to show a local date
locales: 'en-GB',

// Will report about the loaded JSON files
report: true,
});
};

const gulp = require('gulp');
const plugins = require('gulp-load-plugins')();
const jsonLoaderFactory = require('./lib/gulp-json-loader');
const jsonLoader = jsonLoaderFactory(jsonLoaderSettings);

function html() {
return gulp.src('src/html/**/*.pug')
Expand Down Expand Up @@ -108,17 +125,20 @@ block content
//- - console.log(data)

div= filename
div: a(href=data.href)= data.name
div: a(href = $.href)= $.name

ul.genres
each Genre in data.imports.genres
each $GenreItem in $.imports.genres
li
a(href=Genre.href)= Genre.name
a(href = $GenreItem.href)= $GenreItem.name
```

Run command to build html page with data
```bash
$ gulp html

# Or
$ npx gulp html
```

### TODO
Expand Down
24 changes: 24 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
v1.1.0:
- Updated core
- Imposed restrictions on accessing external directories.
- There is no need to pass the config data to GulpJsonLoader, now it's optional
and defined from defaults. But if you want to change them, you might tune it in
both ways: using an old-style passing an object with options to GulpJsonLoader
factory or just pass the settings into a package.json. See package.json.

- Updated dependencies
- gulp-load-plugins: ^2.0.7
- gulp-pug: ^5.0.0

- Improvement of variables names
- To distinguish variables from stylistic PAG syntax it is preferable to name
variables in a different way as opposed to decoration text. That's why I name
variables with a capital letter and a dollar sign at the beginning.
See PUG files to find out more about it.

- The entry name of the Data loaded from the JSON file is defined in a global
space as a "data" entry, now you can change this name as you like.
See package.json and PUG files to find out more about it.

- Implemented data caching
- The data that has already been loaded will be getting from the cache
21 changes: 8 additions & 13 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@

const gulp = require('gulp');
const plugins = require('gulp-load-plugins')();
const jsonLoader = require('./lib/gulp-json-loader')({
// sourcePath: __dirname,
pathHtml: 'src/html',
pathData: 'src/data',
report: true,
});
const jsonLoader = require('./lib/gulp-json-loader')();

function html() {
return gulp.src('src/html/**/*.pug')
.pipe(plugins.data(jsonLoader))
.pipe(plugins.pug({
pretty: true
}))
.pipe(gulp.dest('dist'))
;
return gulp.src('src/html/**/*.pug')
.pipe(plugins.data(jsonLoader))
.pipe(plugins.pug({
pretty: true
}))
.pipe(gulp.dest('dist'))
;
}

exports.html = html;
Expand Down
Loading