-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to generate govspeak gem compatible classes
- Loading branch information
1 parent
476a821
commit 13b30dc
Showing
15 changed files
with
171 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const defaultClassNames = require('./class-names').default | ||
const gemCompatibleClassNames = require('./class-names').compatible | ||
|
||
module.exports = function (component) { | ||
const classNames = this.parser.options.govspeakGemCompatibility ? gemCompatibleClassNames : defaultClassNames | ||
|
||
return classNames[component] ?? '' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports.default = { | ||
address: 'govspeak-address h-adr', | ||
button: 'govuk-button', | ||
'button--start': 'govuk-button govuk-button--start', | ||
'call-to-action': 'govspeak-call-to-action', | ||
contact: 'govspeak-contact', | ||
example: 'govspeak-example', | ||
'form-download': 'govspeak-form-download', | ||
'information-callout': 'govspeak-information-callout', | ||
information: 'govspeak-information', | ||
place: 'govspeak-place', | ||
'stat-headline': 'govspeak-stat-headline', | ||
steps: 'govspeak-steps', | ||
'warning-callout': 'govspeak-warning-callout' | ||
} | ||
|
||
module.exports.compatible = { | ||
address: 'address', | ||
button: 'gem-c-button govuk-button', | ||
'button--start': 'gem-c-button govuk-button govuk-button--start', | ||
'call-to-action': 'call-to-action', | ||
contact: 'contact', | ||
example: 'example', | ||
'form-download': 'form-download', | ||
'information-callout': 'application-notice info-notice', | ||
information: 'information', | ||
place: 'place', | ||
'stat-headline': 'stat-headline', | ||
steps: 'steps', | ||
'warning-callout': 'application-notice help-notice' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import test from 'ava' | ||
import { marked } from 'marked' | ||
import govspeak from '../index.js' | ||
|
||
marked.setOptions({ govspeakGemCompatibility: true }) | ||
marked.use({ extensions: govspeak }) | ||
|
||
test('Renders address', t => { | ||
const result = marked('$A\nLine 1 \nLine 2\n$A') | ||
t.is(result, `<address class="address"> | ||
<p>Line 1<br>Line 2</p> | ||
</address>`) | ||
}) | ||
|
||
test('Renders button', t => { | ||
const result = marked('{button}[Click me](https://gov.uk){/button}') | ||
t.is(result, '<p><a class="gem-c-button govuk-button" href="https://gov.uk" role="button">Click me</a></p>\n') | ||
}) | ||
|
||
test('Renders start button', t => { | ||
const result = marked('{button start}[Click me](https://gov.uk){/button}') | ||
t.is(result, '<p><a class="gem-c-button govuk-button govuk-button--start" href="https://gov.uk" role="button">Click me<svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" aria-hidden="true" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"/></svg></a></p>\n') | ||
}) | ||
|
||
test('Renders call to action', t => { | ||
const result = marked('$CTA\nCall to action\n$CTA') | ||
t.is(result, `<div class="call-to-action"> | ||
<p>Call to action</p> | ||
</div>`) | ||
}) | ||
|
||
test('Renders contact', t => { | ||
const result = marked('$C\nPhone \nEmail\n$C') | ||
t.is(result, `<div class="contact"> | ||
<p>Phone<br>Email</p> | ||
</div>`) | ||
}) | ||
|
||
test('Renders form download', t => { | ||
const result = marked('$D\n[Download (PDF, 14KB)](https://example.com/file.pdf)\n$D') | ||
t.is(result, `<div class="form-download"> | ||
<p><a href="https://example.com/file.pdf">Download (PDF, 14KB)</a></p> | ||
</div>`) | ||
}) | ||
|
||
test('Renders example', t => { | ||
const result = marked('$E\nExample\n$E') | ||
t.is(result, `<div class="example"> | ||
<p>Example</p> | ||
</div>`) | ||
}) | ||
|
||
test('Renders information callout', t => { | ||
const result = marked('^information^') | ||
t.is(result, `<div class="application-notice info-notice" role="note" aria-label="Information"> | ||
<p>information</p> | ||
</div>`) | ||
}) | ||
|
||
test('Renders information', t => { | ||
const result = marked('$I\ninformation\n$I') | ||
t.is(result, `<div class="information"> | ||
<p>information</p> | ||
</div>`) | ||
}) | ||
|
||
test('Renders place', t => { | ||
const result = marked('$P\nThis is a place\n$P') | ||
t.is(result, `<div class="place"> | ||
<p>This is a place</p> | ||
</div>`) | ||
}) | ||
|
||
test('Renders stat headline', t => { | ||
const result = marked('{stat-headline}\n*13.8bn* years since the big bang{/stat-headline}') | ||
t.is(result, `<div class="stat-headline"> | ||
<p><em>13.8bn</em> years since the big bang</p> | ||
</div>`) | ||
}) | ||
|
||
test('Renders steps', t => { | ||
const result = marked('s1. Add numbers.\ns2. Check numbers.\ns3. Love numbers.') | ||
t.is(result, `<ol class="steps"> | ||
<li>Add numbers.</li> | ||
<li>Check numbers.</li> | ||
<li>Love numbers.</li> | ||
</ol>`) | ||
}) | ||
|
||
test('Renders warning callout', t => { | ||
const result = marked('%warning%') | ||
t.is(result, `<div class="application-notice help-notice" role="note" aria-label="Warning"> | ||
<p>warning</p> | ||
</div>`) | ||
}) |