Skip to content

Commit

Permalink
Added support for cssContext
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBackx committed Apr 26, 2024
1 parent 57d1050 commit 5a03f48
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ The plugin has an API consisting of one required parameter and multiple optional
- `webfontsGenerator.templates.scss` – Default SCSS template path. It generates mixin `webfont-icon` to add icon styles. It is safe to use multiple generated files with mixins together.
- See [webfonts-generator#csstemplate](https://github.com/vusion/webfonts-generator#csstemplate)

### cssContext

- See [webfonts-generator#cssContext](https://github.com/vusion/webfonts-generator#cssContext)

### cssFontsUrl

- **type**: `string`
Expand Down
10 changes: 10 additions & 0 deletions src/optionParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,16 @@ describe('optionParser', () => {
expect(resExplicit.cssTemplate).to.eq(cssTemplate);
});

it.concurrent('sets cssContext only if defined in options', () => {
const resDefault = optionParser.parseOptions({ context });
expect('cssContext' in resDefault).to.be.false;
const cssContext = () => {
throw new Error("Shouldn't be called!");
};
const resExplicit = optionParser.parseOptions({ context, cssContext });
expect(resExplicit.cssContext).to.eq(cssContext);
});

it.concurrent('concatenates dest to cssTemplate', () => {
const dest = '/root';
const cssTemplate = 'cssTemplate';
Expand Down
7 changes: 6 additions & 1 deletion src/optionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from 'path';
import { globSync } from 'glob';
import { hasFileExtension } from './utils';
import { InvalidWriteFilesTypeError, NoIconsAvailableError } from './errors';
import type { WebfontsGeneratorOptions, GeneratedFontTypes } from '@vusion/webfonts-generator';
import type { WebfontsGeneratorOptions, GeneratedFontTypes, CSSTemplateContext } from '@vusion/webfonts-generator';

const FILE_TYPE_OPTIONS = ['html', 'css', 'fonts'] as const;
type FileType = (typeof FILE_TYPE_OPTIONS)[number];
Expand Down Expand Up @@ -66,6 +66,10 @@ export interface IconPluginOptions<T extends GeneratedFontTypes = GeneratedFontT
* - `templates.scss` – Default SCSS template path. It generates mixin `webfont-icon` to add icon styles. It is safe to use multiple generated files with mixins together.
*/
cssTemplate?: string;
/**
*
*/
cssContext?: (context: CSSTemplateContext, options: WebfontsGeneratorOptions<T>, handlebars: typeof import('handlebars')) => void;
/**
* Fonts path used in CSS file.
* @default options.cssDest
Expand Down Expand Up @@ -221,6 +225,7 @@ export function parseOptions<T extends GeneratedFontTypes = GeneratedFontTypes>(
cssDest: resolveFileDest(options.dest, options.cssDest, options.fontName, 'css'),
htmlDest: resolveFileDest(options.dest, options.htmlDest, options.fontName, 'html'),
...(options.cssTemplate && { cssTemplate: resolve(options.dest, options.cssTemplate) }),
...(options.cssContext && { cssContext: options.cssContext }),
...(options.cssFontsUrl && { cssFontsUrl: resolve(options.dest, options.cssFontsUrl) }),
...(options.htmlTemplate && { htmlTemplate: resolve(options.dest, options.htmlTemplate) }),
...(typeof options.fixedWidth !== 'undefined' && { fixedWidth: options.fixedWidth }),
Expand Down

0 comments on commit 5a03f48

Please sign in to comment.