├── .gitignore ├── .npmignore ├── .travis.yml ├── History.md ├── Makefile ├── Readme.md ├── bin ├── logger.js └── myth ├── bower.json ├── component.json ├── lib ├── features.js └── index.js ├── myth.js ├── package.json └── test ├── cases ├── myth.io.css └── myth.io.out.css ├── cli ├── compress.css ├── error.css ├── input.css └── input.out.css ├── features ├── calc.css ├── calc.out.css ├── color.css ├── color.out.css ├── custom-media.css ├── custom-media.out.css ├── font-variant.css ├── font-variant.out.css ├── hex-alpha.css ├── hex-alpha.out.css ├── import.css ├── import.include.css ├── import.out.css ├── prefixes.css ├── prefixes.out.css ├── rebeccapurple.css ├── rebeccapurple.out.css ├── variables.css └── variables.out.css ├── index.js └── sourcemap ├── imported.css ├── in.css ├── index.html └── out.css /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | test -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | # - "0.11" 5 | # - "0.8" 6 | # - "0.6" 7 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 2 | 1.5.0 - July 11, 2015 3 | --------------------- 4 | * upgrade `autoprefixer` to `5.2.0` 5 | * add `--ignore-errors` flag to the cli 6 | 7 | 1.4.0 - March 6, 2015 8 | --------------------- 9 | * add `variables` and `preserve` options 10 | 11 | 1.3.0 - January 25, 2015 12 | ------------------------ 13 | * add `--sourcemap` flag to the cli 14 | 15 | 1.2.1 - October 15, 2014 16 | -------------------------- 17 | * upgrade `read-file-stdin` to `0.2.0` 18 | 19 | 1.2.0 - September 12, 2014 20 | -------------------------- 21 | * upgrade `autoprefixer` to `3.0.0` 22 | 23 | 1.1.1 - July 17, 2014 24 | --------------------- 25 | * fix `browsers` option [#97](https://github.com/segmentio/myth/pull/97) 26 | * add cli options to disable individual features 27 | 28 | 1.1.0 - July 14, 2014 29 | --------------------- 30 | * add [custom media](http://dev.w3.org/csswg/mediaqueries/#custom-mq) feature 31 | * add [rebeccapurple](http://lists.w3.org/Archives/Public/www-style/2014Jun/0312.html) support 32 | * improve `calc()` support 33 | * improve `@import` support 34 | * upgrade autoprefixer to `2.0.0` 35 | * upgrade rework to `1.0.0` for sourcemap support 36 | * fix `maximum call stack` issue [#91](https://github.com/segmentio/myth/issues/91) 37 | * fix empty `font-feature` value issue [#79](https://github.com/segmentio/myth/issues/79) 38 | 39 | 1.0.4 - June 3, 2014 40 | -------------------- 41 | * upgrade `rework-inline` to `0.2.0` to fix import bugs 42 | 43 | 1.0.3 - May 16, 2014 44 | -------------------- 45 | * fix returning plugin on empty string 46 | 47 | 1.0.2 - May 7, 2014 48 | ------------------- 49 | * upgrade to `read-file-stdin` version `0.0.4` 50 | 51 | 1.0.1 - May 5, 2014 52 | ------------------- 53 | * add `compress` cli flag 54 | 55 | 1.0.0 - May 5, 2014 56 | ------------------- 57 | * add `@import` support 58 | * add support for new css variables syntax 59 | * add `compress` option 60 | * add `browsers` option 61 | 62 | 0.3.4 - March 31, 2014 63 | ---------------------- 64 | * upgrade `rework-vars` to `2.0.3` to properly clear variables 65 | 66 | 0.3.3 - March 18, 2014 67 | ---------------------- 68 | * add ability to pass options to `rework.toString` 69 | 70 | 0.3.2 - March 18, 2014 71 | ---------------------- 72 | * add bower support 73 | 74 | 0.3.1 - March 4, 2014 75 | --------------------- 76 | * upgrade color plugins to fix media query support 77 | 78 | 0.3.0 - January 7, 2014 79 | ----------------------- 80 | * add browser support 81 | * add component support 82 | 83 | 0.2.0 - December 25, 2013 84 | ------------------------- 85 | * add nice error logging 86 | * upgrade `rework-color-function` to `0.1.2` 87 | 88 | 0.1.8 - December 23, 2013 89 | ------------------------- 90 | * upgrade logger 91 | 92 | 0.1.7 - December 23, 2013 93 | ------------------------- 94 | * change to `node-watch` 95 | 96 | 0.1.6 - December 19, 2013 97 | ------------------------- 98 | * add cli tests 99 | 100 | 0.1.5 - December 19, 2013 101 | ------------------------- 102 | * add `read-file-stdin` 103 | * add `write-file-stdout` 104 | * fix exists check 105 | 106 | 0.1.4 - December 18, 2013 107 | ------------------------- 108 | * upgrade `rework-vars` to `2.0.2` 109 | 110 | 0.1.3 - December 18, 2013 111 | ------------------------- 112 | * add exists check 113 | 114 | 0.1.1 - December 17, 2013 115 | ------------------------- 116 | * add returning rework plugin 117 | * upgrade `rework-calc` dependency 118 | 119 | 0.1.0 - December 17, 2013 120 | ------------------------- 121 | :sparkles: 122 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | # Binaries. 3 | browserify = ./node_modules/.bin/browserify 4 | mocha = ./node_modules/.bin/mocha 5 | 6 | # Remove non-checked-in files. 7 | clean: 8 | @rm -rf node_modules myth.js 9 | 10 | # Build the browser-side myth.js file with Browserify. 11 | myth.js: lib/*.js node_modules 12 | @$(browserify) lib/index.js \ 13 | --standalone myth \ 14 | --outfile myth.js 15 | 16 | # Install dependencies from npm. 17 | node_modules: package.json 18 | @npm install 19 | @touch package.json 20 | 21 | # Run the tests. 22 | test: myth.js node_modules 23 | @$(mocha) \ 24 | --reporter spec \ 25 | --slow 700 \ 26 | --bail 27 | 28 | # Run the tests. 29 | test-debug: myth.js node_modules 30 | @$(mocha) debug \ 31 | --reporter spec \ 32 | --slow 700 33 | 34 | # Phony commands. 35 | .PHONY: clean 36 | .PHONY: test 37 | .PHONY: test-debug -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # Myth [![Build Status](https://travis-ci.org/segmentio/myth.png)](http://travis-ci.org/segmentio/myth) 3 | 4 | _CSS the way it was imagined._ 5 | 6 | Myth is a preprocessor that lets you write pure CSS without having to worry about slow browser support, or even slow spec approval. It's like a CSS polyfill. 7 | 8 | 9 | ## Installation 10 | 11 | $ npm install -g myth 12 | 13 | 14 | ## Usage 15 | 16 | $ myth input.css output.css 17 | # Generated output.css from input.css 18 | 19 | 20 | ## Community 21 | 22 | - [mnmly/builder-myth](https://github.com/mnmly/builder-myth): `component-builder` plugin 23 | - [gulp-myth](https://github.com/sindresorhus/gulp-myth): Gulp plugin 24 | - [grunt-myth](https://github.com/sindresorhus/grunt-myth): Grunt plugin 25 | - [duo-myth](https://github.com/duojs/myth): Duo plugin 26 | - [myth-loader](https://github.com/luigy/myth-loader): Webpack Loader 27 | - [meteor-myth](https://github.com/aquator/meteor-myth): Meteor plugin 28 | - [myth-transformer](https://github.com/ppvk/myth-transform): Dart transformer 29 | 30 | ## Why? 31 | 32 | Myth lets you write pure CSS while still giving you the benefits of tools like LESS and Sass. You can still use variables and math functions, just like you do in preprocessors. It's like a polyfill for future versions of the spec. 33 | 34 | Some of the features in CSS require runtime calculations, which neither Myth nor preprocessors handle, but what Myth does is let you write your code today in the future syntax, so that your code is future-proof. When browsers finally support these features you won't need to rewrite anything, just start using the cascade! 35 | 36 | Taking plain CSS as an input also means you can use Myth to re-process anyone else's CSS (or another preprocessors output), adding the browser support you need, without having to re-write the code in a completely different syntax. 37 | 38 | Myth is built with Rework so it's incredibly fast, and has a nice Javascript API in addition to the CLI. 39 | 40 | 41 | ## Example 42 | 43 | An example is the easiest way to explain it. If you write spec-compliant CSS: 44 | 45 | ```css 46 | :root { 47 | --green: #a6c776; 48 | } 49 | 50 | @custom-media --narrow-window screen and (max-width: 30em); 51 | 52 | @media (--narrow-window) { 53 | html { 54 | font-size: 1.2rem; 55 | } 56 | } 57 | 58 | a { 59 | color: var(--green); 60 | font-variant: all-small-caps; 61 | transition: color 1s; 62 | } 63 | 64 | a:hover { 65 | color: color(var(--green) shade(20%)); 66 | } 67 | 68 | ::placeholder { 69 | opacity: .4; 70 | transition: opacity 1s; 71 | } 72 | 73 | :focus::placeholder { 74 | opacity: .2; 75 | } 76 | ``` 77 | 78 | ... Myth will transform it for you, into browser-compliant CSS: 79 | 80 | ```css 81 | @media screen and (max-width: 30em) { 82 | html { 83 | font-size: 1.2rem; 84 | } 85 | } 86 | 87 | a { 88 | color: #a6c776; 89 | -webkit-font-feature-settings: "smcp", "c2sc"; 90 | -moz-font-feature-settings: "smcp", "c2sc"; 91 | font-feature-settings: "smcp", "c2sc"; 92 | font-variant: all-small-caps; 93 | -webkit-transition: color 1s; 94 | transition: color 1s; 95 | } 96 | 97 | a:hover { 98 | color: rgb(133, 159, 94); 99 | } 100 | 101 | ::-webkit-input-placeholder { 102 | opacity: .4; 103 | -webkit-transition: opacity 1s; 104 | transition: opacity 1s; 105 | } 106 | 107 | ::-moz-placeholder { 108 | opacity: .4; 109 | transition: opacity 1s; 110 | } 111 | 112 | :-ms-input-placeholder { 113 | opacity: .4; 114 | transition: opacity 1s; 115 | } 116 | 117 | ::placeholder { 118 | opacity: .4; 119 | -webkit-transition: opacity 1s; 120 | transition: opacity 1s; 121 | } 122 | 123 | :focus::-webkit-input-placeholder { 124 | opacity: .2; 125 | } 126 | 127 | :focus::-moz-placeholder { 128 | opacity: .2; 129 | } 130 | 131 | :focus:-ms-input-placeholder { 132 | opacity: .2; 133 | } 134 | 135 | :focus::placeholder { 136 | opacity: .2; 137 | } 138 | ``` 139 | 140 | 141 | ## Features 142 | 143 | #### Variables 144 | 145 | Using the same syntax as the [CSS spec](http://dev.w3.org/csswg/css-variables/). Just like future CSS, but without the cascade. Thanks to [`rework-vars`](https://github.com/visionmedia/rework-vars). 146 | 147 | ```css 148 | :root { 149 | --purple: #847AD1; 150 | } 151 | 152 | a { 153 | color: var(--purple); 154 | } 155 | ``` 156 | 157 | #### Math 158 | 159 | Using the same syntax as the [CSS spec](http://www.w3.org/TR/css3-values/#calc-notation). Just like future CSS, but without runtime interpolation. Thanks to [`rework-calc`](https://github.com/klei-dev/rework-calc). 160 | 161 | ```css 162 | pre { 163 | margin: calc(50px * 2); 164 | } 165 | ``` 166 | 167 | #### Custom media queries 168 | 169 | Using the same syntax as the [CSS spec](http://dev.w3.org/csswg/mediaqueries/#custom-mq). Thanks to [`rework-custom-media`](https://github.com/reworkcss/rework-custom-media). 170 | 171 | ```css 172 | @custom-media --narrow-window (max-width: 30em); 173 | 174 | @media (--narrow-window) { 175 | /* narrow window styles */ 176 | } 177 | 178 | @media (--narrow-window) and (script) { 179 | /* special styles for when script is allowed */ 180 | } 181 | ``` 182 | 183 | #### Color Manipulation 184 | 185 | Using the same syntax as the [CSS spec](http://dev.w3.org/csswg/css-color/#modifying-colors). Thanks to [`rework-color-function`](https://github.com/ianstormtaylor/rework-color-function). 186 | 187 | ```css 188 | a { 189 | color: #847AD1; 190 | } 191 | 192 | a:hover { 193 | color: color(#847AD1 tint(20%)); 194 | } 195 | ``` 196 | 197 | #### No Prefixes 198 | 199 | The prefixes from the most-common *and* most-recent browsers are supported, so you never need to worry about what the current browser support landscape is. Big thanks to [`autoprefixer`](https://github.com/postcss/autoprefixer)! 200 | 201 | ```css 202 | .button { 203 | background: linear-gradient(to bottom, black, white); 204 | transition: transform .25s; 205 | } 206 | ``` 207 | 208 | #### And more... 209 | 210 | - 4-digit and 8-digit hex color support. [`Spec`](http://dev.w3.org/csswg/css-color/#hex-notation) - [`Thanks`](https://github.com/ianstormtaylor/rework-hex-alpha) 211 | - Font-variant shorthands. [`Spec`](http://www.w3.org/TR/css3-fonts/#font-variant-prop) - [`Thanks`](https://github.com/ianstormtaylor/rework-font-variant) 212 | 213 | ## API 214 | 215 | #### Command Line 216 | 217 | ``` 218 | Usage: myth [] [] 219 | 220 | Options: 221 | 222 | -h, --help output usage information 223 | -V, --version output the version number 224 | -c, --compress compress output 225 | -w, --watch watch the input file for changes 226 | -s, --sourcemap add source map 227 | -v, --verbose log verbose output for debugging 228 | 229 | --no-import disable import support 230 | --no-variables disable variables support 231 | --no-custom-media disable custom media support 232 | --no-hex-alpha disable hex alpha support 233 | --no-color disable color support 234 | --no-calc disable calc support 235 | --no-font-variant disable font variant support 236 | --no-rebeccapurple disable rebeccapurple support 237 | --no-prefixes disable prefixes support 238 | 239 | Examples: 240 | 241 | # pass an input and output file: 242 | $ myth input.css output.css 243 | 244 | # watch the input file for changes: 245 | $ myth --watch input.css output.css 246 | 247 | # unix-style piping to stdin and stdout: 248 | $ cat input.css | myth | grep background-color 249 | ``` 250 | 251 | #### Node.js 252 | 253 | ```js 254 | var myth = require('myth'); 255 | var fs = require('fs'); 256 | 257 | var css = fs.readFileSync('index.css', 'utf8'); 258 | var converted = myth(css); 259 | 260 | fs.writeFileSync('converted.css', converted); 261 | ``` 262 | 263 | Or use it directly as a Rework plugin: 264 | 265 | ```js 266 | var myth = require('myth'); 267 | var rework = require('rework'); 268 | var fs = require('fs'); 269 | 270 | var css = fs.readFileSync('index.css', 'utf8'); 271 | var converted = rework(css) 272 | .use(myth()) 273 | .toString(); 274 | 275 | fs.writeFileSync('converted.css', converted); 276 | ``` 277 | 278 | Available options: 279 | 280 | | Key | Type | Description 281 | | ----------- | --------- | ----------- 282 | | `browsers` | `Array` | An array of [browsers and versions to support](https://github.com/postcss/autoprefixer#browsers). 283 | | `compress` | `Boolean` | Whether to compress the CSS output. 284 | | `features` | `Object` | A dictionary of features to disable. All features are enabled by default. Available features: `calc`, `color`, `customMedia`, `fontVariant`, `hexAlpha`, `import`, `prefixes`, `rebeccapurple`, `variables`. 285 | | `preserve` | `Boolean` | Whether to preserve variables in the output. 286 | | `source` | `String` | The full path to the source CSS file. This is **required** if you want Myth to concatenate `@import` rules in your CSS. 287 | | `sourcemap` | `Boolean` | Whether to embed a source map. 288 | | `variables` | `Object` | A dictionary of CSS variables to use. 289 | 290 | 291 | ## License 292 | 293 | The MIT License (MIT) 294 | 295 | Copyright (c) 2015, Segment <friends@segment.io> 296 | 297 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 298 | 299 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 300 | 301 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 302 | -------------------------------------------------------------------------------- /bin/logger.js: -------------------------------------------------------------------------------- 1 | 2 | var colors = require('colors'); 3 | var pad = require('pad-component').left; 4 | 5 | /** 6 | * Log. 7 | * 8 | * @param {String} type 9 | * @param {String} message 10 | */ 11 | 12 | exports.log = function(type, message){ 13 | padding(); 14 | log(type, message); 15 | }; 16 | 17 | /** 18 | * Fatal, exits the process with an error. 19 | * 20 | * @param {String} type 21 | * @param {String} message 22 | */ 23 | 24 | exports.fatal = function(type, message){ 25 | if (padded) console.log(); 26 | padding(); 27 | error(type, message, 'red'); 28 | process.exit(1); 29 | }; 30 | 31 | /** 32 | * Throw a pretty fatal error from an `err`. 33 | * 34 | * @param {Error} err 35 | */ 36 | 37 | exports.throw = function(err){ 38 | if (padded) console.log(); 39 | padding(); 40 | 41 | // node errors (or faulty plugins) 42 | if (!err.position) { 43 | error('error', err.toString(), 'red', 'red'); 44 | err.stack.split('\n').slice(1).forEach(function(line){ 45 | error('', line.slice(2)); 46 | }); 47 | } 48 | 49 | // rework plugin errors 50 | else { 51 | var pos = err.position; 52 | var start = pos.start; 53 | var end = pos.end; 54 | var lines = err.css.split('\n'); 55 | 56 | error('error', err.toString(), 'red', 'red'); 57 | error('', ' at ' + pos.source + ':' + start.line + ':' + start.column); 58 | error(); 59 | 60 | for (var i = start.line - 3; i < end.line + 2; i++) { 61 | var line = lines[i]; 62 | if (line === undefined) continue; 63 | var color = i == start.line - 1 ? 'red' : 'grey'; 64 | error((i + 1).toString(), ' ' + line, color, color); 65 | } 66 | } 67 | 68 | process.exit(1); 69 | }; 70 | 71 | /** 72 | * Log to stdout. 73 | */ 74 | 75 | function log(){ 76 | var msg = format.apply(this, arguments); 77 | console.log(msg); 78 | } 79 | 80 | /** 81 | * Log to stderr. 82 | */ 83 | 84 | function error(){ 85 | var msg = format.apply(this, arguments); 86 | console.error(msg); 87 | } 88 | 89 | /** 90 | * Format a `type` and `msg` with `typeColor` and `msgColor`. 91 | * 92 | * @param {String} type 93 | * @param {String} msg 94 | * @param {String} typeColor (optional) 95 | * @param {String} msgColor (optional) 96 | */ 97 | 98 | function format(type, msg, typeColor, msgColor){ 99 | type = type || ''; 100 | msg = msg || ''; 101 | typeColor = typeColor || 'blue'; 102 | msgColor = msgColor || 'grey'; 103 | type = pad(type, 12); 104 | return type[typeColor] + ' · ' + msg[msgColor]; 105 | } 106 | 107 | /** 108 | * Add padding to the output. 109 | */ 110 | 111 | var padded = false; 112 | 113 | function padding(){ 114 | if (padded) return; 115 | console.log(); 116 | process.on('exit', function(){ console.log(); }); 117 | padded = true; 118 | } -------------------------------------------------------------------------------- /bin/myth: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var fmt = require('util').format; 4 | var fs = require('fs'); 5 | var exists = fs.existsSync; 6 | var logger = require('./logger'); 7 | var myth = require('..'); 8 | var path = require('path'); 9 | var resolve = path.resolve; 10 | var program = require('commander'); 11 | var read = require('read-file-stdin'); 12 | var slug = require('to-slug-case'); 13 | var space = require('to-space-case'); 14 | var watch = require('node-watch'); 15 | var write = require('write-file-stdout'); 16 | 17 | /** 18 | * Usage. 19 | */ 20 | 21 | program 22 | .version(require('../package.json').version) 23 | .usage('[] []') 24 | .option('-c, --compress', 'compress output') 25 | .option('-i, --ignore-errors', 'ignore complilation errors', false) 26 | .option('-s, --sourcemap', 'add source map') 27 | .option('-v, --verbose', 'log verbose output for debugging\n') 28 | .option('-w, --watch', 'watch the input file for changes'); 29 | 30 | myth.features.forEach(function(feature){ 31 | var flag = fmt('--no-%s', slug(feature)); 32 | var desc = fmt('disable %s support', space(feature)); 33 | program.option(flag, desc); 34 | }); 35 | 36 | /** 37 | * Examples. 38 | */ 39 | 40 | program.on('--help', function(){ 41 | console.log(' Examples:'); 42 | console.log(); 43 | console.log(' # pass an input and output file:'); 44 | console.log(' $ myth input.css output.css'); 45 | console.log(); 46 | console.log(' # watch the input file for changes:'); 47 | console.log(' $ myth --watch input.css output.css'); 48 | console.log(); 49 | console.log(' # unix-style piping to stdin and stdout:'); 50 | console.log(' $ cat input.css | myth | grep background-color'); 51 | console.log(); 52 | }); 53 | 54 | /** 55 | * Parse. 56 | */ 57 | 58 | program.parse(process.argv); 59 | 60 | /** 61 | * Settings. 62 | */ 63 | 64 | var input = program.args[0] ? resolve(program.args[0]) : null; 65 | var output = program.args[1] ? resolve(program.args[1]) : null; 66 | var verbose = program.verbose; 67 | var regen = program.watch && input && output; 68 | var ignore = program.ignoreErrors; 69 | 70 | /** 71 | * Exists? 72 | */ 73 | 74 | if (input && !exists(input)) logger.fatal('not found', input); 75 | 76 | /** 77 | * Run. 78 | */ 79 | 80 | run(); 81 | 82 | /** 83 | * Watch? 84 | */ 85 | 86 | if (regen) { 87 | watch(input, run); 88 | if (verbose) logger.log('watch', input); 89 | } 90 | 91 | /** 92 | * Run for the given input and output. 93 | */ 94 | 95 | function run(){ 96 | read(input, function(err, buffer){ 97 | if (err) logger.throw(err); 98 | var css = buffer.toString(); 99 | 100 | try { 101 | css = myth(css, { 102 | compress: program.compress, 103 | sourcemap: program.sourcemap, 104 | features: program, 105 | source: input 106 | }); 107 | } catch (e) { 108 | if (ignore) { 109 | return; 110 | } else { 111 | e.css = css; 112 | logger.throw(e); 113 | } 114 | } 115 | 116 | write(output, css); 117 | if (verbose && output) logger.log('write', output); 118 | }); 119 | } 120 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "myth", 3 | "license": "MIT", 4 | "description": "A CSS preprocessor that acts like a polyfill for future versions of the spec.", 5 | "ignore": ["**/.*", "bin", "test"], 6 | "scripts": ["myth.js"], 7 | "main": "myth.js" 8 | } 9 | -------------------------------------------------------------------------------- /component.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "myth", 3 | "repository": "segmentio/myth", 4 | "version": "1.5.0", 5 | "license": "MIT", 6 | "description": "A CSS preprocessor that acts like a polyfill for future versions of the spec.", 7 | "scripts": ["myth.js"], 8 | "main": "myth.js" 9 | } 10 | -------------------------------------------------------------------------------- /lib/features.js: -------------------------------------------------------------------------------- 1 | 2 | var autoprefixer = require('autoprefixer-core'); 3 | var calc = require('rework-calc'); 4 | var clone = require('clone-component'); 5 | var color = require('rework-color-function'); 6 | var customMedia = require('rework-custom-media'); 7 | var dirname = require('path').dirname; 8 | var fontVariant = require('rework-font-variant'); 9 | var hexAlpha = require('rework-hex-alpha'); 10 | var importer = require('rework-import'); 11 | var postcss = require('postcss'); 12 | var rebeccapurple = require('rework-rebeccapurple'); 13 | var Rework = require('rework'); 14 | var variables = require('rework-vars'); 15 | 16 | /** 17 | * Import. 18 | * 19 | * @param {Object} options 20 | * @param {String} source 21 | * @return {Function} 22 | */ 23 | 24 | exports.import = function(options){ 25 | return 'undefined' == typeof window && options.source 26 | ? importer() 27 | : function(){}; 28 | }; 29 | 30 | /** 31 | * Variables. 32 | * 33 | * @param {Object} options 34 | * @param {Object} variables 35 | * @param {Boolean} preserve 36 | * @return {Function} 37 | */ 38 | 39 | exports.variables = function(options){ 40 | return variables({ 41 | map: options.variables, 42 | preserve: options.preserve 43 | }); 44 | }; 45 | 46 | /** 47 | * Custom media. 48 | * 49 | * @param {Object} options 50 | * @return {Function} 51 | */ 52 | 53 | exports.customMedia = function(options){ 54 | return customMedia; 55 | }; 56 | 57 | /** 58 | * Hex alpha. 59 | * 60 | * @param {Object} options 61 | * @return {Function} 62 | */ 63 | 64 | exports.hexAlpha = function(options){ 65 | return hexAlpha; 66 | }; 67 | 68 | /** 69 | * Color. 70 | * 71 | * @param {Object} options 72 | * @return {Function} 73 | */ 74 | 75 | exports.color = function(options){ 76 | return color; 77 | }; 78 | 79 | /** 80 | * Calc. 81 | * 82 | * @param {Object} options 83 | * @return {Function} 84 | */ 85 | 86 | exports.calc = function(options){ 87 | return calc; 88 | }; 89 | 90 | /** 91 | * Font variant. 92 | * 93 | * @param {Object} options 94 | * @return {Function} 95 | */ 96 | 97 | exports.fontVariant = function(options){ 98 | return fontVariant; 99 | }; 100 | 101 | /** 102 | * Rebecca purple. 103 | * 104 | * @param {Object} options 105 | * @return {Function} 106 | */ 107 | 108 | exports.rebeccapurple = function(options){ 109 | return rebeccapurple; 110 | }; 111 | 112 | /** 113 | * Prefixes. 114 | * 115 | * Unfortunately, Autoprefixer uses a different preprocessor, so we have to give 116 | * it the CSS string and re-parse it again afterwards. 117 | * 118 | * @param {Object} options 119 | * @param {Array} browsers 120 | * @return {Function} 121 | */ 122 | 123 | exports.prefixes = function(options){ 124 | var opts = clone(options); 125 | var src = options.source; 126 | var prefixes = autoprefixer({ browsers: options.browsers }); 127 | var processor = postcss(prefixes); 128 | 129 | return function(stylesheet, rework){ 130 | var str = rework.toString(options); 131 | var css = processor.process(str, { from: src, to: src }).css; 132 | // we don't need source mapping the second time reparsing 133 | delete opts.source; 134 | rework.obj = Rework(css, opts).obj; 135 | }; 136 | }; 137 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | 2 | var features = require('./features'); 3 | var Rework = require('rework'); 4 | 5 | /** 6 | * Expose `myth`. 7 | */ 8 | 9 | module.exports = exports = myth; 10 | 11 | /** 12 | * Expose `features`. 13 | */ 14 | 15 | exports.features = Object.keys(features); 16 | 17 | /** 18 | * Rework a CSS `string`, or return the Myth rework plugin. 19 | * 20 | * @param {String} string (optional) 21 | * @param {Object} options (optional) 22 | * @property {String} source 23 | * @property {Array} browsers 24 | * @property {Boolean} compress 25 | * @property {Object} features 26 | * @return {String} 27 | */ 28 | 29 | function myth(string, options){ 30 | if ('object' == typeof string) options = string, string = null; 31 | options = options || {}; 32 | 33 | if ('string' != typeof string) return plugin(options); 34 | 35 | return Rework(string, options) 36 | .use(plugin(options)) 37 | .toString(options); 38 | } 39 | 40 | /** 41 | * Generate a Myth rework plugin with `options`. 42 | * 43 | * @param {Object} options 44 | * @return {Function} 45 | */ 46 | 47 | function plugin(options){ 48 | return function(stylesheet, rework){ 49 | var enabled = options.features || {}; 50 | exports.features.forEach(function(key){ 51 | if (enabled[key] === false) return; 52 | var plugin = features[key](options); 53 | rework.use(plugin); 54 | }); 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "myth", 3 | "version": "1.5.0", 4 | "license": "MIT", 5 | "repository": "git://github.com/segmentio/myth.git", 6 | "description": "A CSS preprocessor that acts like a polyfill for future versions of the spec.", 7 | "main": "lib/index.js", 8 | "bin": { 9 | "myth": "bin/myth" 10 | }, 11 | "scripts": { 12 | "test": "make test" 13 | }, 14 | "dependencies": { 15 | "autoprefixer-core": "^5.2.1", 16 | "clone-component": "~0.2.2", 17 | "colors": "~0.6.2", 18 | "commander": "^2.1.0", 19 | "is-browser": "^2.0.0", 20 | "node-watch": "~0.3.4", 21 | "pad-component": "~0.0.1", 22 | "postcss": "^4.1.16", 23 | "read-file-stdin": "^0.2.0", 24 | "rework": "^1.0.0", 25 | "rework-calc": "^1.1.0", 26 | "rework-color-function": "^1.0.0", 27 | "rework-custom-media": "~0.1.1", 28 | "rework-font-variant": "1.0.1", 29 | "rework-hex-alpha": "^1.0.0", 30 | "rework-import": "^1.2.0", 31 | "rework-rebeccapurple": "^1.0.1", 32 | "rework-vars": "^3.0.0", 33 | "to-slug-case": "~0.1.2", 34 | "to-space-case": "~0.1.3", 35 | "write-file-stdout": "~0.0.2" 36 | }, 37 | "devDependencies": { 38 | "browserify": "^3.46.0", 39 | "mocha": "^1.15.1" 40 | }, 41 | "keywords": [ 42 | "preprocessor", 43 | "pre-processor", 44 | "postprocessor", 45 | "post-processor", 46 | "rework", 47 | "css", 48 | "pure", 49 | "autoprefixer", 50 | "postcss", 51 | "sass", 52 | "less", 53 | "stylus", 54 | "style", 55 | "gradients", 56 | "variables", 57 | "media queries", 58 | "calc", 59 | "prefixes" 60 | ] 61 | } 62 | -------------------------------------------------------------------------------- /test/cases/myth.io.css: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Variables. 4 | */ 5 | 6 | :root { 7 | --light-purple: #989EBA; 8 | --purple: #847AD1; 9 | --dark-purple: #26202B; 10 | --darker-purple: #1C1521; 11 | --meyer-purple: rebeccapurple; 12 | --blue: #5790EF; 13 | --black: #120C17; 14 | --gray: #605668; 15 | } 16 | 17 | /** 18 | * Body. 19 | */ 20 | 21 | body { 22 | font: 100 16px/1.5 "Source Sans", sans-serif; 23 | color: white; 24 | background-color: var(--darker-purple); 25 | } 26 | 27 | a { 28 | color: var(--purple); 29 | text-decoration: underline; 30 | transition: color .2s; 31 | } 32 | 33 | a:visited { 34 | color: var(--meyer-purple); 35 | } 36 | 37 | a:hover { 38 | color: color(var(--purple) tint(20%)); 39 | } 40 | 41 | pre { 42 | font: 300 12px/1.2 "Source Code", monospace; 43 | color: color(var(--light-purple) tint(50%)); 44 | } 45 | 46 | /** 47 | * Sections. 48 | */ 49 | 50 | .Header, 51 | .Section, 52 | .Footer { 53 | position: relative; 54 | padding: 4em 1.5em; 55 | } 56 | 57 | .Section-title { 58 | font-size: 1.5em; 59 | margin-bottom: .25em; 60 | text-align: center; 61 | } 62 | 63 | .Section-description { 64 | color: var(--light-purple); 65 | margin-bottom: 1em; 66 | } 67 | 68 | .Section-example { 69 | margin-top: 1em; 70 | border-radius: .2em; 71 | background: var(--darker-purple); 72 | padding: 1em; 73 | overflow: hidden; 74 | } 75 | 76 | .Section-example-code b { 77 | font-weight: 600; 78 | color: var(--purple); 79 | } 80 | 81 | .Section-example-code em { 82 | font-style: normal; 83 | font-weight: 600; 84 | color: var(--blue); 85 | } 86 | 87 | .Section-example-code s { 88 | font-style: normal; 89 | text-decoration: none; 90 | color: var(--gray); 91 | } 92 | 93 | .Section-legend { 94 | text-align: center; 95 | color: var(--light-purple); 96 | margin-top: .75em; 97 | } 98 | 99 | /** 100 | * Header. 101 | */ 102 | 103 | .Header { 104 | background: url(images/background.jpg); 105 | background-size: cover; 106 | text-align: center; 107 | padding-bottom: 6em; 108 | } 109 | 110 | .Header-title { 111 | font-size: 1.5em; 112 | margin-bottom: 4em; 113 | } 114 | 115 | .Header-subtitle { 116 | font-size: 2.5em; 117 | margin-bottom: .6em; 118 | } 119 | 120 | .Header-description { 121 | max-width: 30em; 122 | margin-right: auto; 123 | margin-left: auto; 124 | } 125 | 126 | .Header-github-link { 127 | display: block; 128 | position: absolute; 129 | top: 3em; 130 | right: -6.5em; 131 | padding: 1em; 132 | width: 20em; 133 | text-align: center; 134 | background-color: var(--purple); 135 | text-transform: uppercase; 136 | font-size: .6em; 137 | color: white; 138 | letter-spacing: 1px; 139 | text-decoration: none; 140 | white-space: nowrap; 141 | transform: rotate(45deg); 142 | transform-origin: 50% 50%; 143 | } 144 | 145 | .Header-github-link:hover { 146 | font-weight: normal; 147 | color: white; 148 | } 149 | 150 | /** 151 | * Feature section. 152 | */ 153 | 154 | .Section--feature { 155 | background-color: var(--dark-purple); 156 | } 157 | 158 | .Section--feature + .Section--feature { 159 | padding-top: 0; 160 | } 161 | 162 | .animate .Section--feature .Section-title, 163 | .animate .Section--feature .Section-description, 164 | .animate .Section--feature .Section-example { 165 | opacity: 0; 166 | } 167 | 168 | .Section--feature .Section-description { 169 | text-align: center; 170 | } 171 | 172 | /** 173 | * First and last feature. 174 | */ 175 | 176 | .Section--feature-variables::before, 177 | .Section--feature-no-prefixes::after { 178 | content: ''; 179 | position: absolute; 180 | right: 0; 181 | left: 0; 182 | } 183 | 184 | /** 185 | * First feature. 186 | */ 187 | 188 | .Section--feature-variables::before { 189 | height: 6em; 190 | bottom: 100%; 191 | background: linear-gradient(to bottom, transparent, var(--dark-purple)); 192 | } 193 | 194 | /** 195 | * Last feature. 196 | */ 197 | 198 | .Section--feature-no-prefixes { 199 | padding-bottom: 2em; 200 | } 201 | 202 | .Section--feature-no-prefixes::after { 203 | height: 14em; 204 | top: 100%; 205 | background: linear-gradient(to bottom, var(--dark-purple), transparent); 206 | } 207 | 208 | /** 209 | * Install section. 210 | */ 211 | 212 | .Section--install { 213 | padding-top: 2em; 214 | padding-bottom: 0; 215 | } 216 | 217 | .Section--install .Section-example { 218 | background-color: var(--black); 219 | } 220 | 221 | .Section--install .Section-example-code { 222 | line-height: 1.4; 223 | } 224 | 225 | /** 226 | * Why section. 227 | */ 228 | 229 | .Section--why .Section-description { 230 | color: var(--light-purple); 231 | } 232 | 233 | /** 234 | * Footer. 235 | */ 236 | 237 | .Footer { 238 | padding-top: 0; 239 | text-align: center; 240 | } 241 | 242 | .Footer-title { 243 | font-size: 1.5em; 244 | transition: transform .2s; 245 | } 246 | 247 | .Footer-title:hover { 248 | transform: scale(1.1); 249 | } 250 | 251 | .Footer-subtitle { 252 | color: var(--light-purple); 253 | font-size: .7em; 254 | text-transform: uppercase; 255 | letter-spacing: 1px; 256 | margin-bottom: .5em; 257 | } 258 | 259 | /** 260 | * Animation, only happens on first load. 261 | */ 262 | 263 | .Header-subtitle { 264 | transition: opacity 2s ease-in-out .5s; 265 | } 266 | 267 | .Header-description { 268 | transition: opacity 2s ease-in-out 2.5s; 269 | } 270 | 271 | .Header-github-link, 272 | .Section--feature .Section-title, 273 | .Section--feature .Section-description, 274 | .Section--feature .Section-example { 275 | transition: opacity 2s ease-in-out 4.5s; 276 | } 277 | 278 | .animate .Header-subtitle, 279 | .animate .Header-description, 280 | .animate .Header-github-link, 281 | .animate .Section--feature .Section-title, 282 | .animate .Section--feature .Section-description, 283 | .animate .Section--feature .Section-example { 284 | opacity: 0; 285 | } 286 | 287 | /** 288 | * Small screens. 289 | */ 290 | 291 | @media (max-width: 767px) { 292 | 293 | .Section--feature .Section-example-code:last-child { 294 | display: none; /* keep it simpler, just show the api */ 295 | } 296 | 297 | .Section--install s { 298 | display: none; /* breaks the line, and just not worth it */ 299 | } 300 | 301 | } 302 | 303 | /** 304 | * Large screens. 305 | */ 306 | 307 | @media (min-width: 768px) { 308 | 309 | body { 310 | font-size: 18px; 311 | } 312 | 313 | pre { 314 | font-size: 14px; 315 | } 316 | 317 | /** 318 | * Sections. 319 | */ 320 | 321 | .Header, 322 | .Section, 323 | .Footer { 324 | padding: 6em 2em; 325 | } 326 | 327 | .Section-title { 328 | font-size: 1.8em; 329 | } 330 | 331 | .Section-example { 332 | margin-top: 1.5em; 333 | padding: 1.5em; 334 | } 335 | 336 | /** 337 | * Header. 338 | */ 339 | 340 | .Header { 341 | font-size: 1.2em; 342 | padding-bottom: 14%; 343 | } 344 | 345 | .Header-subtitle { 346 | font-size: 2.5em; 347 | } 348 | 349 | .Header-description { 350 | max-width: 30em; 351 | margin-right: auto; 352 | margin-left: auto; 353 | } 354 | 355 | .Header-github-link { 356 | top: 4em; 357 | right: -5em; 358 | } 359 | 360 | /** 361 | * Feature section. 362 | */ 363 | 364 | .Section--feature .Section-title, 365 | .Section--feature .Section-description, 366 | .Section--feature .Section-example { 367 | max-width: 40em; 368 | margin-right: auto; 369 | margin-left: auto; 370 | } 371 | 372 | .Section--feature .Section-example { 373 | background-image: url(images/example-background.png); 374 | background-position: center center; 375 | background-repeat: no-repeat; 376 | } 377 | 378 | .Section--feature .Section-example-code { 379 | width: 50%; 380 | float: left; 381 | box-sizing: border-box; 382 | } 383 | 384 | .Section--feature .Section-example-code:first-child { 385 | padding-left: 1em; 386 | } 387 | 388 | .Section--feature .Section-example-code:last-child { 389 | padding-left: 3.5em; 390 | } 391 | 392 | /** 393 | * Install & Why sections. 394 | */ 395 | 396 | .Section--install, 397 | .Section--why { 398 | max-width: 26em; 399 | margin-right: auto; 400 | margin-left: auto; 401 | } 402 | /** 403 | * Install section. 404 | */ 405 | 406 | .Section--install { 407 | padding-top: 8em; 408 | } 409 | 410 | .Section--install .Section-example { 411 | width: 24em; 412 | margin-right: auto; 413 | margin-left: auto; 414 | } 415 | 416 | .Section--install .Section-example-code { 417 | font-size: 1em; 418 | } 419 | 420 | /** 421 | * Why section. 422 | */ 423 | 424 | .Section--why { 425 | padding-top: 0; 426 | padding-bottom: 0; 427 | } 428 | } 429 | -------------------------------------------------------------------------------- /test/cases/myth.io.out.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Variables. 3 | */ 4 | 5 | /** 6 | * Body. 7 | */ 8 | 9 | body { 10 | font: 100 16px/1.5 "Source Sans", sans-serif; 11 | color: white; 12 | background-color: #1C1521; 13 | } 14 | 15 | a { 16 | color: #847AD1; 17 | text-decoration: underline; 18 | -webkit-transition: color .2s; 19 | transition: color .2s; 20 | } 21 | 22 | a:visited { 23 | color: #663399; 24 | } 25 | 26 | a:hover { 27 | color: rgb(157, 149, 218); 28 | } 29 | 30 | pre { 31 | font: 300 12px/1.2 "Source Code", monospace; 32 | color: rgb(204, 207, 221); 33 | } 34 | 35 | /** 36 | * Sections. 37 | */ 38 | 39 | .Header, 40 | .Section, 41 | .Footer { 42 | position: relative; 43 | padding: 4em 1.5em; 44 | } 45 | 46 | .Section-title { 47 | font-size: 1.5em; 48 | margin-bottom: .25em; 49 | text-align: center; 50 | } 51 | 52 | .Section-description { 53 | color: #989EBA; 54 | margin-bottom: 1em; 55 | } 56 | 57 | .Section-example { 58 | margin-top: 1em; 59 | border-radius: .2em; 60 | background: #1C1521; 61 | padding: 1em; 62 | overflow: hidden; 63 | } 64 | 65 | .Section-example-code b { 66 | font-weight: 600; 67 | color: #847AD1; 68 | } 69 | 70 | .Section-example-code em { 71 | font-style: normal; 72 | font-weight: 600; 73 | color: #5790EF; 74 | } 75 | 76 | .Section-example-code s { 77 | font-style: normal; 78 | text-decoration: none; 79 | color: #605668; 80 | } 81 | 82 | .Section-legend { 83 | text-align: center; 84 | color: #989EBA; 85 | margin-top: .75em; 86 | } 87 | 88 | /** 89 | * Header. 90 | */ 91 | 92 | .Header { 93 | background: url(images/background.jpg); 94 | background-size: cover; 95 | text-align: center; 96 | padding-bottom: 6em; 97 | } 98 | 99 | .Header-title { 100 | font-size: 1.5em; 101 | margin-bottom: 4em; 102 | } 103 | 104 | .Header-subtitle { 105 | font-size: 2.5em; 106 | margin-bottom: .6em; 107 | } 108 | 109 | .Header-description { 110 | max-width: 30em; 111 | margin-right: auto; 112 | margin-left: auto; 113 | } 114 | 115 | .Header-github-link { 116 | display: block; 117 | position: absolute; 118 | top: 3em; 119 | right: -6.5em; 120 | padding: 1em; 121 | width: 20em; 122 | text-align: center; 123 | background-color: #847AD1; 124 | text-transform: uppercase; 125 | font-size: .6em; 126 | color: white; 127 | letter-spacing: 1px; 128 | text-decoration: none; 129 | white-space: nowrap; 130 | -webkit-transform: rotate(45deg); 131 | -ms-transform: rotate(45deg); 132 | transform: rotate(45deg); 133 | -webkit-transform-origin: 50% 50%; 134 | -ms-transform-origin: 50% 50%; 135 | transform-origin: 50% 50%; 136 | } 137 | 138 | .Header-github-link:hover { 139 | font-weight: normal; 140 | color: white; 141 | } 142 | 143 | /** 144 | * Feature section. 145 | */ 146 | 147 | .Section--feature { 148 | background-color: #26202B; 149 | } 150 | 151 | .Section--feature + .Section--feature { 152 | padding-top: 0; 153 | } 154 | 155 | .animate .Section--feature .Section-title, 156 | .animate .Section--feature .Section-description, 157 | .animate .Section--feature .Section-example { 158 | opacity: 0; 159 | } 160 | 161 | .Section--feature .Section-description { 162 | text-align: center; 163 | } 164 | 165 | /** 166 | * First and last feature. 167 | */ 168 | 169 | .Section--feature-variables::before, 170 | .Section--feature-no-prefixes::after { 171 | content: ''; 172 | position: absolute; 173 | right: 0; 174 | left: 0; 175 | } 176 | 177 | /** 178 | * First feature. 179 | */ 180 | 181 | .Section--feature-variables::before { 182 | height: 6em; 183 | bottom: 100%; 184 | background: -webkit-linear-gradient(top, transparent, #26202B); 185 | background: linear-gradient(to bottom, transparent, #26202B); 186 | } 187 | 188 | /** 189 | * Last feature. 190 | */ 191 | 192 | .Section--feature-no-prefixes { 193 | padding-bottom: 2em; 194 | } 195 | 196 | .Section--feature-no-prefixes::after { 197 | height: 14em; 198 | top: 100%; 199 | background: -webkit-linear-gradient(top, #26202B, transparent); 200 | background: linear-gradient(to bottom, #26202B, transparent); 201 | } 202 | 203 | /** 204 | * Install section. 205 | */ 206 | 207 | .Section--install { 208 | padding-top: 2em; 209 | padding-bottom: 0; 210 | } 211 | 212 | .Section--install .Section-example { 213 | background-color: #120C17; 214 | } 215 | 216 | .Section--install .Section-example-code { 217 | line-height: 1.4; 218 | } 219 | 220 | /** 221 | * Why section. 222 | */ 223 | 224 | .Section--why .Section-description { 225 | color: #989EBA; 226 | } 227 | 228 | /** 229 | * Footer. 230 | */ 231 | 232 | .Footer { 233 | padding-top: 0; 234 | text-align: center; 235 | } 236 | 237 | .Footer-title { 238 | font-size: 1.5em; 239 | -webkit-transition: -webkit-transform .2s; 240 | transition: transform .2s; 241 | } 242 | 243 | .Footer-title:hover { 244 | -webkit-transform: scale(1.1); 245 | -ms-transform: scale(1.1); 246 | transform: scale(1.1); 247 | } 248 | 249 | .Footer-subtitle { 250 | color: #989EBA; 251 | font-size: .7em; 252 | text-transform: uppercase; 253 | letter-spacing: 1px; 254 | margin-bottom: .5em; 255 | } 256 | 257 | /** 258 | * Animation, only happens on first load. 259 | */ 260 | 261 | .Header-subtitle { 262 | -webkit-transition: opacity 2s ease-in-out .5s; 263 | transition: opacity 2s ease-in-out .5s; 264 | } 265 | 266 | .Header-description { 267 | -webkit-transition: opacity 2s ease-in-out 2.5s; 268 | transition: opacity 2s ease-in-out 2.5s; 269 | } 270 | 271 | .Header-github-link, 272 | .Section--feature .Section-title, 273 | .Section--feature .Section-description, 274 | .Section--feature .Section-example { 275 | -webkit-transition: opacity 2s ease-in-out 4.5s; 276 | transition: opacity 2s ease-in-out 4.5s; 277 | } 278 | 279 | .animate .Header-subtitle, 280 | .animate .Header-description, 281 | .animate .Header-github-link, 282 | .animate .Section--feature .Section-title, 283 | .animate .Section--feature .Section-description, 284 | .animate .Section--feature .Section-example { 285 | opacity: 0; 286 | } 287 | 288 | /** 289 | * Small screens. 290 | */ 291 | 292 | @media (max-width: 767px) { 293 | .Section--feature .Section-example-code:last-child { 294 | display: none; 295 | /* keep it simpler, just show the api */ 296 | } 297 | 298 | .Section--install s { 299 | display: none; 300 | /* breaks the line, and just not worth it */ 301 | } 302 | } 303 | 304 | /** 305 | * Large screens. 306 | */ 307 | 308 | @media (min-width: 768px) { 309 | body { 310 | font-size: 18px; 311 | } 312 | 313 | pre { 314 | font-size: 14px; 315 | } 316 | 317 | /** 318 | * Sections. 319 | */ 320 | 321 | .Header, 322 | .Section, 323 | .Footer { 324 | padding: 6em 2em; 325 | } 326 | 327 | .Section-title { 328 | font-size: 1.8em; 329 | } 330 | 331 | .Section-example { 332 | margin-top: 1.5em; 333 | padding: 1.5em; 334 | } 335 | 336 | /** 337 | * Header. 338 | */ 339 | 340 | .Header { 341 | font-size: 1.2em; 342 | padding-bottom: 14%; 343 | } 344 | 345 | .Header-subtitle { 346 | font-size: 2.5em; 347 | } 348 | 349 | .Header-description { 350 | max-width: 30em; 351 | margin-right: auto; 352 | margin-left: auto; 353 | } 354 | 355 | .Header-github-link { 356 | top: 4em; 357 | right: -5em; 358 | } 359 | 360 | /** 361 | * Feature section. 362 | */ 363 | 364 | .Section--feature .Section-title, 365 | .Section--feature .Section-description, 366 | .Section--feature .Section-example { 367 | max-width: 40em; 368 | margin-right: auto; 369 | margin-left: auto; 370 | } 371 | 372 | .Section--feature .Section-example { 373 | background-image: url(images/example-background.png); 374 | background-position: center center; 375 | background-repeat: no-repeat; 376 | } 377 | 378 | .Section--feature .Section-example-code { 379 | width: 50%; 380 | float: left; 381 | box-sizing: border-box; 382 | } 383 | 384 | .Section--feature .Section-example-code:first-child { 385 | padding-left: 1em; 386 | } 387 | 388 | .Section--feature .Section-example-code:last-child { 389 | padding-left: 3.5em; 390 | } 391 | 392 | /** 393 | * Install & Why sections. 394 | */ 395 | 396 | .Section--install, 397 | .Section--why { 398 | max-width: 26em; 399 | margin-right: auto; 400 | margin-left: auto; 401 | } 402 | 403 | /** 404 | * Install section. 405 | */ 406 | 407 | .Section--install { 408 | padding-top: 8em; 409 | } 410 | 411 | .Section--install .Section-example { 412 | width: 24em; 413 | margin-right: auto; 414 | margin-left: auto; 415 | } 416 | 417 | .Section--install .Section-example-code { 418 | font-size: 1em; 419 | } 420 | 421 | /** 422 | * Why section. 423 | */ 424 | 425 | .Section--why { 426 | padding-top: 0; 427 | padding-bottom: 0; 428 | } 429 | } -------------------------------------------------------------------------------- /test/cli/compress.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: red; 3 | } 4 | -------------------------------------------------------------------------------- /test/cli/error.css: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Variables. 4 | */ 5 | 6 | :root { 7 | --light-purple: #989EBA; 8 | --purple: #847AD1; 9 | --dark-purple: #26202B; 10 | --darker-purple: #1C1521; 11 | --blue: #5790EF; 12 | --black: #120C17; 13 | --gray: #605668; 14 | } 15 | 16 | /** 17 | * Body. 18 | */ 19 | 20 | body { 21 | font: 100 16px/1.5 "Source Sans", sans-serif; 22 | color: white; 23 | background-color: var(--darker-purple); 24 | } 25 | 26 | a { 27 | color: var(--purple); 28 | text-decoration: underline; 29 | transition: color .2s; 30 | } 31 | 32 | a:hover { 33 | color: color(var(--purple) tint(20%)); 34 | } 35 | 36 | pre { 37 | font: 300 12px/1.2 "Source Code", monospace; 38 | color: color(var(--light-purple) tint(50%)); 39 | } 40 | 41 | /** 42 | * Sections. 43 | */ 44 | 45 | .Header, 46 | .Section, 47 | .Footer { 48 | position: relative; 49 | padding: 4em 1.5em; 50 | } 51 | 52 | .Section-title { 53 | font-size: 1.5em; 54 | margin-bottom: .25em; 55 | text-align: center; 56 | } 57 | 58 | .Section-description { 59 | color: var(--light-purple); 60 | margin-bottom: 1em; 61 | } 62 | 63 | .Section-example { 64 | margin-top: 1em; 65 | border-radius: .2em; 66 | background: var(--darker-purple); 67 | padding: 1em; 68 | overflow: hidden; 69 | } 70 | 71 | .Section-example-code b { 72 | font-weight: 600; 73 | color: var(--purple); 74 | } 75 | 76 | .Section-example-code em { 77 | font-style: normal; 78 | font-weight: 600; 79 | color: var(--blue); 80 | } 81 | 82 | .Section-example-code s { 83 | font-style: normal; 84 | text-decoration: none; 85 | color: var(--gray); 86 | } 87 | 88 | .Section-legend { 89 | text-align: center; 90 | color: var(--light-purple); 91 | margin-top: .75em; 92 | } 93 | 94 | /** 95 | * Header. 96 | */ 97 | 98 | .Header { 99 | background: url(images/background.jpg); 100 | background-size: cover; 101 | text-align: center; 102 | padding-bottom: 6em; 103 | } 104 | 105 | .Header-title { 106 | font-size: 1.5em; 107 | margin-bottom: 4em; 108 | } 109 | 110 | .Header-subtitle { 111 | font-size: 2.5em; 112 | margin-bottom: .6em; 113 | } 114 | 115 | .Header-description { 116 | max-width: 30em; 117 | margin-right: auto; 118 | margin-left: auto; 119 | } 120 | 121 | .Header-github-link { 122 | display: block; 123 | position: absolute; 124 | top: 3em; 125 | right: -6.5em; 126 | padding: 1em; 127 | width: 20em; 128 | text-align: center; 129 | background-color: var(--purple); 130 | text-transform: uppercase; 131 | font-size: .6em; 132 | color: white; 133 | letter-spacing: 1px; 134 | text-decoration: none; 135 | white-space: nowrap; 136 | transform: rotate(45deg); 137 | transform-origin: 50% 50%; 138 | } 139 | 140 | .Header-github-link:hover { 141 | font-weight: normal; 142 | color: white; 143 | } 144 | 145 | /** 146 | * Feature section. 147 | */ 148 | 149 | .Section--feature { 150 | background-color: var(--dark-purple); 151 | } 152 | 153 | .Section--feature + .Section--feature { 154 | padding-top: 0; 155 | } 156 | 157 | .animate .Section--feature .Section-title, 158 | .animate .Section--feature .Section-description, 159 | .animate .Section--feature .Section-example { 160 | opacity: 0; 161 | } 162 | 163 | .Section--feature .Section-description { 164 | text-align: center; 165 | } 166 | 167 | /** 168 | * First and last feature. 169 | */ 170 | 171 | .Section--feature-variables::before, 172 | .Section--feature-no-prefixes::after { 173 | content: ''; 174 | position: absolute; 175 | right: 0; 176 | left: 0; 177 | } 178 | 179 | /** 180 | * First feature. 181 | */ 182 | 183 | .Section--feature-variables::before { 184 | height: 6em; 185 | bottom: 100%; 186 | background: linear-gradient(to bottom, transparent, var(--dark-purple)); 187 | } 188 | 189 | /** 190 | * Last feature. 191 | */ 192 | 193 | .Section--feature-no-prefixes { 194 | padding-bottom: 2em; 195 | } 196 | 197 | .Section--feature-no-prefixes::after { 198 | height: 14em; 199 | top: 100%; 200 | background: linear-gradient(to bottom, var(--dark-purple), transparent); 201 | } 202 | 203 | /** 204 | * Install section. 205 | */ 206 | 207 | .Section--install { 208 | padding-top: 2em; 209 | padding-bottom: 0; 210 | } 211 | 212 | .Section--install .Section-example { 213 | background-color: var(--black); 214 | } 215 | 216 | .Section--install .Section-example-code { 217 | line-height: 1.4; 218 | } 219 | 220 | /** 221 | * Why section. 222 | */ 223 | 224 | .Section--why .Section-description { 225 | color: var(--light-purple); 226 | } 227 | 228 | /** 229 | * Footer. 230 | */ 231 | 232 | .Footer { 233 | padding-top: 0; 234 | text-align: center; 235 | } 236 | 237 | .Footer-title { 238 | font-size: 1.5em; 239 | transition: transform .2s; 240 | } 241 | 242 | .Footer-title:hover { 243 | transform: scale(1.1); 244 | } 245 | 246 | .Footer-subtitle { 247 | font-size: .7em; 248 | color: color(var(--light-purple) tint(50%); 249 | text-transform: uppercase; 250 | letter-spacing: 1px; 251 | margin-bottom: .5em; 252 | } 253 | 254 | /** 255 | * Animation, only happens on first load. 256 | */ 257 | 258 | .Header-subtitle { 259 | transition: opacity 2s ease-in-out .5s; 260 | } 261 | 262 | .Header-description { 263 | transition: opacity 2s ease-in-out 2.5s; 264 | } 265 | 266 | .Header-github-link, 267 | .Section--feature .Section-title, 268 | .Section--feature .Section-description, 269 | .Section--feature .Section-example { 270 | transition: opacity 2s ease-in-out 4.5s; 271 | } 272 | 273 | .animate .Header-subtitle, 274 | .animate .Header-description, 275 | .animate .Header-github-link, 276 | .animate .Section--feature .Section-title, 277 | .animate .Section--feature .Section-description, 278 | .animate .Section--feature .Section-example { 279 | opacity: 0; 280 | } 281 | 282 | /** 283 | * Small screens. 284 | */ 285 | 286 | @media (max-width: 767px) { 287 | 288 | .Section--feature .Section-example-code:last-child { 289 | display: none; /* keep it simpler, just show the api */ 290 | } 291 | 292 | .Section--install s { 293 | display: none; /* breaks the line, and just not worth it */ 294 | } 295 | 296 | } 297 | 298 | /** 299 | * Large screens. 300 | */ 301 | 302 | @media (min-width: 768px) { 303 | 304 | body { 305 | font-size: 18px; 306 | } 307 | 308 | pre { 309 | font-size: 14px; 310 | } 311 | 312 | /** 313 | * Sections. 314 | */ 315 | 316 | .Header, 317 | .Section, 318 | .Footer { 319 | padding: 6em 2em; 320 | } 321 | 322 | .Section-title { 323 | font-size: 1.8em; 324 | } 325 | 326 | .Section-example { 327 | margin-top: 1.5em; 328 | padding: 1.5em; 329 | } 330 | 331 | /** 332 | * Header. 333 | */ 334 | 335 | .Header { 336 | font-size: 1.2em; 337 | padding-bottom: 14%; 338 | } 339 | 340 | .Header-subtitle { 341 | font-size: 2.5em; 342 | } 343 | 344 | .Header-description { 345 | max-width: 30em; 346 | margin-right: auto; 347 | margin-left: auto; 348 | } 349 | 350 | .Header-github-link { 351 | top: 4em; 352 | right: -5em; 353 | } 354 | 355 | /** 356 | * Feature section. 357 | */ 358 | 359 | .Section--feature .Section-title, 360 | .Section--feature .Section-description, 361 | .Section--feature .Section-example { 362 | max-width: 40em; 363 | margin-right: auto; 364 | margin-left: auto; 365 | } 366 | 367 | .Section--feature .Section-example { 368 | background-image: url(images/example-background.png); 369 | background-position: center center; 370 | background-repeat: no-repeat; 371 | } 372 | 373 | .Section--feature .Section-example-code { 374 | width: 50%; 375 | float: left; 376 | box-sizing: border-box; 377 | } 378 | 379 | .Section--feature .Section-example-code:first-child { 380 | padding-left: 1em; 381 | } 382 | 383 | .Section--feature .Section-example-code:last-child { 384 | padding-left: 3.5em; 385 | } 386 | 387 | /** 388 | * Install & Why sections. 389 | */ 390 | 391 | .Section--install, 392 | .Section--why { 393 | max-width: 26em; 394 | margin-right: auto; 395 | margin-left: auto; 396 | } 397 | /** 398 | * Install section. 399 | */ 400 | 401 | .Section--install { 402 | padding-top: 8em; 403 | } 404 | 405 | .Section--install .Section-example { 406 | width: 24em; 407 | margin-right: auto; 408 | margin-left: auto; 409 | } 410 | 411 | .Section--install .Section-example-code { 412 | font-size: 1em; 413 | } 414 | 415 | /** 416 | * Why section. 417 | */ 418 | 419 | .Section--why { 420 | padding-top: 0; 421 | padding-bottom: 0; 422 | } 423 | 424 | } -------------------------------------------------------------------------------- /test/cli/input.css: -------------------------------------------------------------------------------- 1 | 2 | :root { 3 | --red: #f00; 4 | } 5 | 6 | ::placeholder { 7 | color: var(--red); 8 | width: calc(50px * 2); 9 | font-variant: small-caps; 10 | transition: all 1s; 11 | } -------------------------------------------------------------------------------- /test/cli/input.out.css: -------------------------------------------------------------------------------- 1 | ::-webkit-input-placeholder { 2 | color: #f00; 3 | width: 100px; 4 | -webkit-font-feature-settings: "c2sc"; 5 | font-feature-settings: "c2sc"; 6 | font-variant: small-caps; 7 | -webkit-transition: all 1s; 8 | transition: all 1s; 9 | } 10 | 11 | ::-moz-placeholder { 12 | color: #f00; 13 | width: 100px; 14 | -moz-font-feature-settings: "c2sc"; 15 | font-feature-settings: "c2sc"; 16 | font-variant: small-caps; 17 | transition: all 1s; 18 | } 19 | 20 | :-ms-input-placeholder { 21 | color: #f00; 22 | width: 100px; 23 | font-feature-settings: "c2sc"; 24 | font-variant: small-caps; 25 | transition: all 1s; 26 | } 27 | 28 | ::placeholder { 29 | color: #f00; 30 | width: 100px; 31 | -webkit-font-feature-settings: "c2sc"; 32 | -moz-font-feature-settings: "c2sc"; 33 | font-feature-settings: "c2sc"; 34 | font-variant: small-caps; 35 | -webkit-transition: all 1s; 36 | transition: all 1s; 37 | } -------------------------------------------------------------------------------- /test/features/calc.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | width: calc(50px * 2); 4 | } -------------------------------------------------------------------------------- /test/features/calc.out.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | width: 100px; 4 | } -------------------------------------------------------------------------------- /test/features/color.css: -------------------------------------------------------------------------------- 1 | 2 | p { 3 | color: color(black tint(10%)); 4 | background-color: color(rgba(255, 255, 255, .5) alpha(100%)); 5 | } 6 | 7 | @media (min-width: 10px) { 8 | p { 9 | color: color(black tint(10%)); 10 | background-color: color(rgba(255, 255, 255, .5) alpha(100%)); 11 | } 12 | } -------------------------------------------------------------------------------- /test/features/color.out.css: -------------------------------------------------------------------------------- 1 | 2 | p { 3 | color: rgb(25, 25, 25); 4 | background-color: rgb(255, 255, 255); 5 | } 6 | 7 | @media (min-width: 10px) { 8 | p { 9 | color: rgb(25, 25, 25); 10 | background-color: rgb(255, 255, 255); 11 | } 12 | } -------------------------------------------------------------------------------- /test/features/custom-media.css: -------------------------------------------------------------------------------- 1 | @custom-media --narrow-window screen and (max-width: 30em); 2 | 3 | @media (--narrow-window) { 4 | /* narrow window styles */ 5 | } -------------------------------------------------------------------------------- /test/features/custom-media.out.css: -------------------------------------------------------------------------------- 1 | @media screen and (max-width: 30em) { 2 | /* narrow window styles */ 3 | } -------------------------------------------------------------------------------- /test/features/font-variant.css: -------------------------------------------------------------------------------- 1 | 2 | h2 { 3 | font-variant-caps: all-small-caps; 4 | } -------------------------------------------------------------------------------- /test/features/font-variant.out.css: -------------------------------------------------------------------------------- 1 | 2 | h2 { 3 | -webkit-font-feature-settings: "smcp", "c2sc"; 4 | -moz-font-feature-settings: "smcp", "c2sc"; 5 | font-feature-settings: "smcp", "c2sc"; 6 | font-variant-caps: all-small-caps; 7 | } -------------------------------------------------------------------------------- /test/features/hex-alpha.css: -------------------------------------------------------------------------------- 1 | 2 | input { 3 | background-color: #39fa; 4 | } -------------------------------------------------------------------------------- /test/features/hex-alpha.out.css: -------------------------------------------------------------------------------- 1 | 2 | input { 3 | background-color: rgba(51,153,255,0.6666666666666666); 4 | } -------------------------------------------------------------------------------- /test/features/import.css: -------------------------------------------------------------------------------- 1 | 2 | @import "import.include.css"; 3 | 4 | body { 5 | color: red; 6 | } -------------------------------------------------------------------------------- /test/features/import.include.css: -------------------------------------------------------------------------------- 1 | 2 | html { 3 | color: black; 4 | } -------------------------------------------------------------------------------- /test/features/import.out.css: -------------------------------------------------------------------------------- 1 | 2 | html { 3 | color: black; 4 | } 5 | 6 | body { 7 | color: red; 8 | } -------------------------------------------------------------------------------- /test/features/prefixes.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | transition: transform 1s; 4 | } 5 | 6 | :fullscreen a { 7 | display: flex; 8 | } 9 | 10 | @keyframes moving-gradient { 11 | 0% { 12 | background-position: left bottom; 13 | } 14 | 15 | 100% { 16 | background-position: right bottom; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /test/features/prefixes.out.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | -webkit-transition: -webkit-transform 1s; 4 | transition: transform 1s; 5 | } 6 | 7 | :-webkit-full-screen a { 8 | display: -webkit-box; 9 | display: -webkit-flex; 10 | display: flex; 11 | } 12 | 13 | :-moz-full-screen a { 14 | display: flex; 15 | } 16 | 17 | :-ms-fullscreen a { 18 | display: -ms-flexbox; 19 | display: flex; 20 | } 21 | 22 | :fullscreen a { 23 | display: -webkit-box; 24 | display: -webkit-flex; 25 | display: -ms-flexbox; 26 | display: flex; 27 | } 28 | 29 | @-webkit-keyframes moving-gradient { 30 | 0% { 31 | background-position: left bottom; 32 | } 33 | 34 | 100% { 35 | background-position: right bottom; 36 | } 37 | } 38 | 39 | @keyframes moving-gradient { 40 | 0% { 41 | background-position: left bottom; 42 | } 43 | 44 | 100% { 45 | background-position: right bottom; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/features/rebeccapurple.css: -------------------------------------------------------------------------------- 1 | * { 2 | color: rebeccapurple; 3 | } 4 | -------------------------------------------------------------------------------- /test/features/rebeccapurple.out.css: -------------------------------------------------------------------------------- 1 | * { 2 | color: #663399; 3 | } -------------------------------------------------------------------------------- /test/features/variables.css: -------------------------------------------------------------------------------- 1 | 2 | :root { 3 | --red: #F00; 4 | } 5 | 6 | body { 7 | color: var(--red); 8 | } 9 | 10 | :root { 11 | --red: #0F0; 12 | } -------------------------------------------------------------------------------- /test/features/variables.out.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | color: #0F0; 4 | } -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 2 | var assert = require('assert'); 3 | var child = require('child_process'); 4 | var exec = child.exec; 5 | var spawn = child.spawn; 6 | var fs = require('fs'); 7 | var myth = require('..'); 8 | var browser = require('../myth.js'); 9 | var path = require('path'); 10 | var slugify = require('to-slug-case'); 11 | var spaceify = require('to-space-case'); 12 | var Stream = require('stream').Readable; 13 | 14 | /** 15 | * Myth tests. 16 | */ 17 | 18 | describe('myth', function(){ 19 | it('should return a css string', function(){ 20 | assert('string' == typeof myth('body {}')); 21 | }); 22 | 23 | it('should return a rework plugin', function(){ 24 | assert('function' == typeof myth()); 25 | }); 26 | }); 27 | 28 | /** 29 | * Feature tests. 30 | */ 31 | 32 | describe('features', function(){ 33 | myth.features.forEach(function(name){ 34 | var slug = slugify(name); 35 | var source = resolve('features/' + slug); 36 | var input = read('features/' + slug); 37 | var expected = read('features/' + slug + '.out'); 38 | 39 | describe(slug, function(){ 40 | it('should add ' + slug + ' node support', function(){ 41 | var css = myth(input, { source: source }); 42 | assert.equal(css.trim(), expected.trim()); 43 | }); 44 | 45 | it('should be able to disable ' + slug + ' node support', function(){ 46 | var options = { source: source, features: {} }; 47 | options.features[name] = false; 48 | var css = myth(input, options); 49 | assert.notEqual(css.trim(), expected.trim()); 50 | assert.equal(css.trim(), input.trim()); 51 | }); 52 | 53 | if ('import' == name) return; 54 | 55 | it('should add ' + slug + ' browser support', function(){ 56 | var css = browser(input); 57 | assert.equal(css.trim(), expected.trim()); 58 | }); 59 | 60 | it('should be able to disable ' + slug + ' browser support', function(){ 61 | var options = { features: {} }; 62 | options.features[name] = false; 63 | var css = browser(input, options); 64 | assert.notEqual(css.trim(), expected.trim()); 65 | assert.equal(css.trim(), input.trim()); 66 | }); 67 | }); 68 | }); 69 | }); 70 | 71 | /** 72 | * Sourcemap tests. 73 | */ 74 | 75 | describe('sourcemap', function(){ 76 | it('should contain a correct sourcemap', function(){ 77 | var input = read('sourcemap/in'); 78 | var output = read('sourcemap/out'); 79 | var options = { 80 | source: './test/sourcemap/in.css', 81 | sourcemap: true 82 | }; 83 | var css = myth(input, options); 84 | debugger; 85 | assert.equal(css.trim(), output.trim()); 86 | }); 87 | }); 88 | 89 | /** 90 | * CLI tests. 91 | */ 92 | 93 | describe('cli', function(){ 94 | var input = read('cli/input'); 95 | var output = read('cli/input.out'); 96 | 97 | afterEach(function(){ 98 | remove('cli/output'); 99 | }); 100 | 101 | it('should read from a file and write to a file', function(done){ 102 | exec('bin/myth test/cli/input.css test/cli/output.css', function(err, stdout){ 103 | if (err) return done(err); 104 | var res = read('cli/output'); 105 | assert.equal(res, output); 106 | done(); 107 | }); 108 | }); 109 | 110 | it('should read from a file and write to stdout', function(done){ 111 | exec('bin/myth test/cli/input.css', function(err, stdout){ 112 | if (err) return done(err); 113 | assert.equal(stdout, output); 114 | done(); 115 | }); 116 | }); 117 | 118 | it('should read from stdin and write to stdout', function(done){ 119 | var child = exec('bin/myth', function(err, stdout){ 120 | if (err) return done(err); 121 | assert.equal(stdout, output); 122 | done(); 123 | }); 124 | 125 | child.stdin.write(new Buffer(input)); 126 | child.stdin.end(); 127 | }); 128 | 129 | it('should error on non-existant file', function(done){ 130 | exec('bin/myth test/cli/non-existant.css', function(err, stdout, stderr){ 131 | assert(err); 132 | assert(err.code == 1); 133 | assert(-1 != stderr.indexOf('not found')); 134 | done(); 135 | }); 136 | }); 137 | 138 | it('should print a nice error', function(done){ 139 | exec('bin/myth test/cli/error.css', function(err, stdout, stderr){ 140 | assert(err); 141 | assert(err.code == 1); 142 | assert(-1 != stderr.indexOf('Error')); 143 | assert(-1 != stderr.indexOf('rework-vars: missing closing ")"')); 144 | assert(-1 != stderr.indexOf('color(')); 145 | assert(-1 != stderr.indexOf('at ')); 146 | done(); 147 | }); 148 | }); 149 | 150 | it('should ignore errors on --ignore-errors', function(done){ 151 | exec('bin/myth --ignore-errors test/cli/error.css', function(err, stdout, stderr){ 152 | if (err) return done(err); 153 | assert(-1 == stderr.indexOf('Error')); 154 | assert(-1 == stderr.indexOf('rework-vars: missing closing ")"')); 155 | assert(-1 == stderr.indexOf('color(')); 156 | assert(-1 == stderr.indexOf('at ')); 157 | done(); 158 | }); 159 | }); 160 | 161 | it('should log on --verbose', function(done){ 162 | exec('bin/myth --verbose test/cli/input.css test/cli/output.css', function(err, stdout){ 163 | if (err) return done(err); 164 | assert(-1 != stdout.indexOf('write')); 165 | done(); 166 | }); 167 | }); 168 | 169 | it('should minify on --compress', function(done){ 170 | exec('bin/myth --compress test/cli/compress.css', function(err, stdout, stderr){ 171 | if (err) return done(err); 172 | assert.equal(stdout, 'body{color:red;}'); 173 | done(); 174 | }); 175 | }); 176 | 177 | myth.features.forEach(function(feature){ 178 | var space = spaceify(feature); 179 | var slug = slugify(feature); 180 | var output = read('features/' + slug); 181 | it('should disable ' + space + ' on --no-' + slug, function(done){ 182 | exec('bin/myth --no-' + slug + ' test/features/' + slug + '.css', function(err, stdout, stderr){ 183 | if (err) return done(err); 184 | assert.equal(stdout.trim(), output.trim()); 185 | done(); 186 | }); 187 | }); 188 | }); 189 | }); 190 | 191 | /** 192 | * A few real-life test cases. 193 | */ 194 | 195 | describe('cases', function(){ 196 | var cases = [ 197 | 'myth.io' 198 | ]; 199 | 200 | cases.forEach(function(name){ 201 | it('should convert ' + name + '\'s css', function(){ 202 | var input = read('cases/' + name); 203 | var output = read('cases/' + name + '.out'); 204 | assert.equal(myth(input).trim(), output.trim()); 205 | }); 206 | }); 207 | }); 208 | 209 | /** 210 | * Read a fixture by `filename`. 211 | * 212 | * @param {String} filename 213 | * @return {String} 214 | */ 215 | 216 | function read(filename){ 217 | var file = resolve(filename); 218 | return fs.readFileSync(file, 'utf8'); 219 | } 220 | 221 | /** 222 | * Remove a fixture by `filename`. 223 | * 224 | * @param {String} filename 225 | */ 226 | 227 | function remove(filename){ 228 | var file = resolve(filename); 229 | if (!fs.existsSync(file)) return; 230 | fs.unlinkSync(file); 231 | } 232 | 233 | /** 234 | * Resolve a fixture by `filename`. 235 | * 236 | * @param {String} filename 237 | * @return {String} 238 | */ 239 | 240 | function resolve(filename){ 241 | return path.resolve(__dirname, filename + '.css'); 242 | } 243 | -------------------------------------------------------------------------------- /test/sourcemap/imported.css: -------------------------------------------------------------------------------- 1 | 2 | html { 3 | background: blue; 4 | } 5 | -------------------------------------------------------------------------------- /test/sourcemap/in.css: -------------------------------------------------------------------------------- 1 | 2 | @import "imported.css"; 3 | 4 | body { 5 | color: red 6 | } 7 | -------------------------------------------------------------------------------- /test/sourcemap/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Please view source & check sourcemap

