292
Automate All the Front-End Development Things! Text Kitt Hodsden • http://ki.tt • @kitt 1

Automate all the things

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Automate all the things

Automate All the Front-End Development Things!

Text

Kitt Hodsden • http://ki.tt • @kitt

1

Page 2: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 2

Hi!

Page 3: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Who are you?

3

Page 4: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

And what do have we here?

4

Page 5: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

http://ki.tt/cfo

5

Page 6: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 6

http://ki.tt/cfo

Page 7: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 7

http://ki.tt/cfo

http://ki.tt/cfo

Page 8: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Wait... what?

8

What are we talking about?

Page 9: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Wait... what?

9

What are we talking about?

Page 10: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

You are invited to participate in group note taking at:

http://ki.tt/cfo14notes

10

Community knowledge!

Page 11: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Prerequisites!

11

Page 12: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

node & ruby

12

We need node and ruby to use the tools we’re going to talk about.

Page 13: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 13

Setup node by downloading the installer and running it.

http://nodejs.org

Page 14: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 14

# mac / linux$ which ruby/usr/local/bin/ruby$ ruby --version ruby 2.0.0p195

# windows> where rubyC:\Ruby200\bin\ruby.exe> ruby --versionruby 2.0.0p451

Yay! Sass installed!See if you already have ruby installed

Page 15: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 15

HOMEBREWhttp://mxcl.github.com/homebrew/$ brew install ruby

RVM RUBY VERSION MANAGERhttps://rvm.io/rvm/install

Install ruby in different ways on OSX

OSX

Page 16: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 16

HOMEBREWhttp://mxcl.github.com/homebrew/$ brew install ruby

RVM RUBY VERSION MANAGERhttps://rvm.io/rvm/install

Install ruby in different ways on OSX

OSX

Page 17: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 17

https://unfiniti.com/software/mac/jewelrybox

Ruby on OSX, I recommend JewelryBox, too.

Page 18: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 18

APT / YUM$ sudo apt-get install ruby1.9.1$ sudo yum install ruby1.9.1

RVM RUBY VERSION MANAGERhttps://rvm.io/rvm/install

Install ruby in different ways on Linux

Linux

Page 19: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 19

APT / YUM$ sudo apt-get install ruby1.9.1$ sudo yum install ruby1.9.1

RVM RUBY VERSION MANAGERhttps://rvm.io/rvm/install

Install ruby in different ways on Linux

Linux

Page 20: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 20

RUBYINSTALLERhttp://rubyinstaller.org/downloads/

PIKhttps://github.com/vertiginous/pik

Install ruby in different ways on Windows

Windows

Page 21: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 21

RUBYINSTALLERhttp://rubyinstaller.org/downloads/

PIKhttps://github.com/vertiginous/pik

Install ruby in different ways on Windows

Windows

CYGWINhttp://cygwin.com

Page 22: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

http://ki.tt/cfo

22

Page 23: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 23

Page 24: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 24

Automate All the Front-End Development Things!

Page 25: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Make your Front-End Workflow AWESOME

25

Page 26: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

1. Embrace the DRY principle

26

Guiding principles of making our workflows AWESOME

Page 27: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

1. Embrace the DRY principle2. Make changes easy

27

Guiding principles of making our workflows AWESOME

Page 28: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

1. Embrace the DRY principle2. Make changes easy3. Make finding mistakes easy

28

Guiding principles of making our workflows AWESOME

Page 29: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Implement a design or prototype

29

What magic do we do?

Page 30: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Implement a design or prototypeUpdate the designs

30

What magic do we do?

Page 31: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Implement a design or prototypeUpdate the designsMake sure it works in all browsers

31

What magic do we do?

Page 32: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Implement a design or prototypeUpdate the designsMake sure it works in all browsersMake it faster

32

What magic do we do?

Page 33: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Implement a design or prototypeUpdate the designsMake sure it works in all browsersMake it faster

33

What magic do we do?

Page 34: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 34

We’re MAGICAL

Page 35: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Implement a design or prototypeUpdate the designsMake sure it works in all browsersMake it faster

35

Page 36: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 36

How often do we have a blank slate, really?

Page 37: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Implement a design or prototypeUpdate the designsMake sure it works in all browsersMake it faster

37

Page 38: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Implement a design or prototypeUpdate the designsMake sure it works in all browsersMake it faster

38

Page 39: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

change.click.

change.click.

39

Page 40: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

change.click.

change.click.

40

change.click.

change.click.

change.click.

change.click.change.

click.change.

click.

change.click.

change.click.

change.click.

change.click.

change.click.

change.click. change.

click.change.

click.

change.click.

change.click.

change.click.

