Skip to content
This repository was archived by the owner on Jun 6, 2022. It is now read-only.

Commit 2c8f253

Browse files
committed
4.0.0
1 parent 084eeca commit 2c8f253

File tree

6 files changed

+121
-73
lines changed

6 files changed

+121
-73
lines changed

.eslintrc

+17-11
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,26 @@ env:
77
browser: true
88
node: true
99

10-
# 0: off, 1: warning, 2: error
1110
rules:
12-
# semicolons are useless
13-
semi: [2, "never"]
14-
11+
indent: [2, 2] # 2 spaces indentation
12+
max-len: [2, 80, 4]
1513
quotes: [2, "double"]
14+
semi: [2, "never"]
15+
no-multiple-empty-lines: [2, {"max": 1}]
1616

17-
# 2 spaces indentation
18-
indent: [2, 2]
19-
20-
# trailing coma are cool for diff
17+
brace-style: [2, "stroustrup"]
2118
comma-dangle: [2, "always-multiline"]
22-
23-
# enforce comma at eol (never before)
2419
comma-style: [2, "last"]
20+
computed-property-spacing: [2, "never"]
21+
dot-location: [2, "property"]
22+
23+
one-var: [2, "never"]
24+
no-bitwise: [2]
2525

26-
valid-jsdoc: 2
26+
object-shorthand: [2, "methods"]
27+
space-after-keywords: [2, "always"]
28+
space-before-blocks: [2, "always"]
29+
space-before-function-paren: [2, "never"]
30+
space-in-brackets: [2, "never"]
31+
space-in-parens: [2, "never"]
32+
spaced-line-comment: [2, "always"]

CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# 4.0.0 - Unrelease
1+
# 4.0.0 - 2015-05-17
22

3-
- Changed: warning messages are not sent via postcss API (^4.1.0)
3+
- Changed: warning messages are now sent via postcss messages api (^4.1.0)
4+
- Added: automatic custom media `--` prefixing
5+
([#11](https://github.com/postcss/postcss-custom-media/issues/11))
46
- Added: `preserve` allows you to preserve custom media query defintions
57
- Added: `appendExtensions` allows you (when `preserve` is truthy) to append your extensions as media queries
68

README.md

+15-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
55
## Installation
66

7-
$ npm install postcss-custom-media
7+
```console
8+
$ npm install postcss-custom-media
9+
```
810

911
## Usage
1012

@@ -45,28 +47,27 @@ Checkout [tests](test) for more examples.
4547

4648
### Options
4749

48-
#### `extensions` (default: `{}`)
50+
#### `extensions`
4951

50-
Allows you to pass an object to define the `<media-query-list>` for each `<extension-name>`. These definitions will override any that exist in the CSS.
52+
(default: `{}`)
5153

52-
#### `preserve` (default: `false`)
54+
Allows you to pass an object to define the `<media-query-list>` for each
55+
`<extension-name>`. These definitions will override any that exist in the CSS.
5356

54-
Allows you to preserve custom media query definitions in output.
57+
#### `preserve`
5558

56-
#### `appendExtensions` (default: `false`)
59+
(default: `false`)
5760

58-
If `preserve` is set to `true`, allows you to append your extensions at end of your CSS.
61+
Allows you to preserve custom media query definitions in output.
5962

60-
---
63+
#### `appendExtensions`
6164

62-
## Contributing
65+
(default: `false`)
6366

64-
Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature.
67+
**This option only works if `preserve` is truthy**.
68+
Allows you to append your extensions at end of your CSS.
6569

66-
$ git clone https://github.com/postcss/postcss-custom-media.git
67-
$ git checkout -b patch-1
68-
$ npm install
69-
$ npm test
70+
---
7071

7172
## [Changelog](CHANGELOG.md)
7273

index.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
/**
2-
* Module dependencies
3-
*/
41
var postcss = require("postcss")
52

6-
/**
7-
* Constants.
8-
*/
93
var EXTENSION_RE = /\(\s*(--[\w-]+)\s*\)/g
104

11-
/**
12-
* Expose the plugin.
13-
*/
14-
module.exports = postcss.plugin("postcss-custom-media", customMedia)
15-
165
/*
176
* read & replace custom media queries by standard media queries
187
*/
@@ -66,7 +55,11 @@ function customMedia(options) {
6655
return map[name]
6756
}
6857

69-
result.warn("Missing @custom-media definition for '" + name + "'. The entire rule has been removed from the output.", {node: rule})
58+
result.warn(
59+
"Missing @custom-media definition for '" + name +
60+
"'. The entire rule has been removed from the output.",
61+
{node: rule}
62+
)
7063
toRemove.push(rule)
7164
})
7265
})
@@ -88,6 +81,10 @@ function customMedia(options) {
8881
}
8982

