@videinfra/static-website-builder 1.15.3 → 1.15.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/init/test/.env CHANGED
@@ -3,3 +3,4 @@ FOO=foo-global
3
3
  TYPE_BOOL_TRUE=true
4
4
  TYPE_BOOL_FALSE=false
5
5
  TYPE_NUMBER=123.456
6
+ TYPE_EMPTY=
@@ -31,6 +31,9 @@ exports.plugins = [
31
31
 
32
32
  // Enables TwigJS engine .twig file compilation
33
33
  require('../../../plugins/twig'),
34
+
35
+ // Enables TWIG Symfony filters
36
+ require('../../../plugins/twig/symfony-filters'),
34
37
  ];
35
38
 
36
39
  exports.env = {
@@ -41,6 +44,7 @@ exports.env = {
41
44
  'TYPE_BOOL_TRUE': 'typeBoolTrue',
42
45
  'TYPE_BOOL_FALSE': 'typeBoolFalse',
43
46
  'TYPE_NUMBER': 'typeNumber',
47
+ 'TYPE_EMPTY': 'typeEmpty',
44
48
  },
45
49
  };
46
50
 
@@ -0,0 +1,4 @@
1
+
2
+ {% extends 'layouts/base.twig' %}
3
+
4
+ {% block body %}{{ 'hello at world' | preposition_nbsp }}{% endblock %}
@@ -3,10 +3,11 @@
3
3
  }
4
4
 
5
5
  :root {
6
- #{ --env-test-type-number }: map-get($env, type-number);
6
+ #{ --env-test-type-number }: map-get($env, typeNumber);
7
+ #{ --env-test-type-empty }: map-get($env, typeEmpty);
7
8
  }
8
9
 
9
- @if map-get($env, type-bool-true) {
10
+ @if map-get($env, typeBoolTrue) {
10
11
  :root {
11
12
  --env-test-bool-true: true;
12
13
  }
@@ -16,7 +17,7 @@
16
17
  }
17
18
  }
18
19
 
