Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadYounes committed Feb 17, 2016
1 parent ad23068 commit 7853d9d
Show file tree
Hide file tree
Showing 9 changed files with 375 additions and 125 deletions.
19 changes: 8 additions & 11 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* grunt-rtlcss
* https://github.com/MohammadYounes/grunt-rtlcss
*
* Copyright (c) 2014 Mohammad Younes
* Copyright (c) 2016 Mohammad Younes
* Licensed under the MIT license.
*/
'use strict'
Expand All @@ -29,26 +29,23 @@ module.exports = function (grunt) {
// Configuration to be run (and then tested).
rtlcss: {
default_options: {
// task options
options: {
//default
},
files: {
'tmp/default_options.css': 'test/fixtures/style.css'
}
},
custom_options: {
// task options
options: {
// rtlcss options
config: {
preserveDirectives: true
},
// extend rtlcss rules
rules: [],
// extend rtlcss declarations
declarations: [],
// extend rtlcss properties
properties: [],
// generate source maps
map: {inline: false},
// rtlcss options
opts: {
clean: false
},
// save unmodified files
saveUnmodified: true,
},
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Mohammad Younes
Copyright (c) 2016 Mohammad Younes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
95 changes: 39 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,52 +32,32 @@ Task targets, files and options may be specified according to the grunt [Configu

### Options

#### options.config
#### options.opts
Description: Specifies [RTLCSS options](https://github.com/MohammadYounes/rtlcss#options-object).

Type: `Object`

Default:

```JS
```js
{
preserveComments: true,
preserveDirectives: false,
swapLeftRightInUrl: true,
swapLtrRtlInUrl: true,
swapWestEastInUrl: true,
autoRename: true,
greedy: false,
stringMap:[...],
enableLogging: false,
minify:false
"autoRename": false,
"autoRenameStrict": false,
"blacklist":{},
"clean": true,
"greedy": false,
"processUrls": false,
"stringMap":[]
}
```

#### options.rules
Description: Specifies custom [RTLCSS rule level](https://github.com/MohammadYounes/rtlcss#rules-array) processing instructions.

Type: `Array`

Default: `[]`


#### options.declarations
Description: Specifies custom [RTLCSS declaration level](https://github.com/MohammadYounes/rtlcss#declarations-array) processing instructions.

Type: `Array`

Default: `[]`


#### options.properties
Description: Specifies custom [RTLCSS property level](https://github.com/MohammadYounes/rtlcss#properties-array) processing instructions.
#### options.plugins
Description: Specifies custom [RTLCSS plugins](https://github.com/MohammadYounes/rtlcss#plugins-array).

Type: `Array`

Default: `[]`


#### options.map
Description: Specifies whether to generate source maps or not, If you want more control over source map generation, you can define the map option as an object. (see [postcss docs](https://github.com/postcss/postcss/blob/master/docs/source-maps.md#options)).

Expand All @@ -92,43 +72,46 @@ Type: `Boolean`

Default: `true`


### Usage Example

```JS
```js
rtlcss: {
'default':{
options:{
// rtlcss options
config:{
preserveComments: false,
greedy: true
},
// extend rtlcss rules
rules:[],
// extend rtlcss declarations
declarations:[],
// extend rtlcss properties
properties:[],
// generate source maps
map: false,
// save unmodified files
saveUnmodified:true,
},
expand : true,
cwd : 'ltr/',
dest : 'rtl/',
src : ['**/*.css']
myTask:{
// task options
options: {
// generate source maps
map: {inline: false},
// rtlcss options
opts: {
clean:false
},
// rtlcss plugins
plugins:[],
// save unmodified files
saveUnmodified: true,
},
expand : true,
cwd : 'ltr/',
dest : 'rtl/',
src : ['**/*.css']
}
}
```


[RTLCSS]: https://github.com/MohammadYounes/rtlcss

-------

## Release History

* **v2.0.0** [18 Feb 2016]
* Upgrade to [RTLCSS] v2.x
* `options.config` renamed to `options.opts` (avoids confusion with [RTLCSS Config](https://github.com/MohammadYounes/rtlcss/blob/master/.rtlcssrc)).
* `options.rules`, `options.declarations` and `options.properties` removed in favor of the new `options.plugins`.

[RTLCSS] options have changed, to view a summary of changes, see [RTLCSS Upgrade guide](https://github.com/MohammadYounes/rtlcss/blob/master/CHANGELOG.md#upgrading-from-version-10).

---
* **v1.6.0** [15 Mar 2015]
* Upgrade dependency (chalk v1.x.x).

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-rtlcss",
"description": "grunt plugin for RTLCSS, a framework for transforming CSS from LTR to RTL.",
"version": "1.6.0",
"version": "2.0.0",
"homepage": "https://github.com/MohammadYounes/grunt-rtlcss",
"author": {
"name": "Mohammad Younes",
Expand All @@ -28,7 +28,7 @@
"test": "grunt test"
},
"dependencies": {
"rtlcss": "^1.0.0",
"rtlcss": "^2.0.0",
"chalk": "^1.0.0"
},
"devDependencies": {
Expand Down
82 changes: 37 additions & 45 deletions tasks/rtlcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,71 @@
* grunt-rtlcss
* https://github.com/MohammadYounes/grunt-rtlcss
*
* Copyright (c) 2014 Mohammad Younes
* Copyright (c) 2016 Mohammad Younes
* Licensed under the MIT license.
*/
module.exports = function(grunt) {
'use strict';

grunt.registerMultiTask('rtlcss', 'grunt plugin for rtlcss, a framework for transforming CSS from LTR to RTL.', function() {
module.exports = function (grunt) {
'use strict'

grunt.registerMultiTask('rtlcss', 'grunt plugin for rtlcss, a framework for transforming CSS from LTR to RTL.', function () {
var rtlcss = require('rtlcss'),
chalk = require('chalk')
;
postcss = require('rtlcss/node_modules/postcss'),
chalk = require('chalk')

// Merge task-specific and/or target-specific options with these defaults.
var options = this.options({
config:{
preserveComments: true,
preserveDirectives: false,
swapLeftRightInUrl: true,
swapLtrRtlInUrl: true,
swapWestEastInUrl: true,
autoRename: true,
map: false,
opts: {
autoRename: false,
autoRenameStrict: false,
blacklist: {},
clean: true,
greedy: false,
enableLogging: false,
minify:false
processUrls: false,
stringMap: []
},
rules:[],
declarations:[],
properties:[],
map: false,
plugins: [],
saveUnmodified: true,
});
})

// postcss options
var opt = { map: options.map, from:'', to:''};
var postcssOptions = { map: options.map, from: '', to: ''}

// Iterate over all specified file groups.
this.files.forEach(function(f) {
this.files.forEach(function (f) {
// read specified files.
var src = f.src.filter(function(filepath) {
var src = f.src.filter(function (filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file ' + chalk.cyan(filepath) + ' not found.');
return false;
grunt.log.warn('Source file ' + chalk.cyan(filepath) + ' not found.')
return false
} else {
return true;
return true
}
}).map(function(filepath) {
opt.from = filepath;
}).map(function (filepath) {
postcssOptions.from = filepath
// Read file source.
return grunt.file.read(filepath);
});
return grunt.file.read(filepath)
})

// RTLCSS
opt.to = f.dest;
var result = rtlcss(options.config,
options.rules,
options.declarations,
options.properties).process(src,opt);
postcssOptions.to = f.dest
var result = postcss(rtlcss(options.opts, options.plugins)).process(src, postcssOptions)

if(!options.saveUnmodified && result.css == src ) {
grunt.log.writeln('Skip saving unmodified file ' + chalk.cyan(f.src) + '.' );
if (!options.saveUnmodified && result.css == src) {
grunt.log.writeln('Skip saving unmodified file ' + chalk.cyan(f.src) + '.')
} else {
// Write the destination file.
grunt.file.write(f.dest, result.css);
grunt.file.write(f.dest, result.css)

// Write the destination source map file.
if(options.map)
grunt.file.write(f.dest + '.map', result.map);
if (options.map)
grunt.file.write(f.dest + '.map', result.map)

// Print a success message.
grunt.log.writeln('File ' + chalk.cyan(f.dest) + ' created.');
grunt.log.writeln('File ' + chalk.cyan(f.dest) + ' created.')
}
});
});
})
})

};
}
Loading

0 comments on commit 7853d9d

Please sign in to comment.