Skip to content

Commit

Permalink
xlsx-renderer v2.3.4 & xlsx-renderer-cli v0.0.5
Browse files Browse the repository at this point in the history
+ lint & format
  • Loading branch information
Siemienik committed Feb 13, 2021
1 parent be07a88 commit d62cb93
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/xlsx-renderer-cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions packages/xlsx-renderer-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sxr",
"version": "0.0.4",
"version": "0.0.5",
"license": "MIT",
"description": "Command line tool for generating XLSX files from a template. Part of XToolset",
"main": "lib/program.js",
Expand Down Expand Up @@ -32,8 +32,7 @@
"lint:fix": "tslint --fix -p tsconfig.json",
"prepublishOnly": "npm run lint && npm run build",
"preversion": "npm run lint",
"version": "npm run format && git add -A ./sxr.ts ./program.ts",
"postversion": "git push && git push --tags"
"version": "npm run format && git add -A ./sxr.ts ./program.ts"
},
"devDependencies": {
"@types/commander": "^2.12.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/xlsx-renderer/.markdownlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"default": true,
"line-length": false,
"no-inline-html": {
"allowed_elements": ["br","details","summary"]
"allowed_elements": ["br","details","summary","code"]
}
}
5 changes: 2 additions & 3 deletions packages/xlsx-renderer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ It is possible to use the command line interface [read more about xlsx-renderer-
| Content | [TemplateStringCell](./src/cell/TemplateStringCell.ts) | 4 | Starts with <code>#` </code> | Template string allows you to create advanced text, for example concat two variables or put them into a sentence. To write in a variable use `${pathToVariable}`. | **Example:**<br/> <code>#` Hello ${name}! How are you?</code> gives for instance `Hello World! How are you?` <br/> [Example](./tests/integration/data/Renderer018-TemplateString)|
| Content | [HyperlinkCell](./src/cell/HyperlinkCell.ts) | 7 | `#! HYPERLINK pathToLabel pathToTarget` | Create a hyperlink. | *Paths resolve exactly same as VariableCell* |
| Content | [FormulaCell](./src/cell/FormulaCell.ts) | 6 | Cell.type eq. formulae | It handles correctly formulas inside and outside of loops - when rows were shifted compared to the template. | *It is used automatically when formulae from the template being rendered* <br/> [Example](./tests/integration/data/Renderer010-Formula)|
| Content | [TemplateFormulaCell](./src/cell/TemplateFormulaCell.ts) | 5 | Starts with `#= ` | This one allows you to put a template string (custom formula) into a cell as a formula. To write in a variable use `${pathToVariable}`. | **Example:**<br/> `#= ${summaryFormula}(A2:A${item.__endOutput.r})` gives something like `=MAX(A2:A2910)` <br/> [Example](./tests/integration/data/Renderer017-TemplateFormula)|
| Content | [TemplateFormulaCell](./src/cell/TemplateFormulaCell.ts) | 5 | Starts with `#=` | This one allows you to put a template string (custom formula) into a cell as a formula. To write in a variable use `${pathToVariable}`. | **Example:**<br/> `#= ${summaryFormula}(A2:A${item.__endOutput.r})` gives something like `=MAX(A2:A2910)` <br/> [Example](./tests/integration/data/Renderer017-TemplateFormula)|
| Navigation | [EndRowCell](./src/cell/EndRowCell.ts) | 2 | `#! END_ROW` | Go to the beginning of next row | |
| Worksheet<br/>Navigation<br/>Loop | [FinishCell](./src/cell/FinishCell.ts) | 9 | `#! FINISH conditionPath` | Finish rendering for current worksheet and: <br/> 1) go to next worksheet if `conditionPath===true`<br/> 2) repeat this template worksheet again (`conditionPath === false`) - looping through worksheets <br/> 3) finished whole rendering when this worksheet is the last one. | **Examples:**<br/> `#! FINISHED` or `#! FINISHED itemFromLoop.__iterated` |
| Worksheet | [WsNameCell](./src/cell/WsNameCell.ts) | 15 | `#! WS_NAME pathToVariable` | Set worksheet's name. | **Examples:** <br/> `#! WS_NAME worksheetName` <br/> `#! WS_NAME item.title` <br/> `#! WS_NAME translatedNames.0` |
Expand Down Expand Up @@ -111,7 +111,6 @@ _These examples might be runned by using the command line tool, [read more](../x
| 17 | [TemplateFormulaCell](./tests/integration/data/Renderer017-TemplateFormulaCell) | Dynamic formula creation |
| 18 | [TemplateStringCell](./tests/integration/data/Renderer018-TemplateStringCell) | Dynamic content creation following by custom template string (`Hello ${name}`). |


## Support

If any help needed, just feel free to create an issue. We will be really thankful for added links into stackoverflow topics if exists.
Expand All @@ -126,7 +125,7 @@ We are ready to provide paid support, in order that please contact me: [hi@siemi

If Node v8 & v9 needed, please contact us [support@siemienik.pl](mailto://support@siemienik.pl).

### ✅ Browser Support
### ✅ Browser Support

XLSX Renderer may run on browser side, [read more how to do it](https://github.com/Siemienik/XToolSet/issues/93).

Expand Down
2 changes: 1 addition & 1 deletion packages/xlsx-renderer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions packages/xlsx-renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xlsx-renderer",
"version": "2.3.5",
"version": "2.4.0",
"description": "Allows render spreadsheet (xlsx) files based on the template supplied by indeed viewModel.",
"main": "lib/Renderer.js",
"types": "lib/Renderer.d.ts",
Expand Down Expand Up @@ -39,8 +39,7 @@
"coverageReport": "nyc -r lcov -r=text -r=text-summary -r=json -e .ts -x \"*.test.ts\" mocha -r ts-node/register tests/**/*.test.ts tests/**/**/*.test.ts && nyc report && cp coverage/coverage-final.json coverage/coverage.json",
"prepublishOnly": "npm test && npm run lint && npm run build",
"preversion": "npm run lint",
"version": "npm run format && git add -A src",
"postversion": "git push && git push --tags"
"version": "npm run format && git add -A src"
},
"devDependencies": {
"@types/chai": "^4.1.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/xlsx-renderer/src/cell/NormalCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class NormalCell extends BaseCell {
cell &&
cell.type === ValueType.String &&
typeof cell.value === 'string' &&
!['##', '#!', "#=", '#`'].includes(cell.value.substring(0, 2)) // todo documentation: describe prefixes in a documentation
!['##', '#!', '#=', '#`'].includes(cell.value.substring(0, 2)) // todo documentation: describe prefixes in a documentation
);
}

Expand Down
17 changes: 6 additions & 11 deletions packages/xlsx-renderer/src/cell/TemplateFormulaCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class TemplateFormulaCell extends BaseCell {
public static match(cell: Cell): boolean {
return (
cell &&
cell.type === ValueType. String &&
cell.type === ValueType.String &&
(cell.isMerged ? cell.master.address === cell.address : true) &&
typeof cell.value === 'string' &&
cell.value.substring(0, 3) === '#= '
Expand All @@ -23,11 +23,9 @@ export class TemplateFormulaCell extends BaseCell {
public apply(scope: Scope): TemplateFormulaCell {
super.apply(scope);

const template = scope
.getCurrentTemplateString()
.substring(3);
const template = scope.getCurrentTemplateString().substring(3);

const formula = template.replace(variableRegex, (match) => {
const formula = template.replace(variableRegex, match => {
const path = match.slice(2, -1).split('.');

// todo refactoring extract, similar like in VariableCell
Expand All @@ -36,18 +34,15 @@ export class TemplateFormulaCell extends BaseCell {
// todo do it better (use logger or something like that)
// tslint:disable-next-line:no-console
console.warn(
`WARN: ${path} is undefined for template formula output: ${
JSON.stringify(scope.outputCell)
} when template is:${
JSON.stringify(scope.templateCell)
}`
`WARN: ${path} is undefined for template formula output: ${JSON.stringify(
scope.outputCell,
)} when template is:${JSON.stringify(scope.templateCell)}`,
);
}

return value;
});


scope.setCurrentOutputValue({ formula } as CellFormulaValue);
scope.incrementCol();

Expand Down
14 changes: 5 additions & 9 deletions packages/xlsx-renderer/src/cell/TemplateStringCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ export class TemplateStringCell extends BaseCell {
public apply(scope: Scope): TemplateStringCell {
super.apply(scope);

const template = scope
.getCurrentTemplateString()
.substring(3);
const template = scope.getCurrentTemplateString().substring(3);

const result = template.replace(variableRegex, (match) => {
const result = template.replace(variableRegex, match => {
const path = match.slice(2, -1).split('.');

// todo refactoring extract, similar like in VariableCell
Expand All @@ -36,11 +34,9 @@ export class TemplateStringCell extends BaseCell {
// todo do it better (use logger or something like that)
// tslint:disable-next-line:no-console
console.warn(
`WARN: ${path} is undefined for template string output: ${
JSON.stringify(scope.outputCell)
} when template is:${
JSON.stringify(scope.templateCell)
}`
`WARN: ${path} is undefined for template string output: ${JSON.stringify(
scope.outputCell,
)} when template is:${JSON.stringify(scope.templateCell)}`,
);
}

Expand Down

0 comments on commit d62cb93

Please sign in to comment.