Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Grunting Maintainability

Grunting Maintainability

Overview of using the Grunt JS task runner and working with some useful Grunt Plugins.

Philip Zastrow

April 02, 2014
Tweet

More Decks by Philip Zastrow

Other Decks in Programming

Transcript

  1. Grunt for People Who Think Things Like Grunt are Weird

    and Hard —Chris Coyier, 24 Ways 24ways.org/2013/grunt-is-not-weird-and-hard
  2. { "name": “sample-site", "version": "0.1.0", "devDependencies": { "grunt": "~0.4.2", "assemble":

    "~0.4.13", "grunt-contrib-clean": "~0.4.0", "grunt-contrib-coffee": "~0.6.0", "grunt-contrib-compass": "~0.1.3", "grunt-contrib-copy": "~0.4.1" } }
  3. module.exports = function(grunt) { // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'),

    uglify: { options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today("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']); }; Example code from gruntjs.com
  4. module.exports = (grunt) -> # Project configuration. grunt.initConfig pkg: require("package.json")

    uglify: options: banner: '/*! <%= pkg.name %> <%= grunt.template.today("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'] Example code from gruntjs.com
  5. Grunt Project coffee data dist features grunt public Gemfile Gruntfile

    config.rb package.json .gitignore bower.json .bowerrc sass specs templates
  6. Grunt Project coffee data dist features grunt public Gemfile Gruntfile

    config.rb package.json .gitignore bower.json .bowerrc sass specs templates
  7. module.exports = (grunt) -> grunt.config "assemble", options: partials: "templates/partials/*" data:

    "data/*.yml" layoutdir: "templates/layouts/" layout: ['default.hbs'] files: expand: true cwd: 'templates/pages' src: ['*.hbs'] dest: './dist/' ! grunt.loadNpmTasks 'assemble'
  8. module.exports = (grunt) -> grunt.config "assemble", options: partials: "templates/partials/*" data:

    "data/*.yml" layoutdir: "templates/layouts/" layout: ['default.hbs'] files: expand: true cwd: 'templates/pages' src: ['*.hbs'] dest: './dist/' ! grunt.loadNpmTasks 'assemble'
  9. module.exports = (grunt) -> grunt.config "assemble", options: partials: "templates/partials/*" data:

    "data/*.yml" layoutdir: "templates/layouts/" layout: ['default.hbs'] files: expand: true cwd: 'templates/pages' src: ['*.hbs'] dest: './dist/' ! grunt.loadNpmTasks 'assemble'
  10. <!doctype html> <html> <head> <title> Sample Site </title> <head> <body>

    {{> _site--header }} {{> body }} {{> _site--footer }} </body> </html>
  11. <!doctype html> <html> <head> <title> Sample Site </title> <head> <body>

    {{> _site--header }} {{> body }} {{! Loads in Page Content }} {{> _site--footer }} </body> </html>
  12. <!doctype html> <html> <head> <title> Sample Site </title> <head> <body>

    {{> _site--header }} {{! Loads Site Header Partial }} {{> body }} {{> _site--footer }} {{! Loads Site Footer Partial }} </body> </html>
  13. module.exports = (grunt) -> grunt.config "assemble", options: partials: "templates/partials/*" data:

    "data/*.yml" layoutdir: "templates/layouts/" layout: ['default.hbs'] files: expand: true cwd: 'templates/pages' src: ['*.hbs'] dest: './dist/' ! grunt.loadNpmTasks 'assemble'
  14. module.exports = (grunt) -> grunt.config "assemble", options: partials: "templates/partials/*" data:

    "data/*.yml" layoutdir: "templates/layouts/" layout: ['default.hbs'] files: expand: true cwd: 'templates/pages' src: ['*.hbs'] dest: './dist/' ! grunt.loadNpmTasks 'assemble'
  15. <div class="main_content"> <article class="main_content--article"> <header class="main_content--header"> <h1 class="main_content--title">Our Homepage</h1> <header>

    <div class="article_content"> <p>This is the main content for our page.</p> </div> </article> </div> ! {{> _site--aside }}
  16. module.exports = (grunt) -> grunt.config "assemble", options: partials: "templates/partials/*" data:

    "data/*.yml" layoutdir: "templates/layouts/" layout: ['default.hbs'] files: expand: true cwd: 'templates/pages' src: ['*.hbs'] dest: './dist/' ! grunt.loadNpmTasks 'assemble'
  17. module.exports = (grunt) -> grunt.config "assemble", options: partials: "templates/partials/*" data:

    "data/*.yml" layoutdir: "templates/layouts/" layout: ['default.hbs'] files: expand: true cwd: 'templates/pages' src: ['*.hbs'] dest: './dist/' ! grunt.loadNpmTasks 'assemble'
  18. nav-list: - nav_item: Home target: "/" - nav_item: About target:

    "about.html" - nav_item: Blog target: "blog.html" - nav_item: Contact target: "contact.html"
  19. <nav class="site_nav"> <ul class="site_nav--list"> <li class="site_nav--list"> <a href="/" class="site_nav--list"> Home

    </a> </li> <li class="site_nav--list"> <a href="about.html" class="site_nav--list"> About </a> </li> <li class="site_nav--list"> <a href="blog.html" class="site_nav--list"> Blog </a> </li> <li class="site_nav--list"> <a href="contact.html" class="site_nav--list"> {{nav_item}} </a>
  20. <!doctype html> <html> <head> <title> Sample Site </title> <head> <body>

    {{> _site-header }} {{> body }} {{> _site-footer }} </body> </html>
  21. <!doctype html> <html> <head> <title> Sample Site </title> <head> <body>

    {{> _site-header }} {{> body }} {{> _site-footer }} </body> </html>
  22. <!doctype html> <html> <head> <title> Sample Site{{#if page_title}} | {{page_title}}{{/if}}

    </title> <head> <body> {{> _site-header }} {{> body }} {{> _site-footer }} </body> </html>
  23. --- page_title: About Us --- ! <div class="main_content"> <article class="main_content--article">

    <header class="main_content--header"> <h1 class="main_content—title">{{page_title}}</h1> <header> <div class="article_content"> {{ about.page-content }} </div> </article> </div> ! {{> _site--aside }}
  24. <!doctype html> <html> <head> <title> Sample Site{{#if page_title}} | {{page_title}}{{/if}}

    </title> <head> <body> {{> _site-header }} {{> body }} {{> _site-footer }} </body> </html>
  25. <!doctype html> <html> <head> <title> Sample Site | About Us

    </title> <head> <body> <header class="site_header"> <h1 class="site_header--title">Sample Site</h1> <nav class="site_nav"> <ul class="site_nav--list"> <li class="site_nav--list"> <a href="/" class="site_nav—list"> Home </a> </li> <li class="site_nav--list"> <a href="about.html" class="site_nav--list"> About </a> </li> <li class="site_nav--list">
  26. module.exports = (grunt) -> grunt.config "compass", dev: options: environment: "dev"

    dist: options: environment: "production" grunt.loadNpmTasks "grunt-contrib-compass"
  27. module.exports = (grunt) -> grunt.config "clean", all: src: "dist/*" dot:

    true #clean hidden files as well ! grunt.loadNpmTasks 'grunt-contrib-clean'
  28. module.exports = (grunt) -> grunt.config "copy", main: files: [ expand:

    true cwd: "public/" src: ["**"] dest: "dist/" ] ! grunt.loadNpmTasks 'grunt-contrib-copy'
  29. module.exports = (grunt) -> grunt.config "grunticon", icons: files: [ expand:

    true, cwd: "grunticon/src", src: ["*.svg"], dest: "dist/grunticon" ] ! grunt.loadNpmTasks "grunt-grunticon"
  30. .icon-sample-logo { background-image: url(‘data:image/svg +xml;charset=US-ASCII,%3C%3Fxml %20version%3D %221.0%22%20encoding%3D %22UTF-8%22%20standalone%3D%22no%22%3F%3E%3Csvg %20width%3D%22302px%22%20height%3D%2266px %22%20viewBox%3D%220%200%20302%2066%22%20version%3D

    %221.1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org %2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F %2Fwww.w3.org%2F1999%2Fxlink%22%3E %20%20%20%20%3Ctitle%3EButton%3C%2Ftitle%3E %20%20%20%20%3Cdefs%3E%20%20%20%20%20%20%3Cstyle%3E %20%20%20%20%20%20%20%20.button--path%20%7B %20%20%20%20%20%20%20%20%20%20fill%3A%20%23D4D4D4%3B %20%20%20%20%20%20%20%20%7D%20%20%20%20%20%20%3C %2Fstyle%3E%20%20%20%20%3C%2Fdefs%3E %20%20%20%20%3Cpath%20class%3D%22button--path%22%20d %3D
 %22M244.681203%2C0%20L56.2445924%2C0%20C27.7845831%2C 0%200%2C33.8953123%200%2C33.8953123%20C0%2C33.8953123 %2026.3926138%2C65.9999996%2055.4422152%2C65.9999996% 20C137.527029%2C65.9999996%20218.318013%2C66.0000005%
  31. .icon-sample-logo { background-image: url(‘data:image/ png;base64,iVBORw0KGgoAAAANSUhEUgAAAS4AAABCCAYAAADpAT vWAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEwAACxMBAJqcGAA ACGpJREFUeJzt3XuMXGUZBvDn/Wa6uy5toS0bE2OUEly3O +eMVrZaFdRN1CbEpqYNBaHBGAtyCaigTRo0AaoxBIsXEoLIRZRU2F CQgEgpcYlJCZcRh3POzGxWCAIBQlgSUzRMpzPv6x/ uku2ys7tzPbPd5/ff5sx5v2f/

    eXL22znnCBa5IAhOBTDknDvdzNYCWG1mawCsBrDaObc83oRE7aWqJ efcuwAOq+rrzrnXALxgZhGAoFAoRNu3b6/ EHLMhEneAWgVBkHbOfR3A51X1dOfcmrgzES0mqvqOc+4pAKNm9ojv +8/ HnalWi6K4oij6NIBtqrrVOXda3HmIjjOvArgfwD7P856JO8xCdGxx BUGwSkQuBHCJiJwScxyiJUFV/ ykiv122bNmdAwMDE3HnqabjiiuXy6VU9QoR2QGgN +48REvR5D7ZPaq6N51OB3HnmaljiiuXy33GzK4D8NW4sxDRMQ6Y2R 7f9w/ FHWRK7MU1eYX1UxHZEncWIqrOzB53zv0olUo9HXeW2IqrUCicUqlU rlPV851zLq4cRFQbVb3PObfb87wX4srQ9uKKoqjLzHaZ2dXOuZ52r 09EjZvcA/ slgD2e5/2n3eu3tbjCMBwWkZsBDLRzXSJqDVV9HcD30+n0SDvXbUt