change.click.change.

click.change.

click.

Page 41: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 41

Guiding principles!

1. Embrace the DRY principle2. Make changes easy3. Make finding mistakes easy

Page 42: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 42

Page 43: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

LiveReload

43

http://livereload.com/

Page 44: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 44

Page 45: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 45

http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-

http://ki.tt/LR

Page 46: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 46

http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-

http://ki.tt/LR

Page 47: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 47

or!

Page 48: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 48

<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script>

If you don’t use browser plugins, you need this JS for LiveReload

Page 49: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 49

<cfoutput><script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script></cfoutput>

If you don’t use browser plugins, you need this JS for LiveReload

Page 50: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 50

Page 51: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

IE options

http://github.com/dvdotsenko/livereload_ie_extension

http://reloadit.codeplex.com/

51

LiveReload IE options

Page 52: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 52

Page 53: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 53

Guiding principles!

1. Embrace the DRY principle2. Make changes easy3. Make finding mistakes easy

Page 54: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

browser-sync

54

http://browsersync.io/

Page 55: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

http://ki.tt/cfo

55

Page 56: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm

56

Node Package Manager for installng node packages

Page 57: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 57

Open a new terminal or command window

Page 58: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 58

In OSX, drag and drop the folder into the terminal window for the path.

Page 59: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 59

In Windows, use right click cut and paste

Page 60: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 60

// save this into run-server.jsvar connect = require('connect');connect.createServer( connect.static(__dirname)).listen(8080);

If you don’t have a local development environment, use this run-server.js

Page 61: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 61

$ npm install connect...$ node run-server.js

# open http://localhost:8080/index.html# control-c to stop

If you don’t have a local development environment, install the connect package

Page 62: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 62

> npm install connect...> node run-server.js

# open http://127.0.0.1:8080/index.html# control-c to stop

If you don’t have a local development environment on Windows, install the connect package

Page 63: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 63

You can accept this local JS file running on node, turn it off later!

Page 64: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

http://localhost:8080/index.html

http://127.0.0.1:8080/index.html

64

You can see the temporary site running locally!

Page 65: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

browser-sync

65

http://browsersync.io/

Page 66: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 66

$ npm install -g browser-sync

Page 67: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 67

$ browser-sync$

Page 68: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 68

$ browser-sync start --server --files "css/*.css"

Page 69: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

bs-config.js

69

Page 70: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 70

$ browser-sync init[BS] Config file created (bs-config.js)[BS] To use it, in the same directory run: browser-sync$

Page 71: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 71

module.exports = { files: "css/*.css", proxy: { host: "localhost", port: 8080 }, ghostMode: { clicks: true, links: true, forms: true, scroll: true }, open: true, injectChanges: false, notify: true,};

https://github.com/shakyShane/browser-sync/wiki/options

Page 72: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

module.exports = { files: "css/*.css", proxy: { host: "localhost", port: 8080 }, ghostMode: { clicks: true, links: true, forms: true, scroll: true }, open: true, injectChanges: false, notify: true,};

72

https://github.com/shakyShane/browser-sync/wiki/options

Page 73: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 73

module.exports = { files: ["css/*.css", "**.*.html", "js/**/*.js"], proxy: { host: "localhost", port: 8080 }, ghostMode: { clicks: true, links: true, forms: true, scroll: true }, open: true, injectChanges: false, notify: true,};

https://github.com/shakyShane/browser-sync/wiki/options

Page 74: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

https://github.com/shakyShane/browser-sync/wiki/options

74

Page 75: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 75

$ browser-sync start

Page 76: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 76

$ browser-sync start[BS] Copy the following snippet into your website, just before the closing </body> tag

<script src='//192.168.5.6:3000/socket.io/socket.io.js'></script><script>var ___socket___ = io.connect('http://192.168.5.6:3000');</script><script src='//192.168.5.6:3001/client/browser-sync-client.0.7.0.js'></script>

[BS] Watching files...

Page 77: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 77

Page 78: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 78

MAGICAL

Page 79: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

click.copy.scroll.click.paste.

79

Page 80: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 80

Page 81: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Alfredhttp://alfredapp.com/

Quicksilverhttp://qsapp.com/

Launchbarhttp://www.obdev.at/products/launchbar/

81

Page 82: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Skylighthttp://www.candylabs.com/skylight

Launchyhttp://www.launchy.net/http://pylaunchy.sourceforge.net/docs/

82

Page 83: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Gnome Launch Boxhttps://live.gnome.org/

Gnome Dohttp://do.davebsd.com/

Launchyhttp://www.launchy.net/http://pylaunchy.sourceforge.net/

83

Page 84: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 84

Page 85: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 85

