Skip to content

Commit 434a18a

Browse files
committed
Remove 'use' prefix from options to match CLI
1 parent 0df8761 commit 434a18a

File tree

8 files changed

+46
-43
lines changed

8 files changed

+46
-43
lines changed

CHANGELOG.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7-
## [3.1.0] - 2019-05-14
7+
## [4.0.0] - 2019-05-14
88
### Added
9-
- Option `useDoubleQuotes` for attribute values
9+
- Option `doubleQuotes` for attribute values
1010
- Option `commas` to CLI
1111
- Travis CI file
1212

1313
### Changed
1414
- Refactored cli.js
15+
- Option `useTabs` to `tabs` (**BREAKING CHANGE**)
16+
- Option `useCommas` to `commas` (**BREAKING CHANGE**)
17+
- Option `isFragment` to `fragment` (**BREAKING CHANGE**)
1518

1619
## [3.0.0] - 2019-04-07
1720
### Changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ See `html2pug --help` for more information.
6363
const html2pug = require('html2pug')
6464

6565
const html = '<header><h1 class="title">Hello World!</h1></header>'
66-
const pug = html2pug(html, { useTabs: true })
66+
const pug = html2pug(html, { tabs: true })
6767
```
6868

6969
### Options
7070

7171
Name | Type | Default | Description
7272
--- | --- | --- | ---
73-
`useTabs` | `Boolean` | `false` | Use tabs instead of spaces
74-
`useCommas` | `Boolean` | `true` | Use commas to separate node attributes
75-
`useDoubleQuotes` | `Boolean` | `false` | Use double quotes instead of single quotes for attribute values
76-
`isFragment` | `Boolean` | `false` | Wraps result in enclosing `<html>` and `<body>` tags if false
73+
`tabs` | `Boolean` | `false` | Use tabs instead of spaces for indentation
74+
`commas` | `Boolean` | `true` | Use commas to separate node attributes
75+
`doubleQuotes` | `Boolean` | `false` | Use double quotes instead of single quotes for attribute values
76+
`fragment` | `Boolean` | `false` | Wraps result in enclosing `<html>` and `<body>` tags if false

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html2pug",
3-
"version": "3.1.0",
3+
"version": "4.0.0",
44
"description": "Converts HTML to Pug",
55
"main": "src/index.js",
66
"bin": {

src/cli.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ if (hasFlag('v') || hasFlag('version')) {
5858
}
5959

6060
const options = {
61-
isFragment: hasFlag('f') || hasFlag('fragment'),
62-
useTabs: hasFlag('t') || hasFlag('tabs'),
63-
useCommas: hasFlag('c') || hasFlag('commas'),
64-
useDoubleQuotes: hasFlag('d') || hasFlag('double-quotes'),
61+
fragment: hasFlag('f') || hasFlag('fragment'),
62+
tabs: hasFlag('t') || hasFlag('tabs'),
63+
commas: hasFlag('c') || hasFlag('commas'),
64+
doubleQuotes: hasFlag('d') || hasFlag('double-quotes'),
6565
}
6666

6767
convert(options)

src/index.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ const Pugify = require('./parser')
44

55
const defaultOptions = {
66
// html2pug options
7-
isFragment: false,
8-
useTabs: false,
9-
useCommas: true,
10-
useDoubleQuotes: false,
7+
fragment: false,
8+
tabs: false,
9+
commas: true,
10+
doubleQuotes: false,
1111

1212
// html-minifier options
1313
caseSensitive: true,
@@ -22,14 +22,14 @@ module.exports = (sourceHtml, options = {}) => {
2222
const opts = { ...defaultOptions, ...options }
2323
const html = minify(sourceHtml, opts)
2424

25-
const { isFragment, useTabs, useCommas, useDoubleQuotes } = opts
25+
const { fragment, tabs, commas, doubleQuotes } = opts
2626

2727
// Parse HTML and convert to Pug
28-
const documentRoot = isFragment ? parseFragment(html) : parse(html)
29-
const pugify = new Pugify(documentRoot, {
30-
useTabs,
31-
useCommas,
32-
useDoubleQuotes,
28+
const doc = fragment ? parseFragment(html) : parse(html)
29+
const pugify = new Pugify(doc, {
30+
tabs,
31+
commas,
32+
doubleQuotes,
3333
})
3434
return pugify.parse()
3535
}

src/parser.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ class Parser {
1717
this.pug = ''
1818
this.root = root
1919

20-
const { useTabs, useCommas, useDoubleQuotes } = options
20+
const { tabs, commas, doubleQuotes } = options
2121

2222
// Tabs or spaces
23-
this.indentStyle = useTabs ? '\t' : ' '
23+
this.indentStyle = tabs ? '\t' : ' '
2424
// Comma separate attributes
25-
this.separatorStyle = useCommas ? ', ' : ' '
25+
this.separatorStyle = commas ? ', ' : ' '
2626
// Single quotes or double
27-
this.quoteStyle = useDoubleQuotes ? '"' : "'"
27+
this.quoteStyle = doubleQuotes ? '"' : "'"
2828
}
2929

3030
getIndent(level = 0) {

test.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ html(lang='en')
2828
t.is(generated, pug)
2929
})
3030

31-
test('result contains no outer html element when isFragment is truthy', t => {
32-
const generated = html2pug('<h1>Hello World!</h1>', { isFragment: true })
31+
test('result contains no outer html element when fragment is truthy', t => {
32+
const generated = html2pug('<h1>Hello World!</h1>', { fragment: true })
3333
t.falsy(generated.startsWith('html'))
3434
})
3535

@@ -82,15 +82,15 @@ test('creates multiline block when linebreaks are present', t => {
8282
line
8383
string`
8484

