Skip to content

Commit 6c949df

Browse files
author
Alexander
authored
Merge pull request #1 from yukal/dev
Merge dev into master branch
2 parents cf0143b + 2d978e9 commit 6c949df

File tree

17 files changed

+446
-328
lines changed

17 files changed

+446
-328
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

README.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,32 @@ src src
6363

6464
Somewhere in gulpfile.js:
6565
```javascript
66-
const gulp = require('gulp');
67-
const plugins = require('gulp-load-plugins')();
68-
const jsonLoaderFactory = require('./lib/gulp-json-loader');
69-
const jsonLoader = jsonLoaderFactory({
70-
// sourcePath: __dirname,
66+
// It is optional now, but you able to tune it as you wish.
67+
// You can pass the settings by an object, or you can pass it using package.json
68+
const jsonLoaderSettings = {
69+
// Chose where the source files are located.
70+
// Use sourcePath or the pare of pathHtml and pathData
71+
72+
// sourcePath: 'src',
7173
pathHtml: 'src/html',
7274
pathData: 'src/data',
75+
76+
// The namespace where the Data is located.
77+
// To get some loaded data from the JSON in a PUG context use syntax:
78+
// $.href or $.imports.menu
79+
dataEntry: '$',
80+
81+
// It needs for the Date object to show a local date
82+
locales: 'en-GB',
83+
84+
// Will report about the loaded JSON files
7385
report: true,
74-
});
86+
};
87+
88+
const gulp = require('gulp');
89+
const plugins = require('gulp-load-plugins')();
90+
const jsonLoaderFactory = require('./lib/gulp-json-loader');
91+
const jsonLoader = jsonLoaderFactory(jsonLoaderSettings);
7592

7693
function html() {
7794
return gulp.src('src/html/**/*.pug')
@@ -108,17 +125,20 @@ block content
108125
//- - console.log(data)
109126
110127
div= filename
111-
div: a(href=data.href)= data.name
128+
div: a(href = $.href)= $.name
112129
113130
ul.genres
114-
each Genre in data.imports.genres
131+
each $GenreItem in $.imports.genres
115132
li
116-
a(href=Genre.href)= Genre.name
133+
a(href = $GenreItem.href)= $GenreItem.name
117134
```
118135

119136
Run command to build html page with data
120137
```bash
121138
$ gulp html
139+
140+
# Or
141+
$ npx gulp html
122142
```
123143

124144
### TODO

changes.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
v1.1.0:
2+
- Updated core
3+
- Imposed restrictions on accessing external directories.
4+
- There is no need to pass the config data to GulpJsonLoader, now it's optional
5+
and defined from defaults. But if you want to change them, you might tune it in
6+
both ways: using an old-style passing an object with options to GulpJsonLoader
7+
factory or just pass the settings into a package.json. See package.json.
8+
9+
- Updated dependencies
10+
- gulp-load-plugins: ^2.0.7
11+
- gulp-pug: ^5.0.0
12+
13+
- Improvement of variables names
14+
- To distinguish variables from stylistic PAG syntax it is preferable to name
15+
variables in a different way as opposed to decoration text. That's why I name
16+
variables with a capital letter and a dollar sign at the beginning.
17+
See PUG files to find out more about it.
18+
19+
- The entry name of the Data loaded from the JSON file is defined in a global
20+
space as a "data" entry, now you can change this name as you like.
21+
See package.json and PUG files to find out more about it.
22+
23+
- Implemented data caching
24+
- The data that has already been loaded will be getting from the cache

gulpfile.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,16 @@
22

33
const gulp = require('gulp');
44
const plugins = require('gulp-load-plugins')();
5-
const jsonLoader = require('./lib/gulp-json-loader')({
6-
// sourcePath: __dirname,
7-
pathHtml: 'src/html',
8-
pathData: 'src/data',
9-
report: true,
10-
});
5+
const jsonLoader = require('./lib/gulp-json-loader')();
116

127
function html() {
13-
return gulp.src('src/html/**/*.pug')
14-
.pipe(plugins.data(jsonLoader))
15-
.pipe(plugins.pug({
16-
pretty: true
17-
}))
18-
.pipe(gulp.dest('dist'))
19-
;
8+
return gulp.src('src/html/**/*.pug')
9+
.pipe(plugins.data(jsonLoader))
10+
.pipe(plugins.pug({
11+
pretty: true
12+
}))
13+
.pipe(gulp.dest('dist'))
14+
;
2015
}
2116

2217
exports.html = html;

0 commit comments

Comments
 (0)