Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
@phenomic/plugin-transform-asciidoc: minor tweaks to adjust lint/tests
Browse files Browse the repository at this point in the history
poke @ezralalonde :)
  • Loading branch information
MoOx committed Oct 11, 2017
1 parent 807f296 commit 15cbdf1
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-transform-asciidoc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@phenomic/plugin-transform-asciidoc",
"version": "1.0.0-alpha.10",
"version": "1.0.0-alpha.11",
"publishConfig": {
"access": "public"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Object {
<div class=\\"listingblock\\">
<div class=\\"content\\">
<pre class=\\"highlight\\"><code class=\\"hljs language-javascript\\" data-lang=\\"javascript\\"><span class=\\"hljs-keyword\\">const</span> name = <span class=\\"hljs-string\\">\\"Ezra\\"</span>
<span class=\\"hljs-built_in\\">console</span>.log(<span class=\\"hljs-string\\">\`Hello, nodejs!\`</span>)</code></pre>
<span class=\\"hljs-built_in\\">console</span>.log(<span class=\\"hljs-string\\">\`Hello, <span class=\\"hljs-subst\\">\${name}</span>!\`</span>)</code></pre>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Object {
<div class=\\"listingblock\\">
<div class=\\"content\\">
<pre class=\\"highlight\\"><code class=\\"hljs language-javascript\\" data-lang=\\"javascript\\"><span class=\\"hljs-keyword\\">const</span> name = <span class=\\"hljs-string\\">\\"Ezra\\"</span>
<span class=\\"hljs-built_in\\">console</span>.log(<span class=\\"hljs-string\\">\`Hello, nodejs!\`</span>)</code></pre>
<span class=\\"hljs-built_in\\">console</span>.log(<span class=\\"hljs-string\\">\`Hello, <span class=\\"hljs-subst\\">\${name}</span>!\`</span>)</code></pre>
</div>
</div>
</div>
Expand Down Expand Up @@ -272,7 +272,17 @@ Object {
".log(",
Object {
"c": Array [
"\`Hello, nodejs!\`",
"\`Hello, ",
Object {
"c": Array [
"\${name}",
],
"p": Object {
"className": "hljs-subst",
},
"t": "span",
},
"!\`",
],
"p": Object {
"className": "hljs-string",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-transform-asciidoc/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Test of Asciidoc.js transformer for Phenomic.
[source,javascript]
const name = "Ezra"
console.log(\`Hello, ${name}!\`)
console.log(\`Hello, \${name}!\`)
`)
})
).toMatchSnapshot();
Expand Down
26 changes: 13 additions & 13 deletions packages/plugin-transform-asciidoc/src/__tests__/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import defaultConfig from "@phenomic/core/lib/defaultConfig.js";

import transformer from "../transformer.js";

const input = `
const input = new Buffer(`
= Hello, AsciiDoc!
Ezra Lalonde <[email protected]>
v1.0, 2017-10-05: First Draft
Expand All @@ -18,8 +18,8 @@ Test of Asciidoc.js transformer for Phenomic.
[source,javascript]
const name = "Ezra"
console.log(\`Hello, ${name}!\`)
`;
console.log(\`Hello, \${name}!\`)
`);

it("should render asciidoc as json (react component)", () => {
const adoc = transformer(
Expand All @@ -40,55 +40,55 @@ it("should render asciidoc as html", () => {
it("should have tags", () => {
const adoc = transformer(
defaultConfig,
`
new Buffer(`
= Title
:tags: phenomic, documentation, test, déjà vu
`
`)
);
expect(adoc.tags).toEqual(["phenomic", "documentation", "test", "deja-vu"]);
});

it("should not have tags", () => {
const adoc = transformer(
defaultConfig,
`
new Buffer(`
= Title
`
`)
);
expect(adoc.tags).toEqual([]);
});

it("should use explicit date attribute for date", () => {
const adoc = transformer(
defaultConfig,
`
new Buffer(`
= Title
Ezra Lalonde <[email protected]>
v1.0, 2017-10-05: First Draft
:date: 2011-12-25
`
`)
);
expect(adoc.date).toBe("2011-12-25");
});

it("should use revdate for date", () => {
const adoc = transformer(
defaultConfig,
`
new Buffer(`
= Title
Ezra Lalonde <[email protected]>
v1.0, 2017-10-05: First Draft
`
`)
);
expect(adoc.date).toBe("2017-10-05");
});

it("should use have no date attribute", () => {
const adoc = transformer(
defaultConfig,
`
new Buffer(`
= Title
`
`)
);
expect(adoc.date).toBe(undefined);
});
4 changes: 2 additions & 2 deletions packages/plugin-transform-asciidoc/src/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const envAttributes = [
function processAsciidoc(text) {
const ad = asciidoctor();
const doc = ad.load(text, defaultOptions);
let data = {
const data = {
...doc.attributes.$$smap,
contents: ad.convert(text, defaultOptions)
};
Expand Down Expand Up @@ -83,7 +83,7 @@ const createElement = (component, props, children) => {
};
};

export default (config?: PhenomicConfig, contents: string) => {
export default (config?: PhenomicConfig, contents: Buffer) => {
const data = processAsciidoc(contents);

const processor = unified()
Expand Down

2 comments on commit 15cbdf1

@ezralalonde
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Nice catch on the snapshots.
  2. packages/plugin-transform-asciidoc/src/transformer.js explicitly mutates const data two lines after its definition. Doesn't bother me…
  3. I wasn't sure whether it would be preferable to Buffer-ize the transformer, or toString() the parameter in index.js.

I really appreciate your help/support with this.

LGTM, +1, 👍, 🍻, etc.

@MoOx
Copy link
Owner Author

@MoOx MoOx commented on 15cbdf1 Oct 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For 2. const prevent the variable reference to be changed, and does not ensure that you do not change the value (eg: object, array, etc) so it's safe to be used here (and in fact it has been changed by eslint + the config we use)

Please sign in to comment.