diff options
author | Chris Rebert <code@rebertia.com> | 2014-03-05 04:50:28 +0400 |
---|---|---|
committer | Chris Rebert <code@rebertia.com> | 2014-03-05 05:48:30 +0400 |
commit | e4ccfb1765a19cf3c11a07877f9bb6701b65eb69 (patch) | |
tree | 526229531c652e3c49afcd3a9c433ea7f2a87ac9 |
initial version
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | .jshintrc | 17 | ||||
-rw-r--r-- | Gruntfile.js | 69 | ||||
-rw-r--r-- | LICENSE | 22 | ||||
-rw-r--r-- | README.md | 89 | ||||
-rw-r--r-- | package.json | 52 | ||||
-rw-r--r-- | tasks/css_flip.js | 34 | ||||
-rw-r--r-- | test/css_flip_test.js | 48 | ||||
-rw-r--r-- | test/expected/custom_options.css | 5 | ||||
-rw-r--r-- | test/expected/default_options.css | 5 | ||||
-rw-r--r-- | test/fixtures/example.css | 5 |
11 files changed, 349 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b785247 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +npm-debug.log +tmp diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..fe2f382 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,17 @@ +{ + "bitwise": true, + "curly": true, + "eqeqeq": true, + "forin": true, + "immed": true, + "indent": 2, + "latedef": true, + "newcap": true, + "noarg": true, + "node": true, + "noempty": true, + "plusplus": false, + "sub": true, + "trailing": true, + "undef": true +} diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..9e729c6 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,69 @@ +/* + * Gruntfile for grunt-css-flip + * https://github.com/twbs/grunt-css-flip + * + * Copyright (c) 2014 Chris Rebert + * Licensed under the MIT License. + */ + +'use strict'; + +module.exports = function(grunt) { + + // Project configuration. + grunt.initConfig({ + jshint: { + all: [ + 'Gruntfile.js', + 'tasks/*.js', + '<%= nodeunit.tests %>' + ], + options: { + jshintrc: '.jshintrc' + } + }, + + // Before generating any new files, remove any previously-created files. + clean: { + tests: ['tmp'] + }, + + // Configuration to be run (and then tested). + css_flip: { + default_options: { + options: {}, + files: { + 'tmp/default_options.css': 'test/fixtures/example.css' + } + }, + custom_options: { + options: { + indent: ' ' + }, + files: { + 'tmp/custom_options.css': 'test/fixtures/example.css' + } + }, + }, + + // Unit tests. + nodeunit: { + tests: ['test/*_test.js'] + }, + + }); + + // Actually load this plugin's task(s). + grunt.loadTasks('tasks'); + + // These plugins provide necessary tasks. + require('load-grunt-tasks')(grunt, {scope: 'devDependencies'}); + + // Whenever the "test" task is run, first clean the "tmp" dir, then run this + // plugin's task(s), then test the result. + grunt.registerTask('test', ['clean', 'css_flip', 'nodeunit']); + + // By default, lint and run all tests. + grunt.registerTask('default', ['jshint', 'test']); + +}; @@ -0,0 +1,22 @@ +Copyright (c) 2014 Christopher Rebert + +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: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b8c8ff2 --- /dev/null +++ b/README.md @@ -0,0 +1,89 @@ +# grunt-css-flip + +> Grunt plugin for [Twitter's css-flip](https://github.com/twitter/css-flip) + +## Getting Started +This plugin requires Grunt `~0.4.2` + +If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: + +```shell +npm install grunt-css-flip --save-dev +``` + +Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: + +```js +grunt.loadNpmTasks('grunt-css-flip'); +``` + +## The "css_flip" task + +### Overview +In your project's Gruntfile, add a section named `css_flip` to the data object passed into `grunt.initConfig()`. + +```js +grunt.initConfig({ + css_flip: { + options: { + // Task-specific options go here. + }, + your_target: { + // Target-specific file lists and/or options go here. + }, + }, +}); +``` + +### Options + +#### options.separator +Type: `String` +Default value: `', '` + +A string value that is used to do something with whatever. + +#### options.punctuation +Type: `String` +Default value: `'.'` + +A string value that is used to do something else with whatever else. + +### Usage Examples + +#### Default Options +In this example, the default options are used to do something with whatever. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result would be `Testing, 1 2 3.` + +```js +grunt.initConfig({ + css_flip: { + options: {}, + files: { + 'dest/default_options': ['src/testing', 'src/123'], + }, + }, +}); +``` + +#### Custom Options +In this example, custom options are used to do something else with whatever else. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result in this case would be `Testing: 1 2 3 !!!` + +```js +grunt.initConfig({ + css_flip: { + options: { + separator: ': ', + punctuation: ' !!!', + }, + files: { + 'dest/default_options': ['src/testing', 'src/123'], + }, + }, +}); +``` + +## Contributing +The project's coding style is laid out in the JSHint and JSCS configurations. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). + +## Release History +_(Nothing yet)_ diff --git a/package.json b/package.json new file mode 100644 index 0000000..4f3e1bc --- /dev/null +++ b/package.json @@ -0,0 +1,52 @@ +{ + "name": "grunt-css-flip", + "description": "Grunt plugin for Twitter's css-flip", + "version": "0.1.0", + "homepage": "https://github.com/twbs/grunt-css-flip", + "author": { + "name": "Chris Rebert", + "email": "code@rebertia.com", + "url": "http://chrisrebert.com" + }, + "repository": { + "type": "git", + "url": "git://github.com/twbs/grunt-css-flip.git" + }, + "bugs": { + "url": "https://github.com/twbs/grunt-css-flip/issues" + }, + "licenses": [ + { + "type": "MIT", + "url": "https://github.com/twbs/grunt-css-flip/blob/master/LICENSE" + } + ], + "engines": { + "node": ">= 0.10.0" + }, + "scripts": { + "test": "grunt test" + }, + "devDependencies": { + "grunt-contrib-jshint": "^0.8.0", + "grunt-contrib-clean": "^0.4.0", + "grunt-contrib-nodeunit": "^0.2.0", + "grunt": "^0.4.2", + "grunt-jscs-checker": "^0.4.0", + "load-grunt-tasks": "^0.4.0" + }, + "peerDependencies": { + "grunt": "~0.4.2" + }, + "keywords": [ + "gruntplugin", + "grunt", + "css", + "flip", + "bidi", + "rtl" + ], + "dependencies": { + "css-flip": "~0.3.0" + } +} diff --git a/tasks/css_flip.js b/tasks/css_flip.js new file mode 100644 index 0000000..3342f8e --- /dev/null +++ b/tasks/css_flip.js @@ -0,0 +1,34 @@ +/* + * grunt-css-flip + * https://github.com/twbs/grunt-css-flip + * + * Copyright (c) 2014 Chris Rebert + * Licensed under the MIT License. + */ + +'use strict'; + +var flip = require('css-flip'); + + +module.exports = function(grunt) { + grunt.registerMultiTask('css_flip', "Grunt plugin for Twitter's css-flip", function () { + var options = this.options({}); + + this.files.forEach(function (f) { + var originalCss = grunt.file.read(f.src); + + var flippedCss = null; + try { + flippedCss = flip(originalCss, options); + } + catch (err) { + grunt.fail.warn(err); + } + + grunt.file.write(f.dest, flippedCss); + + grunt.log.writeln('File "' + f.dest.cyan + '" created.'); + }); + }); +}; diff --git a/test/css_flip_test.js b/test/css_flip_test.js new file mode 100644 index 0000000..8eebdbc --- /dev/null +++ b/test/css_flip_test.js @@ -0,0 +1,48 @@ +'use strict'; + +var grunt = require('grunt'); + +/* + ======== A Handy Little Nodeunit Reference ======== + https://github.com/caolan/nodeunit + + Test methods: + test.expect(numAssertions) + test.done() + Test assertions: + test.ok(value, [message]) + test.equal(actual, expected, [message]) + test.notEqual(actual, expected, [message]) + test.deepEqual(actual, expected, [message]) + test.notDeepEqual(actual, expected, [message]) + test.strictEqual(actual, expected, [message]) + test.notStrictEqual(actual, expected, [message]) + test.throws(block, [error], [message]) + test.doesNotThrow(block, [error], [message]) + test.ifError(value) +*/ + +exports.css_flip = { + setUp: function(done) { + // setup here if necessary + done(); + }, + default_options: function(test) { + test.expect(1); + + var actual = grunt.file.read('tmp/default_options.css'); + var expected = grunt.file.read('test/expected/default_options.css'); + test.equal(actual, expected, 'should flip the CSS.'); + + test.done(); + }, + custom_options: function(test) { + test.expect(1); + + var actual = grunt.file.read('tmp/custom_options.css'); + var expected = grunt.file.read('test/expected/custom_options.css'); + test.equal(actual, expected, 'should flip the CSS while honoring the custom indentation specified in the options.'); + + test.done(); + }, +}; diff --git a/test/expected/custom_options.css b/test/expected/custom_options.css new file mode 100644 index 0000000..ca7e9b0 --- /dev/null +++ b/test/expected/custom_options.css @@ -0,0 +1,5 @@ +p { + border-right: 1px; + float: right; + clear: left; +}
\ No newline at end of file diff --git a/test/expected/default_options.css b/test/expected/default_options.css new file mode 100644 index 0000000..cf87455 --- /dev/null +++ b/test/expected/default_options.css @@ -0,0 +1,5 @@ +p { + border-right: 1px; + float: right; + clear: left; +}
\ No newline at end of file diff --git a/test/fixtures/example.css b/test/fixtures/example.css new file mode 100644 index 0000000..29d4746 --- /dev/null +++ b/test/fixtures/example.css @@ -0,0 +1,5 @@ +p { + border-left: 1px; + float: left; + clear: right; +} |