easy-template-x 4.1.8 → 5.0.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.
package/README.md CHANGED
@@ -6,6 +6,21 @@ Generate docx documents from templates, in Node or in the browser.
6
6
  [![npm version](https://img.shields.io/npm/v/easy-template-x.svg)](https://www.npmjs.com/package/easy-template-x)
7
7
  [![npm license](https://img.shields.io/npm/l/easy-template-x.svg)](https://www.npmjs.com/package/easy-template-x)
8
8
 
9
+ > ---
10
+ >
11
+ > 🚀 **Looking for a managed solution?**
12
+ >
13
+ > Check out [templatedocs.io](https://templatedocs.io) - a cloud platform for document generation with:
14
+ >
15
+ > ✓ PDF support
16
+ > ✓ REST API integration
17
+ > ✓ Live preview functionality
18
+ > ✓ Easy-to-use UI
19
+ >
20
+ > And more...
21
+ >
22
+ > ---
23
+
9
24
  - [Node Example](#node-example)
10
25
  - [Browser Example](#browser-example)
11
26
  - [Live Demo](#live-demo)
@@ -376,7 +391,7 @@ make it easier to do the actual xml modification.
376
391
 
377
392
  _To better understand the internal structure of Word documents check out [this excellent source](http://officeopenxml.com/WPcontentOverview.php)._
378
393
 
379
- Example plugin implementation ([source](./src/plugins/rawXmlPlugin.ts)):
394
+ Example plugin implementation ([source](./src/plugins/rawXml/rawXmlPlugin.ts)):
380
395
 
381
396
  ```typescript
382
397
  /**
@@ -2494,7 +2494,10 @@ class LoopListStrategy {
2494
2494
  setUtilities(utilities) {
2495
2495
  this.utilities = utilities;
2496
2496
  }
2497
- isApplicable(openTag, closeTag) {
2497
+ isApplicable(openTag, closeTag, isCondition) {
2498
+ if (isCondition) {
2499
+ return false;
2500
+ }
2498
2501
  const containingParagraph = this.utilities.docxParser.containingParagraphNode(openTag.xmlTextNode);
2499
2502
  return this.utilities.docxParser.isListParagraph(containingParagraph);
2500
2503
  }
@@ -2531,7 +2534,7 @@ class LoopParagraphStrategy {
2531
2534
  setUtilities(utilities) {
2532
2535
  this.utilities = utilities;
2533
2536
  }
2534
- isApplicable(openTag, closeTag) {
2537
+ isApplicable(openTag, closeTag, isCondition) {
2535
2538
  return true;
2536
2539
  }
2537
2540
  splitBefore(openTag, closeTag) {
@@ -2606,7 +2609,7 @@ class LoopTableStrategy {
2606
2609
  setUtilities(utilities) {
2607
2610
  this.utilities = utilities;
2608
2611
  }
2609
- isApplicable(openTag, closeTag) {
2612
+ isApplicable(openTag, closeTag, isCondition) {
2610
2613
  const openParagraph = this.utilities.docxParser.containingParagraphNode(openTag.xmlTextNode);
2611
2614
  if (!openParagraph.parentNode) return false;
2612
2615
  if (!this.utilities.docxParser.isTableCellNode(openParagraph.parentNode)) return false;
@@ -2676,7 +2679,7 @@ class LoopPlugin extends TemplatePlugin {
2676
2679
  const closeTag = last(tags);
2677
2680
 
2678
2681
  // select the suitable strategy
2679
- const loopStrategy = this.loopStrategies.find(strategy => strategy.isApplicable(openTag, closeTag));
2682
+ const loopStrategy = this.loopStrategies.find(strategy => strategy.isApplicable(openTag, closeTag, isCondition));
2680
2683
  if (!loopStrategy) throw new Error(`No loop strategy found for tag '${openTag.rawText}'.`);
2681
2684
 
2682
2685
  // prepare to loop
@@ -3083,7 +3086,7 @@ class TemplateHandler {
3083
3086
  /**
3084
3087
  * Version number of the `easy-template-x` library.
3085
3088
  */
3086
- version = "4.1.8" ;
3089
+ version = "5.0.1" ;
3087
3090
  xmlParser = new XmlParser();
3088
3091
  constructor(options) {
3089
3092
  this.options = new TemplateHandlerOptions(options);
@@ -2492,7 +2492,10 @@ class LoopListStrategy {
2492
2492
  setUtilities(utilities) {
2493
2493
  this.utilities = utilities;
2494
2494
  }
2495
- isApplicable(openTag, closeTag) {
2495
+ isApplicable(openTag, closeTag, isCondition) {
2496
+ if (isCondition) {
2497
+ return false;
2498
+ }
2496
2499
  const containingParagraph = this.utilities.docxParser.containingParagraphNode(openTag.xmlTextNode);
2497
2500
  return this.utilities.docxParser.isListParagraph(containingParagraph);
2498
2501
  }
@@ -2529,7 +2532,7 @@ class LoopParagraphStrategy {
2529
2532
  setUtilities(utilities) {
2530
2533
  this.utilities = utilities;
2531
2534
  }
2532
- isApplicable(openTag, closeTag) {
2535
+ isApplicable(openTag, closeTag, isCondition) {
2533
2536
  return true;
2534
2537
  }
2535
2538
  splitBefore(openTag, closeTag) {
@@ -2604,7 +2607,7 @@ class LoopTableStrategy {
2604
2607
  setUtilities(utilities) {
2605
2608
  this.utilities = utilities;
2606
2609
  }
2607
- isApplicable(openTag, closeTag) {
2610
+ isApplicable(openTag, closeTag, isCondition) {
2608
2611
  const openParagraph = this.utilities.docxParser.containingParagraphNode(openTag.xmlTextNode);
2609
2612
  if (!openParagraph.parentNode) return false;
2610
2613
  if (!this.utilities.docxParser.isTableCellNode(openParagraph.parentNode)) return false;
@@ -2674,7 +2677,7 @@ class LoopPlugin extends TemplatePlugin {
2674
2677
  const closeTag = last(tags);
2675
2678
 
2676
2679
  // select the suitable strategy
2677
- const loopStrategy = this.loopStrategies.find(strategy => strategy.isApplicable(openTag, closeTag));
2680
+ const loopStrategy = this.loopStrategies.find(strategy => strategy.isApplicable(openTag, closeTag, isCondition));
2678
2681
  if (!loopStrategy) throw new Error(`No loop strategy found for tag '${openTag.rawText}'.`);
2679
2682
 
2680
2683
  // prepare to loop
@@ -3081,7 +3084,7 @@ class TemplateHandler {
3081
3084
  /**
3082
3085
  * Version number of the `easy-template-x` library.
3083
3086
  */
3084
- version = "4.1.8" ;
3087
+ version = "5.0.1" ;
3085
3088
  xmlParser = new XmlParser();
3086
3089
  constructor(options) {
3087
3090
  this.options = new TemplateHandlerOptions(options);
@@ -3,7 +3,7 @@ import { XmlNode } from '../../../xml';
3
3
  import { PluginUtilities } from '../../templatePlugin';
4
4
  export interface ILoopStrategy {
5
5
  setUtilities(utilities: PluginUtilities): void;
6
- isApplicable(openTag: Tag, closeTag: Tag): boolean;
6
+ isApplicable(openTag: Tag, closeTag: Tag, isCondition: boolean): boolean;
7
7
  splitBefore(openTag: Tag, closeTag: Tag): SplitBeforeResult;
8
8
  mergeBack(compiledNodes: XmlNode[][], firstNode: XmlNode, lastNode: XmlNode): void;
9
9
  }
@@ -5,7 +5,7 @@ import { ILoopStrategy, SplitBeforeResult } from './iLoopStrategy';
5
5
  export declare class LoopListStrategy implements ILoopStrategy {
6
6
  private utilities;
7
7
  setUtilities(utilities: PluginUtilities): void;
8
- isApplicable(openTag: Tag, closeTag: Tag): boolean;
8
+ isApplicable(openTag: Tag, closeTag: Tag, isCondition: boolean): boolean;
9
9
  splitBefore(openTag: Tag, closeTag: Tag): SplitBeforeResult;
10
10
  mergeBack(paragraphGroups: XmlNode[][], firstParagraph: XmlNode, lastParagraphs: XmlNode): void;
11
11
  }
@@ -5,7 +5,7 @@ import { ILoopStrategy, SplitBeforeResult } from './iLoopStrategy';
5
5
  export declare class LoopParagraphStrategy implements ILoopStrategy {
6
6
  private utilities;
7
7
  setUtilities(utilities: PluginUtilities): void;
8
- isApplicable(openTag: Tag, closeTag: Tag): boolean;
8
+ isApplicable(openTag: Tag, closeTag: Tag, isCondition: boolean): boolean;
9
9
  splitBefore(openTag: Tag, closeTag: Tag): SplitBeforeResult;
10
10
  mergeBack(middleParagraphs: XmlNode[][], firstParagraph: XmlNode, lastParagraph: XmlNode): void;
11
11
  }
@@ -5,7 +5,7 @@ import { ILoopStrategy, SplitBeforeResult } from './iLoopStrategy';
5
5
  export declare class LoopTableStrategy implements ILoopStrategy {
6
6
  private utilities;
7
7
  setUtilities(utilities: PluginUtilities): void;
8
- isApplicable(openTag: Tag, closeTag: Tag): boolean;
8
+ isApplicable(openTag: Tag, closeTag: Tag, isCondition: boolean): boolean;
9
9
  splitBefore(openTag: Tag, closeTag: Tag): SplitBeforeResult;
10
10
  mergeBack(rowGroups: XmlNode[][], firstRow: XmlNode, lastRow: XmlNode): void;
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-template-x",
3
- "version": "4.1.8",
3
+ "version": "5.0.1",
4
4
  "description": "Generate docx documents from templates, in Node or in the browser.",
5
5
  "keywords": [
6
6
  "docx",
@@ -41,7 +41,7 @@ export class LoopPlugin extends TemplatePlugin {
41
41
  const closeTag = last(tags);
42
42
 
43
43
  // select the suitable strategy
44
- const loopStrategy = this.loopStrategies.find(strategy => strategy.isApplicable(openTag, closeTag));
44
+ const loopStrategy = this.loopStrategies.find(strategy => strategy.isApplicable(openTag, closeTag, isCondition));
45
45
  if (!loopStrategy)
46
46
  throw new Error(`No loop strategy found for tag '${openTag.rawText}'.`);
47
47
 
@@ -6,7 +6,7 @@ export interface ILoopStrategy {
6
6
 
7
7
  setUtilities(utilities: PluginUtilities): void;
8
8
 
9
- isApplicable(openTag: Tag, closeTag: Tag): boolean;
9
+ isApplicable(openTag: Tag, closeTag: Tag, isCondition: boolean): boolean;
10
10
 
11
11
  splitBefore(openTag: Tag, closeTag: Tag): SplitBeforeResult;
12
12
 
@@ -11,7 +11,11 @@ export class LoopListStrategy implements ILoopStrategy {
11
11
  this.utilities = utilities;
12
12
  }
13
13
 
14
- public isApplicable(openTag: Tag, closeTag: Tag): boolean {
14
+ public isApplicable(openTag: Tag, closeTag: Tag, isCondition: boolean): boolean {
15
+ if (isCondition) {
16
+ return false;
17
+ }
18
+
15
19
  const containingParagraph = this.utilities.docxParser.containingParagraphNode(openTag.xmlTextNode);
16
20
  return this.utilities.docxParser.isListParagraph(containingParagraph);
17
21
  }
@@ -11,7 +11,7 @@ export class LoopParagraphStrategy implements ILoopStrategy {
11
11
  this.utilities = utilities;
12
12
  }
13
13
 
14
- public isApplicable(openTag: Tag, closeTag: Tag): boolean {
14
+ public isApplicable(openTag: Tag, closeTag: Tag, isCondition: boolean): boolean {
15
15
  return true;
16
16
  }
17
17
 
@@ -12,7 +12,7 @@ export class LoopTableStrategy implements ILoopStrategy {
12
12
  this.utilities = utilities;
13
13
  }
14
14
 
15
- public isApplicable(openTag: Tag, closeTag: Tag): boolean {
15
+ public isApplicable(openTag: Tag, closeTag: Tag, isCondition: boolean): boolean {
16
16
  const openParagraph = this.utilities.docxParser.containingParagraphNode(openTag.xmlTextNode);
17
17
  if (!openParagraph.parentNode)
18
18
  return false;