boxwood 0.60.3 → 0.61.1

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.
Files changed (139) hide show
  1. package/README.md +0 -358
  2. package/index.js +408 -4
  3. package/package.json +12 -37
  4. package/src/Bundler.js +0 -13
  5. package/src/Cache.js +0 -35
  6. package/src/Compiler.js +0 -28
  7. package/src/Importer.js +0 -142
  8. package/src/Optimizer.js +0 -96
  9. package/src/Scope.js +0 -20
  10. package/src/Statistics.js +0 -58
  11. package/src/bundlers/esbuild/index.js +0 -55
  12. package/src/bundlers/esbuild/plugins/css.js +0 -40
  13. package/src/bundlers/esbuild/plugins/html.js +0 -27
  14. package/src/bundlers/esbuild/plugins/image.js +0 -38
  15. package/src/bundlers/esbuild/plugins/resolve.js +0 -11
  16. package/src/bundlers/esbuild/plugins/yaml.js +0 -38
  17. package/src/bundlers/esbuild/utilities/asset.js +0 -19
  18. package/src/bundlers/rollup.js +0 -38
  19. package/src/compile.js +0 -6
  20. package/src/compilers/any/Compiler.js +0 -16
  21. package/src/compilers/compile.js +0 -17
  22. package/src/compilers/html/Analyzer.js +0 -24
  23. package/src/compilers/html/Compiler.js +0 -47
  24. package/src/compilers/html/Generator.js +0 -19
  25. package/src/compilers/html/Parser.js +0 -11
  26. package/src/compilers/html/Preprocessor.js +0 -130
  27. package/src/compilers/html/Renderer.js +0 -167
  28. package/src/compilers/html/Transpiler.js +0 -76
  29. package/src/compilers/js/Bundler.js +0 -84
  30. package/src/compilers/js/Compiler/index.js +0 -27
  31. package/src/conditions/isEqual.js +0 -5
  32. package/src/lexers/html.js +0 -49
  33. package/src/lexers/internal.js +0 -49
  34. package/src/linters/html/bracket.js +0 -40
  35. package/src/linters/html/component.js +0 -43
  36. package/src/linters/html/import.js +0 -35
  37. package/src/linters/html/index.js +0 -19
  38. package/src/linters/html/tag.js +0 -36
  39. package/src/optimizers/html.js +0 -15
  40. package/src/plugins/BoxModelPlugin/index.js +0 -109
  41. package/src/plugins/CurlyStylesPlugin/index.js +0 -39
  42. package/src/plugins/DataPlugin/index.js +0 -53
  43. package/src/plugins/InlinePlugin/css.js +0 -131
  44. package/src/plugins/InlinePlugin/index.js +0 -39
  45. package/src/plugins/InternationalizationPlugin/index.js +0 -111
  46. package/src/plugins/Plugin.js +0 -22
  47. package/src/plugins/ScopedStylesPlugin/css.js +0 -56
  48. package/src/plugins/ScopedStylesPlugin/html.js +0 -112
  49. package/src/plugins/ScopedStylesPlugin/index.js +0 -48
  50. package/src/plugins/SwappedStylesPlugin/index.js +0 -20
  51. package/src/render.js +0 -48
  52. package/src/tags/case.js +0 -28
  53. package/src/tags/catch.js +0 -17
  54. package/src/tags/data.js +0 -7
  55. package/src/tags/default.js +0 -20
  56. package/src/tags/doctype.js +0 -8
  57. package/src/tags/else.js +0 -18
  58. package/src/tags/elseif.js +0 -25
  59. package/src/tags/elseunless.js +0 -30
  60. package/src/tags/font.js +0 -37
  61. package/src/tags/for.js +0 -90
  62. package/src/tags/foreach.js +0 -80
  63. package/src/tags/if.js +0 -19
  64. package/src/tags/img.js +0 -25
  65. package/src/tags/index.js +0 -53
  66. package/src/tags/link.js +0 -14
  67. package/src/tags/script/index.js +0 -83
  68. package/src/tags/script/scoped.js +0 -26
  69. package/src/tags/slot.js +0 -9
  70. package/src/tags/style.js +0 -9
  71. package/src/tags/switch.js +0 -13
  72. package/src/tags/template.js +0 -22
  73. package/src/tags/translate.js +0 -22
  74. package/src/tags/translation.js +0 -38
  75. package/src/tags/try.js +0 -17
  76. package/src/tags/unless.js +0 -24
  77. package/src/tags/var.js +0 -32
  78. package/src/transpilers/css/index.js +0 -34
  79. package/src/transpilers/html/expression.js +0 -101
  80. package/src/transpilers/html/index.js +0 -189
  81. package/src/transpilers/html/node.js +0 -46
  82. package/src/transpilers/html/tags/any.js +0 -53
  83. package/src/transpilers/html/tags/comment.js +0 -7
  84. package/src/transpilers/html/tags/doctype.js +0 -6
  85. package/src/transpilers/html/tags/for.js +0 -30
  86. package/src/transpilers/html/tags/if.js +0 -55
  87. package/src/transpilers/html/tags/import.js +0 -7
  88. package/src/transpilers/html/tags/index.js +0 -13
  89. package/src/transpilers/html/tags/partial.js +0 -17
  90. package/src/transpilers/html/tags/slot.js +0 -7
  91. package/src/transpilers/html/tags/text.js +0 -6
  92. package/src/transpilers/html/tags/try.js +0 -30
  93. package/src/transpilers/html/tags/unless.js +0 -58
  94. package/src/transpilers/html/utilities/path.js +0 -9
  95. package/src/utilities/action.js +0 -208
  96. package/src/utilities/array.js +0 -80
  97. package/src/utilities/assets.js +0 -18
  98. package/src/utilities/ast.js +0 -13
  99. package/src/utilities/attributes.js +0 -23
  100. package/src/utilities/collect.js +0 -404
  101. package/src/utilities/conditions.js +0 -159
  102. package/src/utilities/convert.js +0 -359
  103. package/src/utilities/data.js +0 -55
  104. package/src/utilities/enum.js +0 -103
  105. package/src/utilities/errors.js +0 -96
  106. package/src/utilities/factory.js +0 -237
  107. package/src/utilities/files.js +0 -55
  108. package/src/utilities/filters.js +0 -140
  109. package/src/utilities/globals.js +0 -43
  110. package/src/utilities/html.js +0 -60
  111. package/src/utilities/inline.js +0 -200
  112. package/src/utilities/js.js +0 -15
  113. package/src/utilities/keywords.js +0 -35
  114. package/src/utilities/log.js +0 -31
  115. package/src/utilities/node.js +0 -149
  116. package/src/utilities/object.js +0 -8
  117. package/src/utilities/optimize.js +0 -268
  118. package/src/utilities/options.js +0 -99
  119. package/src/utilities/request.js +0 -13
  120. package/src/utilities/string.js +0 -144
  121. package/src/utilities/style.js +0 -15
  122. package/src/utilities/translations.js +0 -78
  123. package/src/utilities/url.js +0 -24
  124. package/src/vdom/browser/app.js +0 -19
  125. package/src/vdom/browser/diff.js +0 -104
  126. package/src/vdom/browser/index.js +0 -15
  127. package/src/vdom/browser/mount.js +0 -10
  128. package/src/vdom/browser/render.js +0 -66
  129. package/src/vdom/browser/replace.js +0 -7
  130. package/src/vdom/node.js +0 -10
  131. package/src/vdom/nodes.js +0 -116
  132. package/src/vdom/server/State.js +0 -21
  133. package/src/vdom/server/boxwood.js +0 -5
  134. package/src/vdom/server/index.js +0 -19
  135. package/src/vdom/server/render.js +0 -66
  136. package/src/vdom/tag.js +0 -33
  137. package/src/vdom/utilities/classes.js +0 -22
  138. package/src/vdom/utilities/css.js +0 -17
  139. package/src/vdom/utilities/escape.js +0 -50