Page 86: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 86

Page 87: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 87

Page 88: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 88

Page 89: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 89

Alfred looking up jQuery.

Page 90: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 90

Dash has a large number of document sets

Page 91: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 91

Naïve way to open all the browsers at once

Page 92: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 92

https://github.com/zenorocha/alfred-workflows/

https://github.com/aiyodk/Alfred-Extensions/tree/master/AlfredApp_2.x

https://github.com/willfarrell/alfred-workflows

Alfred Workflows

Page 93: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Can you feel the awesome?

93

Awwwwwwwww yissssssssssssssssssss!

Page 94: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Implement a design or prototypeUpdate the designsMake sure it works in all browsersMake it faster

94

Page 95: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 95

Page 96: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 96

$ npm install -g grunt-cli

Install the grunt package

Page 97: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 97

Windows users, use PowerShell

Page 98: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 98

$ npm install -g grunt-init

$ git clone https://github.com/gruntjs/grunt-init-gruntfile.git ~/.grunt-init/gruntfile

$ grunt-init gruntfile

Download the grunt template files and generate the grunt config files ...

Page 99: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Or just download them.http://ki.tt/fgrf

99

Page 100: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 100

package.jsonGruntfile.js

The two files grunt uses

Page 101: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 101

{ "engines": { "node": ">= 0.10.0" }, "devDependencies": { "grunt": "~0.4.2", "grunt-contrib-jshint": "~0.7.2", "grunt-contrib-watch": "~0.5.3", }}

This is what a package.json file looks like

Page 102: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 102

$ npm install

With a package.json file, you can install the needed packages easily.

Page 103: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

1. Watch for file changes2. Refresh the browser on change

103

What we want grunt to do.

Page 104: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 104

module.exports = function(grunt) {

// Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { options: { banner: '/*! <%= pkg.name %> <%="yyyy-mm-dd") %> */\n' }, build: { src: 'src/<%= pkg.name %>.js', dest: 'build/<%= pkg.name %>.min.js' } } });

// Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-uglify');

// Default task(s). grunt.registerTask('default', ['uglify']);

};

A basic Gruntfile.js file

Page 105: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 105

module.exports = function(grunt) {

// Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { options: { banner: '/*! <%= pkg.name %> <%="yyyy-mm-dd") %> */\n' }, build: { src: 'src/<%= pkg.name %>.js', dest: 'build/<%= pkg.name %>.min.js' } } });

// Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-uglify');

// Default task(s). grunt.registerTask('default', ['uglify']);

};

A basic Gruntfile.js file

Page 106: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 106

module.exports = function(grunt) {

// Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { options: { banner: '/*! <%= pkg.name %> <%="yyyy-mm-dd") %> */\n' }, build: { src: 'src/<%= pkg.name %>.js', dest: 'build/<%= pkg.name %>.min.js' } } });

// Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-uglify');

// Default task(s). grunt.registerTask('default', ['uglify']);

};

A basic Gruntfile.js file

Page 107: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 107

module.exports = function(grunt) {

// Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { options: { banner: '/*! <%= pkg.name %> <%="yyyy-mm-dd") %> */\n' }, build: { src: 'src/<%= pkg.name %>.js', dest: 'build/<%= pkg.name %>.min.js' } } });

// Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-uglify');

// Default task(s). grunt.registerTask('default', ['uglify']);

};

A basic Gruntfile.js file

Page 108: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

browser-sync

108

Page 109: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

1. Find grunt plugin*2. Install with npm install --save-dev3. Add the task to our Gruntfile.js file4. Add the tasks to a command5. Run the command...7. Profit!

*write if you need to

109

How to add a task to grunt

Page 110: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

http://npmjs.org

110

Where to find node and grunt packages

Page 111: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

“grunt browser-sync”

111

What I searched for on npmjs.org

Page 112: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

THIS IS OKAY.

112

Page 113: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 113

Check for current state before downloading.

Page 114: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 114

$ npm install grunt-browser-sync --save-dev

Installing the browser-sync grunt package

Page 115: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 115

$ lsGemfile!! README.txt fonts node_modules template.phpGemfile.lock bs-config.js images package.json templatesGruntfile.js config.rb js screenshot.png theme.infoGuardfile! css logo.png scss widgets

Page 116: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 116

"grunt-browser-sync": "~0.7.0"

Page 117: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 117

browserSync: { bsFiles: { src: [ 'css/*.css', 'img/*', 'js/*.js', '*.html' ] }, options: { watchTask: true, proxy: { host: "localhost", port: 8082 }, server: false, } },

Page 118: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 118

