Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initialize

  • Loading branch information...
commit 182eef92ed3c3adf7843d1b2025088ac6373d952 0 parents
@mach3 authored
Showing with 256 additions and 0 deletions.
  1. +22 −0 LICENSE
  2. +88 −0 README.md
  3. +22 −0 package.json
  4. +124 −0 tasks/ezless.js
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2013 matsukaze.
+
+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.
88 README.md
@@ -0,0 +1,88 @@
+
+# grunt-easy-less
+
+## This is
+
+Grunt task to compile Less to CSS.
+
+This just has very simple feature, then can be used with less writing.
+If you want to configrue options more, use [grunt-contrib-less](https://github.com/gruntjs/grunt-contrib-less), awesome grunt task as official.
+
+
+## Install
+
+```
+npm install grunt-easy-less
+```
+
+## The simplest example
+
+The simplest way to add task.
+
+```javascript
+grunt.loadNpmTasks("grunt-easy-less");
+
+grunt.initConfig({
+ ezless : {
+ options : {
+ lessPath : "./assets/less",
+ cssPath : "./assets/css"
+ }
+ }
+});
+```
+
+`ezless` search the `*.less` files in `./assets/less` (not recursively), compile them to css, and save as the same name in `./assets/css` directory.
+
+For example, if you have Less files in `lessPath` as below,
+
+```
+assets/
+ less/
+ foo.less
+ bar.less
+```
+
+Compiled css file will be saved as below.
+
+```
+assets/
+ css/
+ foo.css
+ bar.css
+```
+
+## Specify the files to compile
+
+If you want to specify the less file to compile, or want to compile the less files in sub-directories,
+use `less` option.
+
+```
+grunt.initConfig({
+ ezless : {
+ options : { ... },
+ less : [
+ "foo.less",
+ "path/to/bar.less"
+ ]
+ }
+});
+```
+
+The path must be relative from `options.lessPath`. If `less` list is not blank, files not specified in the list will be ignored.
+
+## Options
+
+- lessPath : String ("less") - The path to less directory
+- cssPath : String ("css") - The path to css directory
+- verbose : Boolean (true) - Show the message log or not
+- compress : Boolean (true) - Compress the css file or not
+
+## Author
+
+mach3
+
+- [Website](http://www.mach3.jp)
+- [Blog](http://blog.mach3.jp)
+- [Twitter](http://twitter.com/mach3ss)
+
22 package.json
@@ -0,0 +1,22 @@
+{
+ "name": "grunt-easy-less",
+ "version": "0.8.2",
+ "description": "Easier less task for grunt",
+ "main": "tasks/ezless.js",
+ "dependencies": {
+ "less": "~1.3.0"
+ },
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/mach3/grunt-easy-less"
+ },
+ "keywords": [
+ "grunt",
+ "less"
+ ],
+ "author": "mach3",
+ "license": "MIT"
+}
124 tasks/ezless.js
@@ -0,0 +1,124 @@
+/**
+ * grunt-easy-less
+ * ---------------
+ * Simple less compile task for grunt
+ *
+ * @author mach3
+ * @require less
+ * @url http://github.com/mach3/grunt-easy-less
+ *
+ */
+
+module.exports = function(grunt){
+
+ grunt.registerMultiTask(
+
+ "ezless",
+ "Easily compile LESS to CSS",
+
+ function(){
+ var my = {},
+ less = require("less"),
+ path = require("path");
+
+ my.options = this.options({
+ verbose : true,
+ compress : true,
+ lessPath : "less",
+ cssPath : "css"
+ });
+ my.files = this.data.less || [];
+ my.done = this.async();
+
+ my.length = 0;
+ my.errors = 0;
+
+ my.init = function(){
+ if(! this.files.length){
+ grunt.file.expand(this.options.lessPath + "/*.less")
+ .forEach(function(value, index){
+ my.files.push(
+ value.replace(my.options.lessPath, "")
+ .replace(/^\//, "")
+ );
+ });
+ }
+ this.files = this.files.map(function(value){
+ return value.replace(/\.less$/, "");
+ });
+
+ this.run();
+ };
+
+ my.run = function(){
+ if(this.files.length){
+ this.compile(this.files.shift(), function(){
+ my.run();
+ });
+ } else {
+ grunt.log.writeln("\nfailed " + this.errors + " in " + this.length);
+ this.done();
+ }
+ };
+
+ my.compile = function(file, callback){
+ var lessfile, cssfile, parser;
+
+ this.length += 1;
+
+ lessfile = this.getPath(this.options.lessPath, file, "less");
+ cssfile = this.getPath(this.options.cssPath, file, "css");
+ parser = new less.Parser({
+ paths : [
+ path.dirname(less),
+ this.options.lessPath
+ ]
+ });
+ parser.parse(grunt.file.read(lessfile), function(error, tree){
+ try {
+ if(error){
+ my.log(error, true);
+ my.errors += 1;
+ } else {
+ grunt.file.write(cssfile, tree.toCSS({
+ compress : my.options.compress
+ }));
+ my.log(cssfile + " <= " + lessfile);
+ }
+ } catch(e){
+ my.lessError(e, lessfile);
+ my.errors += 1;
+ }
+ callback();
+ });
+ };
+
+ my.getPath = function(path, name, ext){
+ return path + "/" + name + "." + ext;
+ };
+
+ my.log = function(message, error){
+ if(this.options.verbose){
+ if(error){
+ grunt.log.errorlns(message);
+ } else {
+ grunt.log.writeln(message);
+ }
+ }
+ };
+
+ my.lessError = function(e, lessfile){
+ if(this.options.verbose){
+ var message = "[!] {{message}} ({{file}} at line {{line}})"
+ .replace("{{file}}", lessfile)
+ .replace("{{line}}", e.line)
+ .replace("{{message}}", e.message);
+ grunt.log.errorlns(message);
+ }
+ };
+
+ my.init();
+ }
+ );
+
+};
Please sign in to comment.
Something went wrong with that request. Please try again.