9083
// remove @custom-media
91-
toRemove.forEach(function(rule) { rule.removeSelf() })
84+
toRemove.forEach(function(rule) {
85+
rule.removeSelf()
86+
})
9287
}
9388
}
89+
90+
module.exports = postcss.plugin("postcss-custom-media", customMedia)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"postcss": "^4.1.4"
2525
},
2626
"devDependencies": {
27-
"eslint": "^0.18.0",
27+
"eslint": "^0.23.0",
2828
"tape": "^4.0.0"
2929
},
3030
"scripts": {

test/index.js

+74-32
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ var test = require("tape")
55
var postcss = require("postcss")
66
var plugin = require("..")
77

8-
function filename(name) { return "test/" + name + ".css" }
9-
function read(name) { return fs.readFileSync(name, "utf8") }
8+
function filename(name) {
9+
return "test/" + name + ".css"
10+
}
11+
function read(name) {
12+
return fs.readFileSync(name, "utf8")
13+
}
1014

1115
function compareFixtures(t, name, msg, opts, postcssOpts) {
1216
postcssOpts = postcssOpts || {}
1317
postcssOpts.from = filename("fixtures/" + name)
1418
opts = opts || {}
15-
var result = postcss().use(plugin(opts)).process(read(postcssOpts.from), postcssOpts)
19+
var result = postcss()
20+
.use(plugin(opts))
21+
.process(read(postcssOpts.from), postcssOpts)
1622
var actual = result.css
1723
var expected = read(filename("fixtures/" + name + ".expected"))
1824
fs.writeFile(filename("fixtures/" + name + ".actual"), actual)
@@ -22,35 +28,71 @@ function compareFixtures(t, name, msg, opts, postcssOpts) {
2228
}
2329

2430
test("@custom-media", function(t) {
25-
compareFixtures(t, "transform", "should transform custom media")
26-
27-
compareFixtures(t, "transform-all", "should replaces all extension names")
28-
29-
var undefinedRes = compareFixtures(t, "undefined", "should remove undefined @media")
30-
t.ok(undefinedRes.warnings()[0].text.match(/Missing @custom-media/), "should send warning to postcss")
31-
32-
compareFixtures(t, "js-defined", "should transform custom media and override local extensions", {
33-
extensions: {
34-
"--viewport-max-s": "(max-width: 30em)",
35-
"--viewport-min-s": "(min-width: 30.01em)",
36-
},
37-
})
38-
39-
compareFixtures(t, "js-defined", "should transform custom media and override local unprefixed extensions", {
40-
extensions: {
41-
"viewport-max-s": "(max-width: 30em)",
42-
"viewport-min-s": "(min-width: 30.01em)",
43-
},
44-
})
45-
46-
compareFixtures(t, "preserve", "should preserve custom media", {preserve: true})
47-
48-
compareFixtures(t, "append", "should append custom media", {
49-
extensions: {
50-
"--viewport-max-s": "(max-width: 30em)",
51-
},
52-
appendExtensions: true,
53-
})
31+
compareFixtures(
32+
t,
33+
"transform",
34+
"should transform custom media"
35+
)
36+
37+
compareFixtures(
38+
t,
39+
"transform-all",
40+
"should replaces all extension names"
41+
)
42+
43+
var undefinedRes = compareFixtures(
44+
t,
45+
"undefined",
46+
"should remove undefined @media"
47+
)
48+
49+
t.ok(
50+
undefinedRes.warnings()[0].text.match(/Missing @custom-media/),
51+
"should send warning to postcss"
52+
)
53+
54+
compareFixtures(
55+
t,
56+
"js-defined",
57+
"should transform custom media and override local extensions",
58+
{
59+
extensions: {
60+
"--viewport-max-s": "(max-width: 30em)",
61+
"--viewport-min-s": "(min-width: 30.01em)",
62+
},
63+
}
64+
)
65+
66+
compareFixtures(
67+
t,
68+
"js-defined",
69+
"should transform custom media and override local unprefixed extensions",
70+
{
71+
extensions: {
72+
"viewport-max-s": "(max-width: 30em)",
73+
"viewport-min-s": "(min-width: 30.01em)",
74+
},
75+
}
76+
)
77+
78+
compareFixtures(
79+
t,
80+
"preserve",
81+
"should preserve custom media",
82+
{preserve: true}
83+
)
84+
85+
compareFixtures(
86+
t,
87+
"append",
88+
"should append custom media",
89+
{
90+
extensions: {
91+
"--viewport-max-s": "(max-width: 30em)",
92+
},
93+
appendExtensions: true,
94+
}
95+
)
5496

5597
t.end()
5698
})

0 commit comments

Comments
 (0)