85-
const generated = html2pug(html, { isFragment: true })
85+
const generated = html2pug(html, { fragment: true })
8686
t.is(generated, pug)
8787
})
8888

8989
test('uses div tag shorthand when id/class is present', t => {
9090
const html = "<div id='foo' class='bar'>baz</div>"
9191
const pug = '#foo.bar baz'
9292

93-
const generated = html2pug(html, { isFragment: true })
93+
const generated = html2pug(html, { fragment: true })
9494
t.is(generated, pug)
9595
})
9696

@@ -111,23 +111,23 @@ test('removes whitespace between HTML elements', t => {
111111
li three
112112
li four`
113113

114-
const generated = html2pug(html, { isFragment: true })
114+
const generated = html2pug(html, { fragment: true })
115115
t.is(generated, pug)
116116
})
117117

118118
test('does not fail on unicode characters', t => {
119119
const generated = html2pug('<h1 class="accents">â, é, ï, õ, ù</h1>', {
120-
isFragment: true,
120+
fragment: true,
121121
})
122122
const expected = 'h1.accents â, é, ï, õ, ù'
123123

124124
t.is(generated, expected)
125125
})
126126

127-
test('uses tabs when useTabs is truthy', t => {
127+
test('uses tabs when tabs is truthy', t => {
128128
const generated = html2pug('<div><span>Tabs!</span></div>', {
129-
isFragment: true,
130-
useTabs: true,
129+
fragment: true,
130+
tabs: true,
131131
})
132132
const expected = 'div\n\tspan Tabs!'
133133

@@ -136,7 +136,7 @@ test('uses tabs when useTabs is truthy', t => {
136136

137137
test('uses a comma to separate attributes', t => {
138138
const generated = html2pug('<input type="text" name="foo" />', {
139-
isFragment: true,
139+
fragment: true,
140140
})
141141
const expected = "input(type='text', name='foo')"
142142

@@ -145,8 +145,8 @@ test('uses a comma to separate attributes', t => {
145145

146146
test('uses a space to separate attributes', t => {
147147
const generated = html2pug('<input type="text" name="foo" />', {
148-
isFragment: true,
149-
useCommas: false,
148+
fragment: true,
149+
commas: false,
150150
})
151151
const expected = "input(type='text' name='foo')"
152152

@@ -155,8 +155,8 @@ test('uses a space to separate attributes', t => {
155155

156156
test('uses double quotes for attribute values', t => {
157157
const generated = html2pug('<input type="text" name="foo" />', {
158-
isFragment: true,
159-
useDoubleQuotes: true,
158+
fragment: true,
159+
doubleQuotes: true,
160160
})
161161
const expected = 'input(type="text", name="foo")'
162162

@@ -167,7 +167,7 @@ test('single quotes in attribute values are escaped', t => {
167167
const generated = html2pug(
168168
`<button aria-label="closin&apos;" onclick="window.alert('bye')">close</button>`,
169169
{
170-
isFragment: true,
170+
fragment: true,
171171
}
172172
)
173173
const expected = `button(aria-label='closin\\'', onclick='window.alert(\\'bye\\')') close`
@@ -178,7 +178,7 @@ test('single quotes in attribute values are escaped', t => {
178178
test('collapses boolean attributes', t => {
179179
const generated = html2pug(
180180
`<input type="text" name="foo" disabled="disabled" readonly="readonly" />`,
181-
{ isFragment: true }
181+
{ fragment: true }
182182
)
183183
const expected = `input(type='text', name='foo', disabled, readonly)`
184184

0 commit comments

Comments
 (0)