4 | -------------------------------------------------------------------------------- /test/sourcemap/out.css: -------------------------------------------------------------------------------- 1 | 2 | html { 3 | background: blue; 4 | } 5 | 6 | body { 7 | color: red; 8 | } 9 | 10 | 11 | /*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3Qvc291cmNlbWFwL2ltcG9ydGVkLmNzcyIsInRlc3Qvc291cmNlbWFwL2luLmNzcyIsInNvdXJjZS5jc3MiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0E7RUFDRTs7O0FDQ0Y7RUFDRTs7O0FDR0YiLCJzb3VyY2VzQ29udGVudCI6WyJcbmh0bWwge1xuICBiYWNrZ3JvdW5kOiBibHVlO1xufVxuIiwiXG5AaW1wb3J0IFwiaW1wb3J0ZWQuY3NzXCI7XG5cbmJvZHkge1xuICBjb2xvcjogcmVkXG59XG4iLCJodG1sIHtcbiAgYmFja2dyb3VuZDogYmx1ZTtcbn1cblxuYm9keSB7XG4gIGNvbG9yOiByZWQ7XG59XG4vKiMgc291cmNlTWFwcGluZ1VSTD1kYXRhOmFwcGxpY2F0aW9uL2pzb247YmFzZTY0LGV5SjJaWEp6YVc5dUlqb3pMQ0p6YjNWeVkyVnpJanBiSW5SbGMzUXZjMjkxY21ObGJXRndMMmx0Y0c5eWRHVmtMbU56Y3lJc0ltbHVMbU56Y3lJc0luUmxjM1F2YzI5MWNtTmxiV0Z3TDJsdUxtTnpjeUpkTENKdVlXMWxjeUk2VzEwc0ltMWhjSEJwYm1keklqb2lRVUZEUVR0RlFVTkZMR2xDUVVGQk8wTkRRVVE3TzBGRFEwUTdSVUZEUlN4WFFVRkJPME5FUlVRaUxDSm1hV3hsSWpvaWFXNHVZM056SWl3aWMyOTFjbU5sYzBOdmJuUmxiblFpT2xzaVhHNW9kRzFzSUh0Y2JpQWdZbUZqYTJkeWIzVnVaRG9nWW14MVpUdGNibjFjYmlJc0ltaDBiV3dnZTF4dUlDQmlZV05yWjNKdmRXNWtPaUJpYkhWbE8xeHVmVnh1WEc1aWIyUjVJSHRjYmlBZ1kyOXNiM0k2SUhKbFpEdGNibjFjYmk4cUl5QnpiM1Z5WTJWTllYQndhVzVuVlZKTVBXUmhkR0U2WVhCd2JHbGpZWFJwYjI0dmFuTnZianRpWVhObE5qUXNaWGxLTWxwWVNucGhWemwxU1dwdmVreERTbnBpTTFaNVdUSldla2xxY0dKSmJsSnNZek5SZG1NeU9URmpiVTVzWWxkR2Qwd3liSFJqUnpsNVpFZFdhMHh0VG5wamVVbHpTV2swZG1SSFZucGtRemw2WWpOV2VWa3lWblJaV0VGMllWYzBkVmt6VG5wSmJEQnpTVzAxYUdKWFZucEphbkJpV0ZOM2FXSlhSbmRqUjJ4MVdqTk5hVTlwU2tKUlZVNUNUekJXUWxFd1ZUZFBlblJDVVRCT1IwOHdWa0pSTUZWcFRFTktlbUl6Vm5sWk1sWjZVVEk1ZFdSSFZuVmtRMGsyVjNsS1kySnRhREJpVjNkblpURjRkVWxEUW1sWlYwNXlXak5LZG1SWE5XdFBhVUpwWWtoV2JFOHhlSFZtVm5oMVNXbDNhVmhITlVGaFZ6RjNZak5LTUVsR2QybGhWekYzWWpOS01GcFhVWFZaTTA1NldFTkpOMWhITldOaWJVcDJXa2hyWjJVeGVIVkpRMEpxWWpKNGRtTnFiMmRqYlZacldFYzFPVmhITkdsWVdEQTlJQ292SWl3aVhHNUFhVzF3YjNKMElGd2lhVzF3YjNKMFpXUXVZM056WENJN1hHNWNibUp2WkhrZ2UxeHVJQ0JqYjJ4dmNqb2djbVZrWEc1OVhHNGlYWDA9ICovIl19 */ 12 | --------------------------------------------------------------------------------