Skip to content

Commit

Permalink
v0.0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvianen committed Jan 3, 2024
1 parent 8fbfb49 commit e9d98a7
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 14 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.14
0.0.15
2 changes: 1 addition & 1 deletion dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pack.gl",
"version": "0.0.14",
"version": "0.0.15",
"description": "Package Builder.",
"keywords": [
"pack.gl",
Expand Down
99 changes: 99 additions & 0 deletions dist/ts/class/TemplateWriter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// class/TemplateWriter.ts

// Copyright 2023 Scape Agency BV

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


// ============================================================================
// Import
// ============================================================================

import fs from 'fs/promises';
import path from 'path';
import nunjucks from 'nunjucks';


// ============================================================================
// Classes
// ============================================================================

class TemplateWriter {

/**
* Constructs a TemplateWriter instance.
* @param templatesDir - Directory for Nunjucks templates.
* @param enableCache - Enable or disable caching for Nunjucks.
*/
constructor(
templatesDir: string,
enableCache: boolean = false
) {
nunjucks.configure(templatesDir, {
autoescape: true,
noCache: !enableCache
});
}

/**
* Generates a template using the provided template file and context.
* @param template - The template file name.
* @param context - Context data to render the template with.
* @returns The rendered template as a string.
*/
async generateTemplate(template: string, context: {}): Promise<string> {
try {
// const formattedColors = this.formatColorsForTemplate();
// return nunjucks.render(template, { colors: formattedColors });
return nunjucks.render(
template,
context,
);
} catch (error) {
console.error(`Error generating template: ${error}`);
// throw error;
throw new Error('Template generation failed');

}
}

/**
* Writes the rendered template content to a file.
* @param template - The template file name.
* @param outputFile - The output file path.
* @param context - Context data to render the template with.
*/
async generateToFile(template: string, outputFile: string, context: {}): Promise<void> {
try {
const content = await this.generateTemplate(template, context);
const dir = path.dirname(outputFile);

// Ensure the directory exists
await fs.mkdir(dir, { recursive: true });

// Write the file
await fs.writeFile(outputFile, content, 'utf-8');
} catch (error) {
console.error(`Error writing to file: ${error}`);
throw new Error('File writing failed');
}
}

}


// ============================================================================
// Export
// ============================================================================

export default TemplateWriter;
44 changes: 44 additions & 0 deletions dist/ts/config/nunjucks.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// config/nunjucks.config.ts

// Copyright 2023 Scape Agency BV

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


// ============================================================================
// Import
// ============================================================================

import path from 'node:path'


// ============================================================================
// Constants
// ============================================================================

const nunjucksConfig = {

autoescape: true, // Controls if output with dangerous characters are escaped automatically
throwOnUndefined: false, // Throw errors when outputting a null/undefined value
trimBlocks: true, // Automatically remove trailing newlines from a block/tag
lstripBlocks: true, // Automatically remove leading whitespace from a block/tag
// noCache: !enableCache

};


// ============================================================================
// Export
// ============================================================================

export default nunjucksConfig;
20 changes: 10 additions & 10 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"icon.gl": "^0.0.1",
"loop.gl": "^0.0.1",
"mini-css-extract-plugin": "^2.7.6",
"pack.gl": "^0.0.13",
"pack.gl": "^0.0.15",
"page.gl": "^0.0.1",
"postcss-loader": "^7.3.3",
"postcss-preset-env": "^9.1.2",
Expand All @@ -103,7 +103,7 @@
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"typescript": "^5.3.3",
"unit.gl": "^0.0.24",
"unit.gl": "^0.0.25",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
Expand Down
99 changes: 99 additions & 0 deletions src/ts/class/TemplateWriter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// class/TemplateWriter.ts

// Copyright 2023 Scape Agency BV

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


// ============================================================================
// Import
// ============================================================================

import fs from 'fs/promises';
import path from 'path';
import nunjucks from 'nunjucks';


// ============================================================================
// Classes
// ============================================================================

class TemplateWriter {

/**
* Constructs a TemplateWriter instance.
* @param templatesDir - Directory for Nunjucks templates.
* @param enableCache - Enable or disable caching for Nunjucks.
*/
constructor(
templatesDir: string,
enableCache: boolean = false
) {
nunjucks.configure(templatesDir, {
autoescape: true,
noCache: !enableCache
});
}

/**
* Generates a template using the provided template file and context.
* @param template - The template file name.
* @param context - Context data to render the template with.
* @returns The rendered template as a string.
*/
async generateTemplate(template: string, context: {}): Promise<string> {
try {
// const formattedColors = this.formatColorsForTemplate();
// return nunjucks.render(template, { colors: formattedColors });
return nunjucks.render(
template,
context,
);
} catch (error) {
console.error(`Error generating template: ${error}`);
// throw error;
throw new Error('Template generation failed');

}
}

/**
* Writes the rendered template content to a file.
* @param template - The template file name.
* @param outputFile - The output file path.
* @param context - Context data to render the template with.
*/
async generateToFile(template: string, outputFile: string, context: {}): Promise<void> {
try {
const content = await this.generateTemplate(template, context);
const dir = path.dirname(outputFile);

// Ensure the directory exists
await fs.mkdir(dir, { recursive: true });

// Write the file
await fs.writeFile(outputFile, content, 'utf-8');
} catch (error) {
console.error(`Error writing to file: ${error}`);
throw new Error('File writing failed');
}
}

}


// ============================================================================
// Export
// ============================================================================

export default TemplateWriter;
44 changes: 44 additions & 0 deletions src/ts/config/nunjucks.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// config/nunjucks.config.ts

// Copyright 2023 Scape Agency BV

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


// ============================================================================
// Import
// ============================================================================

import path from 'node:path'


// ============================================================================
// Constants
// ============================================================================

const nunjucksConfig = {

autoescape: true, // Controls if output with dangerous characters are escaped automatically
throwOnUndefined: false, // Throw errors when outputting a null/undefined value
trimBlocks: true, // Automatically remove trailing newlines from a block/tag
lstripBlocks: true, // Automatically remove leading whitespace from a block/tag
// noCache: !enableCache

};


// ============================================================================
// Export
// ============================================================================

export default nunjucksConfig;

0 comments on commit e9d98a7

Please sign in to comment.