19
- @if map-get($env, type-bool-false) {
20
+ @if map-get($env, typeBoolFalse) {
20
21
  :root {
21
22
  --env-test-bool-false: true;
22
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@videinfra/static-website-builder",
3
- "version": "1.15.3",
3
+ "version": "1.15.5",
4
4
  "description": "Customizable static site project builder",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -78,5 +78,21 @@ module.exports.push({
78
78
  }
79
79
  });
80
80
 
81
+ /**
82
+ * Preposition filter
83
+ * Adds a non-breaking space between prepositions and other words
84
+ *
85
+ * @example
86
+ * {{ 'hello at world' | preposition_nbsp }}
87
+ * Output: hello at world
88
+ */
89
+
90
+ const preposition_nbsp = require('./preposition_nbsp');
81
91
 
92
+ module.exports.push({
93
+ name: 'preposition_nbsp',
94
+ func: function (text) {
95
+ return preposition_nbsp(text);
96
+ }
97
+ });
82
98
 
@@ -0,0 +1,28 @@
1
+ const prepositions = [
2
+ 'about', 'above', 'across', 'after', 'against', 'along', 'amid', 'among', 'around', 'as', 'at', 'before', 'behind', 'below', 'beneath', 'beside', 'besides', 'between', 'beyond', 'by', 'concerning', 'despite', 'down', 'during', 'except', 'for', 'from', 'in', 'inside', 'into', 'like', 'near', 'of', 'off', 'on', 'onto', 'out', 'outside', 'over', 'past', 'regarding', 'round', 'since', 'through', 'throughout', 'to', 'toward', 'towards', 'under', 'underneath', 'until', 'unto', 'up', 'upon', 'with', 'within', 'without', 'a', 'an', 'the',
3
+ 'в', 'на', 'по', 'к', 'у', 'от', 'из', 'с', 'над', 'под', 'при', 'без', 'до', 'для', 'за', 'через', 'перед', 'около', 'вокруг', 'о', 'об', 'обо', 'про', 'среди', 'между', 'ради', 'вдоль', 'вне', 'кроме', 'сквозь', 'вследствие', 'благодаря', 'согласно', 'вопреки', 'вроде', 'насчёт', 'касательно', 'против', 'со', 'во', 'ко', 'ото', 'изо', 'надо', 'подо', 'передо', 'передо', 'и'
4
+ ];
5
+
6
+ // Word boundary regex
7
+ // (?<= # Lookbehind, but don't consume
8
+ // (^| # Start of string or
9
+ // [^\\p{L}] # Non-letter, works with unicode characters too
10
+ const regexWordBoundary = '(?<=(^|[^\\p{L}]))';
11
+ const regexEscape = /[.*+?^${}()|[\]\\]/g;
12
+
13
+ let prepositionsRegex = null;
14
+
15
+ function escapeRegExp(string) {
16
+ return string.replace(regexEscape, '\\$&'); // $& means the whole matched string
17
+ }
18
+
19
+ function prepositionNbsp(text) {
20
+ if (!prepositionsRegex) {
21
+ const prepositionsEscaped = prepositions.map(preposition => escapeRegExp(preposition));
22
+ prepositionsRegex = new RegExp(`${regexWordBoundary}(${prepositionsEscaped.join('|')})\\s+`, 'uig');
23
+ }
24
+
25
+ return text.replace(prepositionsRegex, '$2&nbsp;');
26
+ }
27
+
28
+ module.exports = prepositionNbsp;
@@ -46,7 +46,7 @@ function getEnvData () {
46
46
  if (key in envVariables) {
47
47
  const value = envVariables[key];
48
48
  const camelCase = map[key];
49
- const kebabCase = map[key].replace(/([a-z])([A-Z])/g, '$1-$2').replace(/_([a-z])/ig, '-$1').toLowerCase();
49
+ const kebabCase = map[key];
50
50
  twigVariables[camelCase] = normalizeTwigVariable(value);
51
51
  envOutVariables[camelCase] = value;
52
52
  jsVariables[`process.env.${ camelCase }`] = escapeJSVariable(value);
@@ -40,10 +40,12 @@ const getWatchGlobPaths = memoize(function () {
40
40
  const sourcePaths = getPaths.getSourcePaths('html');
41
41
  const extensions = getConfig.getTaskConfig('html', 'extensions');
42
42
  const dataExtensions = getConfig.getTaskConfig('data', 'extensions');
43
+ const envFiles = getPaths.getPathConfig().env.map((path) => getPaths.getProjectPath(path))
43
44
 
44
45
  return globs.generate(
45
46
  globs.paths(sourcePaths).filesWithExtensions(extensions), // HTML / TWIG files
46
- globs.paths(sourcePaths).filesWithExtensions(dataExtensions) // Data files
47
+ globs.paths(sourcePaths).filesWithExtensions(dataExtensions), // Data files
48
+ envFiles, // env files
47
49
  );
48
50
  });
49
51
 
@@ -114,6 +114,7 @@ test('.env and .env.local files loaded', () => {
114
114
  expect(css.indexOf('--env-test-bool-true:true')).not.toBe(-1);
115
115
  expect(css.indexOf('--env-test-bool-false:false')).not.toBe(-1);
116
116
  expect(css.indexOf('--env-test-type-number:123.456')).not.toBe(-1);
117
+ expect(css.indexOf('--env-test-type-empty:""')).not.toBe(-1);
117
118
  }),
118
119
  ]);
119
120
  });
@@ -0,0 +1,28 @@
1
+ const path = require('path');
2
+ const publicPath = path.resolve(__dirname, 'build', 'public');
3
+ const fs = require('fs')
4
+ const fsPromises = fs.promises;
5
+
6
+ const preposition_nbsp = require('../plugins/twig/symfony-filters/preposition_nbsp');
7
+
8
+ test('preposition_nbsp english', () => {
9
+ expect(preposition_nbsp('hello world')).toEqual('hello world');
10
+ expect(preposition_nbsp('hello at')).toEqual('hello at');
11
+ expect(preposition_nbsp('hello at. world')).toEqual('hello at. world');
12
+ expect(preposition_nbsp('hello at world')).toEqual('hello at&nbsp;world');
13
+ expect(preposition_nbsp('hello before at world')).toEqual('hello before&nbsp;at&nbsp;world');
14
+ });
15
+
16
+ test('preposition_nbsp russian', () => {
17
+ expect(preposition_nbsp('ппппп дддд')).toEqual('ппппп дддд');
18
+ expect(preposition_nbsp('ппппп над')).toEqual('ппппп над');
19
+ expect(preposition_nbsp('ппппп над. дддд')).toEqual('ппппп над. дддд');
20
+ expect(preposition_nbsp('ппппп над дддд')).toEqual('ппппп над&nbsp;дддд');
21
+ expect(preposition_nbsp('ппппп before над дддд')).toEqual('ппппп before&nbsp;над&nbsp;дддд');
22
+ });
23
+
24
+ test('Preposition TWIG filter applied', () => {
25
+ return fsPromises.readFile(path.resolve(publicPath, 'preposition.html'), {'encoding': 'utf8'}).then((html) => {
26
+ expect(html).toBe('<html><body>hello at&nbsp;world</body></html>');
27
+ });
28
+ });