browserSync: { bsFiles: { src: [ 'css/*.css', 'img/*', 'js/*.js', '*.html' ] }, options: { watchTask: true, proxy: { host: "localhost", port: 8082 }, server: false, } },

Page 119: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 119

browserSync: { bsFiles: { src: [ 'css/*.css', 'img/*', 'js/*.js', '*.html' ] }, options: { watchTask: true, proxy: { host: "localhost", port: 8082 }, server: false, } },

Page 120: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 120

watch: { gruntfile: { files: '<%= jshint.gruntfile.src %>', tasks: ['jshint:gruntfile'] }, scss: {        files: ['scss/*.scss'],        tasks: ['sass:dev']      },      js: { // watch for js changes except for script.min.js        files: ['js/*.js', '!js/script.min.js'],         tasks: ['uglify:dev']      } }

Page 121: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 121

grunt.loadNpmTasks('grunt-browser-sync');

...

grunt.registerTask('default', ['browserSync', ‘watch’]);

Page 122: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 122

grunt.registerTask('gogogo', ['browserSync', 'watch']);

Page 123: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 123

$ grunt gogogo

Running the newly defined “gogogo” command

Page 124: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 124

Page 125: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 125

modern.ie

Page 126: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 126

Page 127: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Implement a design or prototypeUpdate the designsMake sure it works in all browsersMake it faster

127

Page 128: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Javascript?

128

Page 129: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 129

1. Find grunt plugin*2. Install with npm install --save-dev3. Add the task to our Gruntfile.js file4. Add the tasks to a command5. Run the command...7. Profit!

*write if you need to

Page 130: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

1. Embrace the DRY principle2. Make changes easy3. Make finding mistakes easy

130

Guiding principles of making our workflows AWESOME

Page 131: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 131

$ npm install matchdep --save-dev

Installing the browser-sync grunt package

Page 132: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 132

...

// load all the grunt modules instead of one each linerequire("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks);

grunt.registerTask('checkjs', ['jshint']);grunt.registerTask('watchjs', ['jshint', 'watch']);grunt.registerTask('gruntjs', ['jshint:gruntfile', 'watch']);

Page 133: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

1. Embrace the DRY principle2. Make changes easy3. Make finding mistakes easy

133

Guiding principles of making our workflows AWESOME

Page 134: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

jshint

134

Page 135: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install grunt-contrib-jshint --save-dev

135

Use jshint when editing your Gruntfile.js

https://github.com/gruntjs/grunt-contrib-jshint

Page 136: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 136

jshint: { options: { ... }, gruntfile: { src: ‘Gruntfile.js’ }}

...

grunt.loadNpmTasks('grunt-contrib-jshint');

grunt.registerTask('checkjs', ['jshint']);grunt.registerTask('watchjs', ['jshint', 'watch']);grunt.registerTask('gruntjs', ['jshint:gruntfile', 'watch']);

Page 137: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 137

Page 138: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install grunt-contrib-qunit --save-dev

138

Javascript unit tests

https://github.com/gruntjs/grunt-contrib-qunit

Page 139: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install grunt-contrib-jasmine --save-dev

139

Javascript unit tests

https://github.com/gruntjs/grunt-contrib-jasmine

Page 140: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install grunt-simple-mocha --save-dev

140

Javascript unit tests

https://github.com/yaymukund/grunt-simple-mocha

Page 141: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Implement a design or prototypeUpdate the designsMake sure it works in all browsersMake it faster

141

Page 142: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Implement a design or prototypeUpdate the designsMake sure it works in all browsersMake it faster

142

Page 143: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

1. Reduce file sizes2. Reduce the number of files3. Reduce content rendering time

143

Page 144: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 144

1. Reduce file sizes2. Reduce the number of files3. Reduce content rendering time

Page 145: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Images

145

Page 146: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install grunt-contrib-imagemin --save-dev

146

Make pages load faster by reducing image sizes

Page 147: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 147

imagemin: { prod: { files: [{ expand: true, cwd: 'imgs-src/', src: ['**/*.{png,jpg,gif}'], dest: 'imgs/' }] }}

Page 148: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install grunt-svgmin --save-dev

148

Reduce SVG sizes, too

Page 149: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 149

grunt.initConfig({ svgmin: { // Task options: { // Configuration that will be passed directly to SVGO plugins: [ { removeViewBox: false }, { removeUselessStrokeAndFill: false } ] }, dist: { // Target files: [{ // Dictionary of files expand: true, // Enable dynamic expansion. cwd: 'img/src', // Src matches are relative to this path. src: ['**/*.svg'], // Actual pattern(s) to match. dest: 'img/', // Destination path prefix. ext: '.min.svg' // Dest filepaths will have this extension. // ie: optimise img/src/branding/logo.svg and store it in img/branding/logo.min.svg }] }});

grunt.loadNpmTasks('grunt-svgmin');grunt.registerTask('default', ['svgmin']);

Sample grunt-svgmin configuration

Page 150: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install grunt-responsive-images --save-dev

150

Responsive images by resizing

https://github.com/andismith/grunt-responsive-images

Page 151: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 151

grunt.initConfig({ responsive_images: { myTask: { options: { sizes: [{ width: 320, height: 240 },{ name: 'large', width: 640 },{ name: "large", width: 1024, suffix: "_x2", quality: 60 }] }, files: [{ expand: true, src: ['assets/**.{jpg,gif,png}'], cwd: 'test/', dest: 'resize/{%= width %}/' }] } },});

Sample grunt-responsive-images configuration

Page 152: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install grunt-grunticon --save-dev

152

SVG with PNG fallbacks

https://github.com/filamentgroup/grunticon

Page 153: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Non-images

153

Page 154: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install grunt-contrib-cssmin --save-dev

154

Minimize CSS files

Page 155: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install grunt-csscss --save-dev

155

Minimize CSS files

Page 156: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install grunt-contrib-uglify --save-dev

156

Minimize javascript files

Page 157: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 157

1. Reduce file sizes2. Reduce the number of files3. Reduce content rendering time

Page 158: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Sprites!

158

Making things easier with sprites!

Page 159: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

WHOO!159

Page 160: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Creating them is EASY!

160

Page 161: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install grunt-montage --save-dev

161

Sprite your images

Page 162: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 162

1. Reduce file sizes2. Reduce the number of files3. Reduce content rendering time

Page 163: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 163

1. Reduce file sizes2. Reduce the number of files3. Reduce content rendering time

Page 164: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

1. Embrace the DRY principle2. Make changes easy3. Make finding mistakes easy

164

Guiding principles of making our workflows AWESOME

Page 165: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Change the font BLUE

165

Easiest change ever!

Page 166: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

#6c869d ⇒ #212939

166

Easiest change ever!

Page 167: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 167

Well, phooey. The ticket was reopened.

Page 168: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 168

Soon, EVERYTHING is important!

Page 169: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 169

Page 170: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 170

Page 171: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 171

Guiding principles!

1. Embrace the DRY principle2. Make changes easy3. Make finding mistakes easy

Page 172: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 172

Guiding principles!

1. Embrace the DRY principle2. Make changes easy3. Make finding mistakes easy

Page 173: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Use a CSS preprocessor.

173

Saw that coming, didn’t you?

Page 174: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Sass / LESS / Stylus

174

Saw that coming, didn’t you?

Page 175: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Quick Check!

Did you go to Andy Matthews Sass session?

175

Page 176: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Are we passing GO?Are we collecting $200?

176

Page 177: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Sass ⟳ CSS

177

Page 178: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Getting started with Sass

178

Page 179: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Install it.

179

Page 180: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 180

$ gem update --system$ gem install sass

$ sudo gem update --system$ sudo gem install sass

Yay! Sass installed!

Page 181: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

COMPASS

181

Install Compass, too

http://compass-style.org/install/

Page 182: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 182

$ gem update --system$ gem install compass

$ sudo gem update --system$ sudo gem install compass

Setting up tools. In this case, Compass.

Page 183: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

CSS ⇒ Sass

183

Page 184: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Let us count the (3) ways.

184

How we get started with Sass in an existing project.

Page 185: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Move and rename files.

185

How we get started with Sass in an existing project.

Page 186: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 186

$ mkdir scss$ mv css/styles.css scss/styles.scss

Setting up tools. In this case, Compass.

Page 187: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Use sass-convert

187

How we get started with Sass in an existing project.

Page 188: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 188

$ sass-convert --helpUsage: sass-convert [options] [INPUT] [OUTPUT] $$ cd theme-dir$ sass-convert --recursive --from=css --to=scss css scss

Setting up tools. In this case, Compass.

Page 189: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Use http://css2sass.heroku.com

189

How we get started with Sass in an existing project.

Page 190: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 190

Page 191: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

$variables

191

Quick! Sass in 5 slides!

Page 192: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 192

$variable: value;

Before variables...

Page 193: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 193

dev[405]% grep background-color * style.css: background-color: #edf5fa;style.css: background-color: #ddecf5;style.css: background-color: #e6f1f7;style.css: background-color: #d4e7f3;style.css: background-color: #edf5fa;style.css: background-color: #fcfce8;style.css: background-color: #fcf9e5;style.css: background-color: #fbf5cf;style.css: background-color: #fefefe;style.css: background-color: #f5f5f5;style.css: background-color: #fdf5e6;style.css: background-color: #fdf2de;style.css: background-color: #fbe4e4;style.css: background-color: #fbdbdb;style.css: background-color: #ffcccc;style.css: background-color: #ffffdd;style.css: background-color: #ddffdd;

Before variables...

Page 194: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 194

$color-main: rgb(255,251,114);$color-second: rgb(70,87,204);$color-hilite: rgb(189,177,255);

...

.button { background-color: $color-main; ...}

See? Easy!

Page 195: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 195

$font-times: Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif;

$font-garamond: "Palatino Linotype", Palatino, Palladio, "URW Palladio L", "Book Antiqua", Baskerville, "Bookman Old Style", "Bitstream Charter", "Nimbus Roman No9 L", Garamond, "Apple Garamond", "ITC Garamond Narrow", "New Century Schoolbook", "Century Schoolbook", "Century Schoolbook L", Georgia, serif;

Uses of variables: fonts

http://css-tricks.com/snippets/css/font-stacks/

Page 196: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 196

$color-main: #ff0000;$border-main: 2px solid $color-main;.multivalue-example { border-top: $border-main;}

# compiles to.multivalue-example { border-top: 2px solid red;}

See? Easy!

Page 197: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Variable name best practice.

197

Page 198: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 198

$ourBlue : #1f4363;$ourBlueLight : #355673;$ourBlueLighter : #6c869d;$ourBlueDark : #0e2c47;$ourBlueDarker : #212939;$ourBlueHover : #7e99b3;

...

$color_border $ourBlue;$color_link: $ourBlue;$table_header: $ourBlueLighter;

Use descriptive AND functional variable names

http://sachagreif.com/sass-color-variables

Page 199: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Nested syntax

199

Quick! Sass in 5 slides!

Page 200: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 200

.navigation {

a {

display: block; padding: .5em; color: $color-link; border: none; } b {

font-size: .9em; } span { display: block; font-size: .8em; }

}

.navigation a {

display: block;

padding: .5em;

color: #444040;

border: none;

}

.navigation b {

font-size: .9em;

}

.navigation span {

display: block;

font-size: .8em;

}

Sass syntax, talking nesting

Page 201: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 201

.navigation {

a {

display: block; padding: .5em; &:hover {

color: $color-link; border: none; } } &>.first { padding-left: 0; }}

Sass syntax, talking nesting

Page 202: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

@extend

202

Quick! Sass in 5 slides!

Page 203: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 203

Sass syntax, talking @extend

.box { padding: 2em; color: $color-text; background-color: $color-bg;}

.box-warning { @extend .box; border: 2px dotted $color-yikes;}

.box-success { @extend .box; border: 2px dotted $color-success;}

.box-info { @extend .box; border: 2px dotted $color-info;}

Page 204: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 204

Sass syntax, talking @extend

.box, .box-warning, .box-success, .box-info { padding: 2em; color: #333333; background-color: white;}

.box-warning { border: 2px dotted #cc0000;}

.box-success{ border: 2px dotted #33cc00;}

.box-info { border: 2px dotted #996633;}

Page 205: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

<div class=”box box-info”>...</div>

205

Sass syntax, talking @extend

Page 206: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 206

Sass syntax, talking @extend

<div class=”box-info”>...</div>

Page 207: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

@mixin@include

207

Quick! Sass in 5 slides!

Page 208: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 208

Sass syntax, @mixin

@mixin module($parent-color) { color: darken($parent-color, 50%); }

.main_module { @include module(#ccc); min-height: 3em;}

.sidebar_module { @include module(#444); min-height: 2em;}

Page 209: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

When you can, use a Compass mixin.

209

Page 210: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 210

Sass syntax, @mixin

@import "compass/css3/box-sizing";* { @include box-sizing(border-box); }

http://compass-style.org/reference/compass/css3/box_sizing/

Page 211: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

@mixin vs @extend

211

Sass Overview

Page 212: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

You’re awesome.

212

Page 213: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

_partials.scss

213

Quick! Sass in 5 slides!

Page 214: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 214

Sass syntax, @mixin

@import "vars";@import "mixins";@import "layouts/*";

Page 215: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 215

Quick! Sass in 5 slides!

@if/@else

@for

@each

@functions (return a single value)

Page 216: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Media Queriesmade EASY

216

Page 217: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 217

@mixin bp($point) { $bp-mobile: "(max-width: 600px)"; $bp-notso: "(max-width: 1250px)"; $bp-fullon: "(max-width: 1600px)";

@if $point == mq-fullon { @media #{$bp-fullon} { @content; } } @else if $point == mq-notso { @media #{$bp-notso} { @content; } } @else if $point == mq-mobile { @media #{$bp-mobile} { @content; } }}

Page 218: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 218

h1 { font-size: 20px; font-family: $font-main; @include bp(mq-notso) { font-size: 30px; } @include bp(mq-fullon) { font-size: 60px; }}

Page 219: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 219

h1 { font-size: 20px;}@media (max-width: 1250px) { h1 { font-size: 30px; }}@media (max-width: 1600px) { h1 { font-size: 60px; }}

Page 220: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 220

Guiding principles!

1. Embrace the DRY principle2. Make changes easy3. Make finding mistakes easy

Page 221: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

More Information.

221

Sass for DesignersPragmatic Guide To Sass

Sass and Compass in Action

Page 222: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 222

sass --watch --line-numbers --style expanded scss:css

Page 223: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Compass has its config.rb

223

Page 224: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 224

Page 225: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 225

compass config config.rb --sass-dir=scss \--css-dir=css --javascripts-dir=js \--output-style=expanded

How to create a compass conifig.rb file

Page 226: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 226

$ compass watch

Page 227: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

GUI

227

Page 228: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 228

https://incident57.com/codekit/

Page 229: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 229

http://compass.kkbox.com/

Page 230: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 230

http://koala-app.com/

Page 231: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 231

https://github.com/vladikoff/grunt-devtools

Page 232: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

1. Watch for file changes2. Compile our Sass to CSS3. Refresh the browser on change

232

What we want grunt to do.

Page 233: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install grunt-contrib-compass --save-dev

233

Installing the compass compiling node package

Page 234: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 234

grunt.initConfig({ compass: { dist: { options: { config: 'config.rb' } } }});

Page 235: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 235

grunt.initConfig({ watch: { scss: { files: ['**/*.scss'], tasks: ['compass'] } }, compass: { dev: { options: { sassDir: 'scss', cssDir: 'css', outputStyle: 'expanded' } }, }});

Page 236: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 236

grunt.initConfig({ watch: { scss: { files: ['**/*.scss'], tasks: ['compass'] } }, compass: { dev: { options: { sassDir: 'scss', cssDir: 'css', outputStyle: 'expanded' } }, }});

Page 237: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 237

grunt.initConfig({ watch: { scss: { files: ['**/*.scss'], tasks: ['compass'] } }, compass: { dev: { options: { sassDir: 'scss', cssDir: 'css', outputStyle: 'expanded' } }, }});

Page 238: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 238

compass: { dev: { options: { sassDir: 'scss', cssDir: 'css', outputStyle: 'expanded' } }, prod: { options: { sassDir: 'scss', cssDir: 'css', outputStyle: 'compressed' } }, }

Page 239: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 239

grunt.loadNpmTasks('grunt-contrib-compass');

...

grunt.registerTask('default', ['compass:dev', ‘watch’]);

Page 240: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 240

Page 241: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 241

1. Reduce file sizes2. Reduce the number of files3. Reduce content rendering time

Page 242: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 242

@import "compass/utilities/sprites";

...

$sprites-spacing: 20px;@import “../img/sprites/*png”;

Creating sprite images with Compass

Page 243: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 243

@import "compass/utilities/sprites";

...

$orange-spacing: 20px;@import “../img/orange/*png”;

Sprite names are dependent on your directory name

Page 244: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 244

@import "compass/utilities/sprites";

...

$awesome-spacing: 20px;@import “../img/awesome/*png”;

Sprite names are dependent on your directory name

Page 245: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 245

Using generated sprites

.footer-follow-us{ .twitter { @include awesome-sprite(follow-us-twitter); } .facebook { @include awesome-sprite(follow-us-fb); } .google { @include awesome-sprite(follow-us-google); } .pinterest { @include awesome-sprite(follow-us-pins); }}

.awesome-sprite,

.footer-follow-us .twitter,

.footer-follow-us .facebook,

.footer-follow-us .google,

.footer-follow-us .pinterest { background: url('../images/awesome-s34fe0604ab.png') no-repeat; }

.footer-follow-us .twitter { background-position: 0 -96px; }

.footer-follow-us .facebook { background-position: 0 0; }

.footer-follow-us .google { background-position: 0 -32px; }

.footer-follow-us .pinterest { background-position: 0 -64px; }

Page 246: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Uh...

246

How do we check these?

Page 247: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

1. Embrace the DRY principle2. Make changes easy3. Make finding mistakes easy

247

Guiding principles of making our workflows AWESOME

Page 248: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 248

How do we check these?

Page 249: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Source Maps

249

How do we check these?

Page 250: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 250

c

http://code.tutsplus.com/tutorials/developing-with-sass-and-chrome-devtools--net-32805

Page 251: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 251

Generating

Page 252: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 252

sass --compass --sourcemap --watch scss:css

Page 253: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 253

compass: { dev: { options: { sassDir: 'scss', cssDir: 'css', outputStyle: 'expanded', sourcemap: true } }, prod: { options: { sassDir: 'scss', cssDir: 'css', outputStyle: 'compressed' } }, }

Page 254: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 254

Don’t deploy to production!

Page 255: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 255

Using

Page 256: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 256

This works in > Firefox 29, right click to show CSS

Page 257: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 257

1. Reduce file sizes2. Reduce the number of files3. Reduce content rendering time

Page 258: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Don’t nest more than 3 deep

258

http://css-tricks.com/sass-style-guide/

Page 259: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Avoid using tag selectorsUse class selectors if you can.

259

https://developers.google.com/speed/docs/best-practices/rendering

Page 260: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

1. Embrace the DRY principle2. Make changes easy3. Make finding mistakes easy

260

Guiding principles of making our workflows AWESOME

Page 261: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Regression testing

261

Page 262: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

PhantomCSS

262

Page 263: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install grunt-phantomcss --save-dev

install details at

https://www.npmjs.org/package/grunt-phantomcss

263

Page 264: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 264

phantomcss: { desktop: { options: { screenshots: 'test/visual/desktop/', results: 'results/visual/desktop', viewportSize: [1024, 768] }, src: [ 'test/visual/**.js' ] }, mobile: { options: { screenshots: 'test/visual/mobile/', results: 'results/visual/mobile', viewportSize: [320, 480] }, src: [ 'test/visual/**.js' ] } }

phantomcss grunt task

Page 265: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 265

casper.start('http://cfobj.localhost:8082/').then(function() { phantomcss.screenshot('#region-branding', 'region-branding');}).then( function now_check_the_screenshots(){ phantomCSS.compareAll();});

phantomcss website flow

Page 266: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Seeing failures

266

http://tldr.huddle.com/blog/css-testing/

Page 267: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Phew!

267

Page 268: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Triggering tests

268

Page 269: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

git pre-commit hook

269

svn works, too!

Page 270: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Vagrant

270

Page 271: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Say Goodbye to “It works on my machine” with Chef

and Vagrant.Curt Gratz, 3pm this room

271

Page 272: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 272

What magic do we do?

Implement a design or prototypeUpdate the designsMake sure it works in all browsersMake it faster

Page 273: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

From the beginning!

273

Page 274: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Faster HTML

274

Page 275: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

http://docs.emmet.io/

275

Page 276: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

div#banner>div.logo+ul#navigation>li*4>a

276

Page 277: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

<div id="banner"> <div class="logo"></div> <ul id="navigation"> <li><a href=""></a></li> <li><a href=""></a></li> <li><a href=""></a></li> <li><a href=""></a></li> </ul></div>

277

Page 278: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

http://www.thoughtdelimited.org/thoughts/post.cfm/zen-coding-a-faster-way-to-write-html-and-tag-based-cfml-in-cfbuilder-cfeclipse

278

http://ki.tt/cfoem

Page 279: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 279

http://ki.tt/cfoem

http://www.thoughtdelimited.org/thoughts/post.cfm/zen-coding-a-faster-way-to-write-html-and-tag-based-cfml-in-cfbuilder-cfeclipse

Page 280: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 280

http://yeoman.io

Yeoman

Page 281: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

yo

281

Page 282: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

npm install -g yo

282

Installing yeoman globally

Page 283: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 283

# use a generator $ yo webapp

# start the server$ grunt server

# run tests$ grunt test

# run default$ grunt

Page 284: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 284

# download new generator$ npm install generator-gruntplugin

# run the generator$ yo gruntplugin

Page 285: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 285

# download new generator$ npm install generator-gruntfile

# run the generator$ yo gruntfile

Page 286: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 286

Lots of generators available

http://yeoman.io/official-generators.html

Page 287: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo 287

# download new generator$ npm install generator-generator

# create the directory$ mkdir generator-bigred && cd $_

# run the generator$ yo generator

Page 288: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

http://yeoman.io/generators.html#writing-your-first-generator

288

http://ki.tt/yog

Page 289: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Wow, that was fast.

289

Page 290: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

I skipped over

BundlerManaging what ruby gems you have installed

http://bundler.io/

Creating your own Grunt tasks http://gruntjs.com/creating-tasks

Bowerhttp://bower.io/

290

Page 291: Automate all the things

Kitt Hodsden • @kitt • http://ki.tt/cfo

Questions?

291

Page 292: Automate all the things

Thanks!

292

You’re awesome!