chore(plugin-title): Ported to v3
This commit is contained in:
parent
7b3b26da41
commit
5ce24d49a1
5 changed files with 22 additions and 22 deletions
|
@ -14,7 +14,7 @@ const banner = `/**
|
||||||
const options = {
|
const options = {
|
||||||
banner: { js: banner },
|
banner: { js: banner },
|
||||||
bundle: true,
|
bundle: true,
|
||||||
entryPoints: ['src/index.js'],
|
entryPoints: ['src/index.mjs'],
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
outfile: 'dist/index.mjs',
|
outfile: 'dist/index.mjs',
|
||||||
external: ["@freesewing"],
|
external: ["@freesewing"],
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
"vbuild": "VERBOSE=1 node --experimental-json-modules build.mjs",
|
"vbuild": "VERBOSE=1 node --experimental-json-modules build.mjs",
|
||||||
"lab": "cd ../../sites/lab && yarn start",
|
"lab": "cd ../../sites/lab && yarn start",
|
||||||
"tips": "node ../../scripts/help.mjs",
|
"tips": "node ../../scripts/help.mjs",
|
||||||
"prettier": "npx prettier --write 'src/*.js' 'tests/*.mjs'",
|
"prettier": "npx prettier --write 'src/*.mjs' 'tests/*.mjs'",
|
||||||
"testci": "npx mocha tests/*.test.mjs --reporter ../../tests/reporters/terse.js",
|
"testci": "npx mocha tests/*.test.mjs --reporter ../../tests/reporters/terse.js",
|
||||||
"cibuild_step1": "node --experimental-json-modules build.mjs"
|
"cibuild_step1": "node --experimental-json-modules build.mjs"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import pkg from '../package.json'
|
import { name, version } from '../package.json'
|
||||||
|
|
||||||
const style = `
|
const style = `
|
||||||
text.title-nr {
|
text.title-nr {
|
||||||
|
@ -22,21 +22,17 @@ text.title-pattern {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
export default {
|
export const plugin = {
|
||||||
name: pkg.name,
|
name,
|
||||||
version: pkg.version,
|
version,
|
||||||
hooks: {
|
hooks: {
|
||||||
preRender: (svg) => {
|
preRender: (svg) => {
|
||||||
if (svg.attributes.get('freesewing:plugin-title') === false) {
|
if (svg.style.indexOf(`test.title-nr`) === -1) svg.style += style
|
||||||
svg.attributes.set('freesewing:plugin-title', pkg.version)
|
|
||||||
svg.style += style
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
macros: {
|
macros: {
|
||||||
title: function (so) {
|
title: function (so) {
|
||||||
let prefix = ''
|
const prefix = so.prefix || ''
|
||||||
if (so.prefix) prefix = so.prefix
|
|
||||||
|
|
||||||
// Passing `false` will remove the title
|
// Passing `false` will remove the title
|
||||||
if (so === false) {
|
if (so === false) {
|
||||||
|
@ -111,3 +107,8 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// More specifically named exports
|
||||||
|
export const titlePlugin = plugin
|
||||||
|
export const pluginTitle = plugin
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import chai from 'chai'
|
import chai from 'chai'
|
||||||
import freesewing from '@freesewing/core'
|
import { Pattern } from '@freesewing/core'
|
||||||
import plugin from '../dist/index.mjs'
|
import { plugin } from './dist/index.mjs'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
describe('Title Plugin Tests', () => {
|
describe('Title Plugin Tests', () => {
|
||||||
const pattern = new freesewing.Pattern().use(plugin)
|
const pattern = new Pattern().use(plugin)
|
||||||
pattern.draft().render()
|
pattern.draft().render()
|
||||||
|
|
||||||
it("Should run the title macro", () => {
|
it("Should run the title macro", () => {
|
||||||
let pattern = new freesewing.Pattern({ name: "testPattern", version: 99 });
|
let pattern = new Pattern({ name: "testPattern", version: 99 });
|
||||||
pattern.draft = function() {};
|
pattern.draft = function() {};
|
||||||
pattern.use(plugin);
|
pattern.use(plugin);
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
|
@ -45,7 +45,7 @@ describe('Title Plugin Tests', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should run the title macro with append flag", () => {
|
it("Should run the title macro with append flag", () => {
|
||||||
let pattern = new freesewing.Pattern({ name: "testPattern", version: 99 });
|
let pattern = new Pattern({ name: "testPattern", version: 99 });
|
||||||
pattern.draft = function() {};
|
pattern.draft = function() {};
|
||||||
pattern.use(plugin);
|
pattern.use(plugin);
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
|
@ -73,7 +73,7 @@ describe('Title Plugin Tests', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should run the title macro with point prefix", () => {
|
it("Should run the title macro with point prefix", () => {
|
||||||
let pattern = new freesewing.Pattern({ name: "testPattern", version: 99 });
|
let pattern = new Pattern({ name: "testPattern", version: 99 });
|
||||||
pattern.draft = function() {};
|
pattern.draft = function() {};
|
||||||
pattern.use(plugin);
|
pattern.use(plugin);
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
// This file is auto-generated.
|
// This file is auto-generated | Any changes you make will be overwritten.
|
||||||
// Changes you make will be overwritten.
|
import { plugin } from './dist/index.mjs'
|
||||||
import plugin from './dist/index.mjs'
|
|
||||||
import { sharedPluginTests } from '../../../tests/plugins/shared.mjs'
|
import { sharedPluginTests } from '../../../tests/plugins/shared.mjs'
|
||||||
|
|
||||||
|
|
||||||
// Run shared tests
|
// Run shared tests
|
||||||
sharedPluginTests(plugin)
|
sharedPluginTests(plugin)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue