|
16 | 16 | - [@repeat](#repeat)
|
17 | 17 | - [@if – @elseif – @else](#if--elseif--else)
|
18 | 18 | - [@error](#error)
|
| 19 | + - [@warning](#warning) |
19 | 20 | - [Filters](#filters)
|
20 | 21 | - [Expressions](#expressions)
|
21 | 22 | - [Types](#types)
|
|
25 | 26 | - [Member Expressions](#member-expressions)
|
26 | 27 | - [Conditional Expressions](#conditional-expressions)
|
27 | 28 | - [Variables](#variables)
|
28 |
| - - [Variable Definition Order](#variables-definition-order) |
| 29 | + - [Variable Definition Order](#variable-definition-order) |
29 | 30 | - [\_\_LINE\_\_](#__line__)
|
30 | 31 | - [\_\_FILE\_\_](#__file__)
|
31 | 32 | - [\_\_PATH\_\_](#__path__)
|
|
34 | 35 | - [Comments](#comments)
|
35 | 36 | - [Usage](#usage)
|
36 | 37 | - [Running](#running)
|
| 38 | + - [Including JavaScript Libraries](#including-javascript-libraries) |
| 39 | + - [Binding the Context Object Correctly](#binding-the-context-object-correctly) |
37 | 40 | - [Cache for Remote Includes](#cache-for-remote-includes)
|
38 | 41 | - [Testing](#testing)
|
39 | 42 | - [License](#license)
|
@@ -350,6 +353,29 @@ Emits an error.
|
350 | 353 | <b>@endif</b>
|
351 | 354 | </pre>
|
352 | 355 |
|
| 356 | +### @warning |
| 357 | + |
| 358 | +<pre> |
| 359 | +<b>@warning</b> <i><message:expression></i> |
| 360 | +</pre> |
| 361 | + |
| 362 | +Emits a warning. |
| 363 | + |
| 364 | +#### Example |
| 365 | + |
| 366 | +<pre> |
| 367 | +<b>@if</b> PLATFORM == "platform1" |
| 368 | + // platform 1 code |
| 369 | +<b>@elseif</b> PLATFORM == "platform2" |
| 370 | + // platform 2 code |
| 371 | +<b>@elseif</b> PLATFORM == "platform3" |
| 372 | + // platform 3 code |
| 373 | +<b>@else</b> |
| 374 | + <b>@warning</b> "Building for default platform" |
| 375 | + // default platform code |
| 376 | +<b>@endif</b> |
| 377 | +</pre> |
| 378 | + |
353 | 379 | ## Filters
|
354 | 380 |
|
355 | 381 | The `|` operator (filter) allows you to pass a value through any of the supported functions.
|
@@ -507,6 +533,20 @@ will print the home directory path of the current user of the system where *Buil
|
507 | 533 | - <code>min(<i><numbers></i>)</code>
|
508 | 534 | - <code>max(<i><numbers></i>)</code>
|
509 | 535 | - <code>abs(<i><number></i>)</code>
|
| 536 | +- String functions: the following string functions, based on the JavaScript methods of the same names, are available under the namespace `S`. The first argument to each function is always the string to be operated on. For documentation on the remaining arguments, please see the documentation for JavaScript string methods [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String). |
| 537 | + - <code>S.concat()</code> |
| 538 | + - <code>S.endsWith()</code> |
| 539 | + - <code>S.includes()</code> |
| 540 | + - <code>S.repeat()</code> |
| 541 | + - <code>S.split()</code> |
| 542 | + - <code>S.startsWith()</code> |
| 543 | + - <code>S.substr()</code> |
| 544 | + - <code>S.substring()</code> |
| 545 | + - <code>S.toLowerCase()</code> |
| 546 | + - <code>S.toUpperCase()</code> |
| 547 | + - <code>S.trim()</code> |
| 548 | + - <code>S.trimLeft()</code> |
| 549 | + - <code>S.trimRight()</code> |
510 | 550 |
|
511 | 551 | ## Comments
|
512 | 552 |
|
@@ -565,6 +605,70 @@ Lines starting with `@` followed by space or a line break are treated as comment
|
565 | 605 | * <code>--cache</code> or <code>-c</code> — enable cache for remote files.
|
566 | 606 | * <code>--clear-cache</code> — remove cache before builder starts running.
|
567 | 607 | * <code>--cache-exclude-list <i><path_to_file></i></code> — path to exclude list file.
|
| 608 | + * <code>--lib(s) <i><path_to_file|path_to_directory|glob></i></code> — path to JavaScript file to include as libraries |
| 609 | + |
| 610 | +## Including JavaScript Libraries |
| 611 | + |
| 612 | +Builder can accept JavaScript libraries to add functionality to its global namespace. The library should export an object, the properties of which will be merged into the global namespace. For example, to include a function to convert strings to uppercase, define your library file like so: |
| 613 | + |
| 614 | +```js |
| 615 | +module.exports = { |
| 616 | + upper: (s) => s.toUpperCase() |
| 617 | +}; |
| 618 | +``` |
| 619 | + |
| 620 | +Include directives, such as the following example, in your input file: |
| 621 | + |
| 622 | +``` |
| 623 | +@{upper("warning:")} |
| 624 | +@{upper(include("warning.txt"))} |
| 625 | +``` |
| 626 | + |
| 627 | +Run builder with the option `--lib path/to/your/lib/file`. |
| 628 | + |
| 629 | +### Binding the Context Object Correctly |
| 630 | + |
| 631 | +**Note** Functions called by Builder will be called with their *this* argument set to a Builder context object. Within the context object, Builder [variables](#variables) like `__FILE__`, [functions](#functions) like `max()`, and other included library functions will be made available at the top level. Variables defined in your input code with `@macro` or `@set` will be available under the key *globals*. |
| 632 | + |
| 633 | +Ignoring the binding of *this* may cause unexpected behavior, for example when calling methods on objects. Take the following example library: |
| 634 | + |
| 635 | +```js |
| 636 | +class MyClass { |
| 637 | + constructor(str) { |
| 638 | + this._str = str; |
| 639 | + } |
| 640 | + |
| 641 | + getStr() { |
| 642 | + return this._str; |
| 643 | + } |
| 644 | +} |
| 645 | + |
| 646 | +myObject = MyClass("my text"); |
| 647 | + |
| 648 | +module.exports = { |
| 649 | + myObject |
| 650 | +}; |
| 651 | +``` |
| 652 | + |
| 653 | +Attempting to use this library with the directive `@{myObject.getStr()}` will not deliver the expected behavior because *this* in *getStr()* will be set to a Builder context object and not to *myObject*. When calling class methods ensure they have been bound to the correct value of *this*: |
| 654 | + |
| 655 | +```js |
| 656 | +class MyClass { |
| 657 | + constructor(str) { |
| 658 | + this._str = str; |
| 659 | + } |
| 660 | + |
| 661 | + getStr() { |
| 662 | + return this._str; |
| 663 | + } |
| 664 | +} |
| 665 | + |
| 666 | +myObject = MyClass("my text"); |
| 667 | + |
| 668 | +module.exports = { |
| 669 | + getStr: myObject.getStr.bind(myObject) |
| 670 | +}; |
| 671 | +``` |
568 | 672 |
|
569 | 673 | ## Cache for Remote Includes
|
570 | 674 |
|
|
0 commit comments