package/README.md CHANGED
@@ -7,373 +7,15 @@
7
7
 
8
8
  ## Table of Contents
9
9
 
10
- - [Background](#background)
11
10
  - [Install](#install)
12
- - [Usage](#usage)
13
- - [API](#api)
14
- - [REPL](https://buxlabs.pl/en/tools/js/boxwood)
15
11
  - [Maintainers](#maintainers)
16
12
  - [Contributing](#contributing)
17
13
  - [License](#license)
18
14
 
19
- ## Background
20
-
21
- The library is a compiler designed to generate an optimal rendering function. The function should get cached and reused to provide a much better performance than other templating languages.
22
-
23
- It can also be used in variety of contexts, for rendering html pages, email templates, pdf templates. It's capable of importing components and partials, inlining images and styles, which can be useful in those scenarios. The syntax should be easy to read and write.
24
-
25
- Not everything is ready yet, but long-term, the library should be able to generate a template that includes minified html with critical css/js that's required to run the page. Scoped css/js should let you build big, dynamic apps.
26
-
27
- Server-side rendering works out of the box, and some day we'd like to include an optional runtime with a minimal footprint, which allows you to seamlessly switch to a single-page-app mode, without page reloads.
28
-
29
- Even further in the future, the compiler is going to be split into a front-end compiler and a back-end compiler, that will use an intermediate representation to represent the app. This way it'll allow the app to be written in a different way, while preserving the performance, which will get better over time, as the compiler matures.
30
-
31
- If this sounds great, jump on board and try it out. Every little bit helps.
32
-
33
- ### Status
34
-
35
- Beta / Used in production / Needs security assessment
36
-
37
- ### Syntax
38
-
39
- #### Curly Tags
40
-
41
- `{name}` is a curly tag
42
-
43
- Curly tags can contain expressions, e.g. `{1 + 2}` is a valid tag.
44
- They can also contain additional filters like `{name | capitalize}`.
45
-
46
- ```html
47
- <div>{name}</div>
48
- ```
49
-
50
- #### Square Tags
51
-
52
- `[color]` is a square tag
53
-
54
- Square tags are array expressions and can be used as values of html attributes.
55
-
56
- ```html
57
- <button class="[color, size, shape]"><slot/></button>
58
- ```
59
-
60
- #### HTML Tags
61
-
62
- `<if>` is an html tag
63
-
64
- HTML tags can contain additional attributes, e.g. `<if limit is a number>` is a valid tag. The attribute syntax follows the natural language principles.
65
-
66
- ```html
67
- <if name is present>
68
- Hello, {name}!
69
- <else>
70
- Welcome!
71
- <end>
72
- ```
73
-
74
15
  ## Install
75
16
 
76
17
  `npm install boxwood`
77
18
 
78
- ## Usage
79
-
80
- ### compile
81
-
82
- ```js
83
- const { compile, escape } = require('boxwood')
84
-
85
- async function example () {
86
- const { template } = await compile('<div>{foo}</div>', { cache: false })
87
- console.log(template({ foo: 'bar' }, escape))
88
- }
89
-
90
- example()
91
-
92
- ```
93
-
94
- ### createRender
95
-
96
- ```js
97
- const { createRender } = require('boxwood')
98
-
99
- const render = createRender({
100
- cacheEnabled: process.env.NODE_ENV === 'production',
101
- compilerOptions: {
102
- paths: [
103
- path.join(__dirname, 'views'),
104
- path.join(__dirname, 'public')
105
- ]
106
- },
107
- globals (path, options) {
108
- return { domain: 'https://foo.bar' }
109
- }
110
- })
111
-
112
- // ... await render(path, options, callback?)
113
- ```
114
-
115
- #### cacheEnabled = true
116
-
117
- It lets you disable cache in certain conditions. You probably don't want to cache files during development.
118
-
119
- #### compilerOptions = {}
120
-
121
- These options are passed down to [boxwood](https://github.com/buxlabs/boxwood).
122
-
123
- #### globals = {}
124
-
125
- Often you have some data that can be reused in many pages. The option can be either a function that returns an object, or an object.
126
-
127
- #### log = false
128
-
129
- Option for displaying warnings and errors in console. By default logging is off.
130
-
131
- ## API
132
-
133
- ### Tags
134
-
135
- #### import/require
136
-
137
- You can import components and use them.
138
-
139
- ```html
140
- <import layout from="./layouts/default.html">
141
- <import { form, input, button } from="./components">
142
-
143
- <layout>
144
- <h1>Hello, world!</h1>
145
- <form>
146
- <input name="foo" />
147
- <button>Submit</button>
148
- </form>
149
- </layout>
150
- ```
151
-
152
- It's possible to import multiple components from a given directory. Curly brackets within the import tag are optional.
153
-
154
- You can use the special `<slot/>` tag if you want to render child nodes.
155
-
156
- #### render/partial/include
157
-
158
- You can also render html partials inline. It can be useful for fragments or pages like header, footer etc.
159
-
160
- ```html
161
- <partial from="./foo.html" />
162
- <include partial="./foo.html" />
163
- <render partial="./foo.html" />
164
- ```
165
-
166
- #### if/else/elseif/unless/elseunless
167
-
168
- There are two syntaxes you can use - short and long. The short one allows you to specify the starting tags only, for example:
169
-
170
- ```html
171
- <if foo>bar<end>
172
- ```
173
-
174
- ```html
175
- <if foo>
176
- bar
177
- <elseif baz>
178
- qux
179
- <else>
180
- quux
181
- <end>
182
- ```
183
-
184
- ```html
185
- <unless foo>bar<end>
186
- ```
187
-
188
- The long syntax requires to specify closing tags explicitly.
189
-
190
- ```html
191
- <if foo>
192
- bar
193
- </if>
194
- <else>
195
- baz
196
- </else>
197
- ```
198
-
199
- #### for/each/foreach
200
-
201
- The only difference between those methods is what is being used under the hood, `<for>` uses a standard for tag, `<each>` and `<foreach>` call `.each(` and `.forEach(` method of given object.
202
-
203
- ```html
204
- <for car of cars>
205
- {car.brand}
206
- </for>
207
-
208
- <for car and index of cars>
209
- #{index + 1} {car.brand}
210
- </for>
211
-
212
- <for key and value in object>
213
- {key}: {value}
214
- </for>
215
- ```
216
-
217
- #### data
218
-
219
- ```html
220
- <data yaml>
221
- title: Hello, world!
222
- subtitle: Hey!
223
- </data>
224
- <layout {title}>
225
- {subtitle}
226
- </layout>
227
- ```
228
-
229
- ### Filters
230
-
231
- There are many filters available out of the box.
232
-
233
- ```html
234
- {title | capitalize}
235
- {title | uppercase}
236
- ```
237
-
238
- Filters can be chained too.
239
-
240
- ```html
241
- {title | trim | classify}
242
- ```
243
-
244
- Params can be passed as well.
245
-
246
- ```html
247
- {title | slugify('_')}
248
- ```
249
-
250
- Full list of filters is available [here](https://buxlabs.pl/en/tools/js/pure-utilities/repl).
251
-
252
- ### Attributes
253
-
254
- #### element[padding|margin|border]
255
-
256
- Custom spacing is often a problem, so you can add paddings, margins and borders using a shorter syntax.
257
-
258
- ```html
259
- <div padding-bottom="1rem"></div>
260
- ```
261
-
262
- #### element[css|style]
263
-
264
- You can define styles as objects too.
265
-
266
- ```html
267
- <div css="{{ padding: { bottom: '1rem', top: '2rem' } }}"></div>
268
- ```
269
-
270
- #### element[partial]
271
-
272
- Partial attribute will load the html file and include as the children of given node. The tag will be preserved.
273
-
274
- ```html
275
- <head partial="./head.html"></head>
276
- ```
277
-
278
- #### img[inline]
279
-
280
- It's possible to inline images as base64 strings.
281
-
282
- ```html
283
- <img src="images/foo.png" inline>
284
- ```
285
-
286
- ### Styles
287
-
288
- #### scoped
289
-
290
- Scoped styles are adding special `scope-${number}` classes to both html and css to ensure they're unique.
291
-
292
- ```html
293
- <div class="foo">bar</div>
294
- <style scoped>
295
- .foo {
296
- color: red;
297
- }
298
- </style>
299
- ```
300
-
301
- ### Scripts
302
-
303
- #### compiler
304
-
305
- You can hook up any compiler, which will transform and inline the source code.
306
-
307
- ```html
308
- <div id="app"></div>
309
- <script compiler="preact">
310
- import { render } from "preact"
311
- const Foo = ({ bar }) => {
312
- return (<span>{bar}</span>)
313
- }
314
- render(
315
- <Foo bar="baz" />,
316
- document.getElementById("app")
317
- )
318
- </script>
319
- ```
320
-
321
- ### Variables
322
-
323
- #### globals
324
-
325
- You can reference the parameters that were passed to the template via the `globals` object too. It might be useful is some scenarios but sending params explicitly is usually better.
326
-
327
- ```html
328
- <!-- layouts/partials/head.html - layouts/default.html - pages/about/index.html -->
329
- <!-- you could send stylesheets explicitly, but it could -->
330
- <!-- get annoying if the layout is used in many places -->
331
-
332
- <head>
333
- <for stylesheet in globals.stylesheets>
334
- <link rel="stylesheet" type="text/css" href="{stylesheet}">
335
- </for>
336
- </head>
337
- ```
338
-
339
- ### Internationalization
340
-
341
- #### translate tag
342
-
343
- You can keep translations in every file. They're scoped so you can use same names in multiple files. Translations can be kept in `data` tags.
344
-
345
- ```html
346
- <h1><translate hello/></h1>
347
- <data yaml>
348
- i18n:
349
- hello:
350
- pl: Hej
351
- en: Hello
352
- </data>
353
- ```
354
-
355
- You also need to pass `languages` to the compiler. The template needs to get the `language` to know which text to render.
356
-
357
- ```js
358
- // ...
359
- const { template } = await compile(source, { languages: ['pl', 'en'] })
360
- const html = template({ language: 'en' }, escape)
361
- // ...
362
- ```
363
-
364
- #### translation tag
365
-
366
- For more complicated texts, you can also use inline translations.
367
-
368
- ```html
369
- <translation pl>
370
- <p>Hej! Lorem ipsum dolor <span>sit amet</span>.</p>
371
- </translation>
372
- <translation en>
373
- <p>Hello! Lorem ipsum dolor <span>sit amet</span>.</p>
374
- </translation>
375
- ```
376
-
377
19
  ## Maintainers
378
20
 
379
21
  [@emilos](https://github.com/emilos)