On Github jolicode / assez-tic-de-perdre-du-temps-automatisez-conf
Présentation par Claire Coloma / JoliCode
Scss
$primary-color : #cc6699;
Less
@primary-color : #5d83a3;
Stylus
primary-color = #b3d107 // or $primary-color = #b3d107
Scss
@mixin error($borderWidth: 2px) { border: $borderWidth solid #F00; color: #F00; } .generic-error { padding: 20px; margin: 4px; @include error(); } .login-error { left: 12px; position: absolute; top: 20px; @include error(5px); }La mixin error prend un argument optionnel qui est ici $borderWidth valant par défaut 2px En Scss on utilise l’instruction @mixin pour déclarer notre “fonction” et on y fait appel avec l’instruction @include.
Less
.error(@borderWidth: 2px) { border: @borderWidth solid #F00; color: #F00; } .generic-error { padding: 20px; margin: 4px; .error(); } .login-error { left: 12px; position: absolute; top: 20px; .error(5px); }En LESS on utilise plutôt les sélecteur de classe
Stylus
error(borderWidth= 2px) { border: borderWidth solid #F00; color: #F00; } .generic-error { padding: 20px; margin: 4px; error(); } .login-error { left: 12px; position: absolute; top: 20px; error(5px); }En Stylus les mixins se créent de la même façon que l’on crée une fonction en PHP
Scss / Stylus
.block { margin: 10px 5px; padding: 2px; } p { @extend .block; border: 1px solid #EEE; } ul, ol { @extend .block; color: #333; text-transform: uppercase; }
Rendu CSS
.block, p, ul, ol { margin: 10px 5px; padding: 2px; } p { border: 1px solid #EEE; } ul, ol { color: #333; text-transform: uppercase; }
LESS
.block { margin: 10px 5px; padding: 2px; } p { .block; border: 1px solid #EEE; } ul, ol { .block; color: #333; text-transform: uppercase; }
Rendu CSS
.block { margin: 10px 5px; padding: 2px; } p { margin: 10px 5px; padding: 2px; border: 1px solid #EEE; } ul, ol { margin: 10px 5px; padding: 2px; color: #333; text-transform: uppercase; }
CSS
nav ul { margin: 0; padding: 0; list-style: none; } nav li { display: inline-block; } nav a { display: block; padding: 6px 12px; text-decoration: none; }
Scss / LESS / Stylus
nav { ul { margin: 0; padding: 0; list-style: none; } li { display: inline-block; } a { display: block; padding: 6px 12px; text-decoration: none; } }
Sass
$ sass input.scss output.css
LESS
$ lessc input.less output.css
Stylus
$ stylus < input.styl > output.css
Sass
$ sass --watch input.scss:output.css
Stylus
$ stylus --watch < input.styl > output.cssMalheureusement LESS ne dispose pas de cette fonctionnalité
Sass
$ sass app/sass:public/stylesheets
Stylus
$ stylus styl/SASS : watch nécessaire Avec stylus on a juste indiqué le nom du dossier qui contient les .styl, cependant on ne peut pas indiquer le dossier de destination. LESS ne permet pas cette compilation, la solution serait de créer un fichier .less qui importe tous les fichiers less à compiler.
LESS
$ lessc --clean-css input.less output.css
Sass
$ sass input.scss output.css --style compressed
Stylus
$ stylus < input.styl > output.css --compressLes 3 préprocesseurs permettent de récupérer un fichier css directement minifier.
Sass (2006)
371
3 912
722
LESS (Fév. 2010)
606
10 627
2 367
Stylus (Déc. 2010)
225
4 464
621
Issues :
116 Open
1 177 Closed
Issues :
250 Open
1 815 Closed
Issues :
168 Open
1 426 Closed
* Données récupérées le 21/06/14
Besoin d'aucun des deux
doClick = function(e) { return console.log(e.index); };
doClick = (e) -> console.log(e.index)
var math; math = { square: function(x) { return Math.sqrt(x); }, cube: function(x) { return x * square(x); } }; alert("Three cubed is " + (math.cube(3)));
math = square: (x) -> Math.sqrt x cube: (x) -> x * square x alert "Three cubed is #{math.cube 3}"
if (typeof joli !=="undefined" && joli !==null) { alert("I knew it!"); }
alert "I knew it!" if joli?
JavaScript
Hello
CoffeeScript
$ coffee --compile --output js/ chocolate.coffee
$ coffee --compile --output js/ coffeedir/
$ coffee --watch --compile chocolate.coffee
$ coffee --join js/project.js --compile coffee/
{% stylesheets 'bundles/event/css/event.css' 'bundles/event/css/buttons.css' 'bundles/event/css/main.css' filter='cssrewrite' filter='cssmin' output='css/generated/layout.css' %} <link rel="stylesheet" href="{{ asset_url }}"> {% endstylesheets %}
<link rel="stylesheet" href="/app_dev.php/css/all_main1.css" type="text/css">
{% javascripts '@AcmeFooBundle/Resources/public/coffee/*' '@SiteBundle/Resources/public/coffee/form.coffee' output='js/compiled/main.js' filter='coffee' %} <script src="{{ asset_url }}"></script> {% endjavascripts %}
# app/config/config.yml # Assetic Configuration assetic: debug: "%kernel.debug%" use_controller: false bundles: ['AcmeFooBundle', 'SiteBundle'] filters: sass: ~ compass: ~
$ php app/console asset:install web -symlink
$ php app/console assetic:dump --watch
$ php app/console assetic:dump --env=prod --no-debug
$ npm install -g grunt $ npm install -g grunt-cli
{ "name": "My badass project", "description": "Des poneys et des petits coeurs partout partout" "version": "0.0.1", "author": "Claire COLOMA", "devDependencies": { "grunt": "~0.4.1", "grunt-contrib-jshint": "~0.6.4", "grunt-contrib-cssmin": "~0.4.1", "grunt-contrib-uglify": "~0.2.4", "grunt-contrib-watch": "~0.5.3", }, }
$ npm install
module.exports = function(grunt) { // Importation des différents modules grunt grunt.loadNpmTasks('grunt-plugin'); // Configuration des plugins grunt.initConfig({}); // Déclaration des différentes tâches grunt.registerTask('default', ['tache1', 'tache2']); };
module.exports = function(grunt) { // Importation des différents modules grunt grunt.loadNpmTasks('grunt-contrib-compress'); grunt.loadNpmTasks('grunt-contrib-connect'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-watch'); };
module.exports = function(grunt) { require('load-grunt-tasks')(grunt); };
module.exports = function(grunt) { grunt.initConfig({ coffee: { compile: { files: { 'js/output1.js': 'coffee/input1.coffee', 'js/output2.js': 'coffee/input2.coffee' } } }, sass: { dist: { options : { style: 'compressed' }, files: { 'css/output1.css': 'scss/input1.scss', 'css/output2.css': 'scss/input2.scss' } } }, watch: { css: { files: ['scss/*.scss'], tasks: ['sass'], } script: { files: ['coffee/*.coffee'], tasks: ['coffee'] } } }); };
module.exports = function(grunt) { // Déclaration des tâches grunt.registerTask('compress', ['sass', 'coffee']); grunt.registerTask('default', ['compress', 'watch']); grunt.registerTask( 'serve', [ 'connect', 'watch'] ); };
$ grunt [task-name]
module.exports = function(grunt) { grunt.initConfig({ sass: { dist: { files: [{ expand: true, cwd: 'css/theme/source/', src: ['*.scss'], dest: 'css/theme/', ext: '.css' }] } }, watch: { css: { files: ['scss/*.scss'], tasks: ['sass'], } } }); // Importation des différents modules grunt require('load-grunt-tasks')(grunt); // Déclaration des tâches grunt.registerTask('default', ['sass','watch']); };
var gulp = require ('gulp'); // Importation des plugins var sass = require('gulp-sass'); var cssmin = require('gulp-cssmin'); // Traitement des tâches gulp.task('sass', function () { gulp.src('scss/*.scss') .pipe(plumber()) .pipe(sass()) .pipe(gulp.dest('css/')) .pipe(rename({suffix:'.min'})) .pipe(cssmin()) .pipe(gulp.dest('css/')) }); gulp.task('watch', function() { gulp.watch('scss/*.scss', ['sass']); }) gulp.task('default', ['sass', 'watch']);
$ npm install -g gulp
$ npm install gulp --save-dev
{ "devDependencies": { "gulp": "~3.6.2", "gulp-connect": "~2.0.5", "gulp-jshint": "~1.6.1", "gulp-sass": "~0.7.1", "gulp-plumber": "~0.6.2", }, }
$ npm install
// Importation de l'API var gulp = require ('gulp'); // Importation des plugins var task = require('gulp-task'); // Traitement des tâches gulp.task('default', ['task1', 'task2']);
$ gulp [task-name]
$ bower install package-name
$ bower install package-name#version
$ bower install https://github.com/user-name/package-name
{ "directory": "vendor/bower_components" }
{ "name": "My badass project", "description": "Des poneys et des petits coeurs partout partout" "version": "0.0.1", "author": "Claire COLOMA", }, "dependencies": { "angular": "~1.2.13", "modernizr": "~2.6.2", "moment": "~2.4.0", "underscore": "~1.4.4", }, }
<script src="vendor/bower_components/jquery/jquery.js"></script>
$ bower update package-name
Claire COLOMA / @_ClaireColoma http://jolicode.github.io/phptourconf-tools