Skip to content

Commit f67665f

Browse files
committed
Merge master, fix conflicts
2 parents fd95c5d + b14d279 commit f67665f

File tree

8 files changed

+104
-59
lines changed

8 files changed

+104
-59
lines changed

__tests__/applyClassPrefix.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import postcss from 'postcss'
2+
import applyClassPrefix from '../src/util/applyClassPrefix'
3+
4+
test('it prefixes classes with the provided prefix', () => {
5+
const input = postcss.parse(`
6+
.foo { color: red; }
7+
.apple, .pear { color: green; }
8+
`)
9+
10+
const expected = `
11+
.tw-foo { color: red; }
12+
.tw-apple, .tw-pear { color: green; }
13+
`
14+
15+
const result = applyClassPrefix(input, 'tw-').toResult()
16+
expect(result.css).toEqual(expected)
17+
expect(result.warnings().length).toBe(0)
18+
})

docs/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"scripts": {
3-
"local": "cross-env NODE_ENV=development webpack --progress --hide-modules --env=local --config=node_modules/laravel-mix/setup/webpack.config.js",
4-
"staging": "cross-env NODE_ENV=development webpack --progress --hide-modules --env=staging --config=node_modules/laravel-mix/setup/webpack.config.js",
5-
"production": "cross-env NODE_ENV=development webpack --progress --hide-modules --env=production --config=node_modules/laravel-mix/setup/webpack.config.js",
6-
"dev": "npm run local",
3+
"development": "cross-env NODE_ENV=development webpack --progress --hide-modules --env=local --config=node_modules/laravel-mix/setup/webpack.config.js",
4+
"production": "cross-env NODE_ENV=production webpack --progress --hide-modules --env=production --config=node_modules/laravel-mix/setup/webpack.config.js",
5+
"dev": "npm run development",
76
"prod": "npm run production",
8-
"watch": "npm run local -- --watch"
7+
"watch": "npm run development -- --watch"
98
},
109
"private": true,
1110
"devDependencies": {

docs/source/_layouts/documentation.blade.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,17 @@
115115
</defs>
116116
</svg>
117117
@endsection
118+
119+
@push('scripts')
120+
@if ($page->production)
121+
<!-- Algolia DocSearch -->
122+
<script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script>
123+
<script type="text/javascript">
124+
docsearch({
125+
apiKey: '3df93446658cd9c4e314d4c02a052188',
126+
indexName: 'tailwindcss',
127+
inputSelector: '#docsearch',
128+
});
129+
</script>
130+
@endif
131+
@endpush

docs/source/_layouts/master.blade.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@
2525
@yield('body')
2626

2727
@if ($page->production)
28-
<!-- Algolia DocSearch -->
29-
<script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script>
30-
<script type="text/javascript">
31-
docsearch({
32-
apiKey: '3df93446658cd9c4e314d4c02a052188',
33-
indexName: 'tailwindcss',
34-
inputSelector: '#docsearch',
35-
});
36-
</script>
37-
3828
<!-- Google Analytics -->
3929
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-109068504-1"></script>
4030
<script>
@@ -46,5 +36,7 @@ function gtag(){dataLayer.push(arguments);}
4636
</script>
4737
@endif
4838

39+
@stack('scripts')
40+
4941
</body>
5042
</html>

docs/source/docs/functions-and-directives.blade.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Tailwind exposes a few custom CSS functions and directives that can be used in y
88

99
### `@@tailwind`
1010

11-
Use the `@@tailwind` directive to insert Tailwind's `preflight`, `utilities` and `screen` styles into your CSS. Here's a full example of how you might do this:
11+
Use the `@@tailwind` directive to insert Tailwind's `preflight`, `utilities` and `screens` styles into your CSS. Here's a full example of how you might do this:
1212

1313
```less
1414
/**
@@ -27,9 +27,11 @@ Use the `@@tailwind` directive to insert Tailwind's `preflight`, `utilities` and
2727
@@tailwind utilities;
2828

2929
/**
30-
* (Optional)
31-
* This injects the utility classes and styles wrapped by the @@responsive directive.
32-
* These will be appended at the end of the stylesheet if the `@@tailwind screens` directive is not used.
30+
* Use this directive to control where Tailwind injects the responsive
31+
* variations of each utility.
32+
*
33+
* If omitted, Tailwind will append these classes to the very end of
34+
* your stylesheet by default.
3335
*/
3436
@@tailwind screens;
3537
```

src/lib/generateUtilities.js

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import _ from 'lodash'
2+
import postcss from 'postcss'
3+
import applyClassPrefix from '../util/applyClassPrefix'
24
import backgroundColors from '../generators/backgroundColors'
35
import backgroundPositions from '../generators/backgroundPositions'
46
import backgroundSize from '../generators/backgroundSize'
@@ -38,49 +40,60 @@ import zIndex from '../generators/zIndex'
3840

3941
export default function(config) {
4042
return function(css) {
41-
const options = config()
43+
const unwrappedConfig = config()
4244

4345
css.walkAtRules('tailwind', atRule => {
4446
if (atRule.params === 'utilities') {
45-
const utilities = _.flatten([
46-
lists(options),
47-
forms(options),
48-
textSizes(options),
49-
textWeights(options),
50-
textFonts(options),
51-
textColors(options),
52-
textLeading(options),
53-
textTracking(options),
54-
textAlign(options),
55-
textWrap(options),
56-
textStyle(options),
57-
verticalAlign(options),
58-
backgroundColors(options),
59-
backgroundPositions(options),
60-
backgroundSize(options),
61-
borderWidths(options),
62-
borderColors(options),
63-
borderStyles(options),
64-
rounded(options),
65-
display(options),
66-
position(options),
67-
overflow(options),
68-
sizing(options),
69-
spacing(options),
70-
shadows(options),
71-
flex(options),
72-
floats(options),
73-
visibility(options),
74-
zIndex(options),
75-
opacity(options),
76-
userSelect(options),
77-
pointerEvents(options),
78-
resize(options),
79-
cursor(options),
80-
])
47+
const utilities = postcss.root({
48+
nodes: _.flatten([
49+
lists(unwrappedConfig),
50+
forms(unwrappedConfig),
51+
textSizes(unwrappedConfig),
52+
textWeights(unwrappedConfig),
53+
textFonts(unwrappedConfig),
54+
textColors(unwrappedConfig),
55+
textLeading(unwrappedConfig),
56+
textTracking(unwrappedConfig),
57+
textAlign(unwrappedConfig),
58+
textWrap(unwrappedConfig),
59+
textStyle(unwrappedConfig),
60+
verticalAlign(unwrappedConfig),
61+
backgroundColors(unwrappedConfig),
62+
backgroundPositions(unwrappedConfig),
63+
backgroundSize(unwrappedConfig),
64+
borderWidths(unwrappedConfig),
65+
borderColors(unwrappedConfig),
66+
borderStyles(unwrappedConfig),
67+
rounded(unwrappedConfig),
68+
display(unwrappedConfig),
69+
position(unwrappedConfig),
70+
overflow(unwrappedConfig),
71+
sizing(unwrappedConfig),
72+
spacing(unwrappedConfig),
73+
shadows(unwrappedConfig),
74+
flex(unwrappedConfig),
75+
floats(unwrappedConfig),
76+
visibility(unwrappedConfig),
77+
zIndex(unwrappedConfig),
78+
opacity(unwrappedConfig),
79+
userSelect(unwrappedConfig),
80+
pointerEvents(unwrappedConfig),
81+
resize(unwrappedConfig),
82+
cursor(unwrappedConfig),
83+
]),
84+
})
8185

82-
atRule.before(container(options))
83-
atRule.before(responsive(utilities))
86+
if (_.get(unwrappedConfig, 'options.important', false)) {
87+
utilities.walkDecls(decl => (decl.important = true))
88+
}
89+
90+
const tailwindClasses = postcss.root({
91+
nodes: [...container(unwrappedConfig), responsive(utilities)],
92+
})
93+
94+
applyClassPrefix(tailwindClasses, _.get(unwrappedConfig, 'options.prefix', ''))
95+
96+
atRule.before(tailwindClasses)
8497
atRule.remove()
8598
}
8699
})

src/util/applyClassPrefix.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default function(css, prefix) {
2+
css.walkRules(rule => {
3+
rule.selectors = rule.selectors.map(selector => `.${prefix}${selector.slice(1)}`)
4+
})
5+
return css
6+
}

src/util/responsive.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import _ from 'lodash'
12
import postcss from 'postcss'
23
import cloneNodes from './cloneNodes'
34

@@ -6,5 +7,5 @@ export default function responsive(rules) {
67
.atRule({
78
name: 'responsive',
89
})
9-
.append(cloneNodes(rules))
10+
.append(cloneNodes(_.isArray(rules) ? rules : rules.nodes))
1011
}

0 commit comments

Comments
 (0)