Skip to content

Instantly share code, notes, and snippets.

@craigmdennis
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigmdennis/0fe3aecb2b974b343425 to your computer and use it in GitHub Desktop.
Save craigmdennis/0fe3aecb2b974b343425 to your computer and use it in GitHub Desktop.
Use Grunt to write Kirby templates in Jade and compile to .php
// Generated on 2014-03-14 using generator-webapp 0.4.8
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Turn on the stack trace by default
grunt.option('stack', true);
// Define the configuration for all the tasks
grunt.initConfig({
// Project settings
config: {
// Configurable paths
app: {
root: 'app',
scripts: '<%= config.app.root %>/scripts',
styles: '<%= config.app.root %>/styles',
templates: '<%= config.app.root %>/templates',
snippets: '<%= config.app.root %>/snippets',
img: '<%= config.app.root %>/images'
},
dist: {
site: 'theme/v9/site',
assets: 'theme/v9/assets',
scripts: '<%= config.dist.assets %>/scripts',
styles: '<%= config.dist.assets %>/styles',
templates: '<%= config.dist.site %>/templates',
snippets: '<%= config.dist.site %>/snippets',
img: '<%= config.dist.assets %>/images'
}
},
// Watches files for changes and runs tasks based on the changed files
watch: {
jadeTemplates: {
files: ['<%= config.app.templates %>/*.jade', '<%= config.app.snippets %>/*.jade'],
tasks: ['jadephp:dist']
},
coffee: {
files: ['<%= config.app.scripts %>/{,*/}*.{coffee,litcoffee,coffee.md}'],
tasks: ['coffee', 'jshint:dist']
},
js: {
files: ['<%= config.app.scripts %>/{,*/}*.js'],
tasks: ['newer:copy:all', 'newer:copy:dist', 'jshint:dist']
},
gruntfile: {
files: ['Gruntfile.js'],
tasks: ['jshint:gruntfile']
},
assets: {
files: ['<%= config.app.img %>/{,*/}*.{webp,svg}', '<%= config.app.assets %>/fonts/{,*/}*.*'],
tasks: ['newer:copy:dist']
},
compass: {
files: ['<%= config.app.styles %>/{,*/}*.{scss,sass}'],
tasks: ['compass:server', 'autoprefixer']
},
styles: {
files: ['<%= config.app.styles %>/{,*/}*.css'],
tasks: ['newer:copy:all', 'autoprefixer']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= config.dist.templates %>/{,*/}*.php',
'<%= config.dist.snippets %>/{,*/}*.php',
'.tmp/styles/{,*/}*.css',
'.tmp/scripts/{,*/}*.js',
'<%= config.app.img %>/{,*/}*'
]
}
},
// The actual grunt server settings
connect: {
options: {
port: 9000,
livereload: 35729,
// Change this to '0.0.0.0' to access the server from outside
hostname: '0.0.0.0'
},
livereload: {
options: {
open: 'http://craigmdennis.local',
base: [
'.tmp',
'<%= config.app.root %>'
]
}
},
dist: {
options: {
open: 'http://craigmdennis.local',
base: '<%= config.dist.site %>',
livereload: false
}
}
},
// Empties folders to start fresh
clean: {
all: {
files: [{
dot: true,
src: [
'.tmp',
'<%= config.dist.templates %>/*',
'<%= config.dist.snippets %>/*',
'<%= config.dist.assets %>/*'
]
}]
}
},
// Compile Jade to HTML
jadephp: {
options: {
pretty: true
},
dist: {
files: [
{
expand: true,
cwd: '<%= config.app.templates %>/',
dest: '<%= config.dist.templates %>',
src: '*.jade',
ext: '.php'
},{
expand: true,
cwd: '<%= config.app.snippets %>/',
dest: '<%= config.dist.snippets %>',
src: '*.jade',
ext: '.php'
}
]
},
},
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
gruntfile: {
src: 'Gruntfile.js'
},
dist: {
src: '.tmp/scripts/{,*/}.js'
}
},
// Compiles CoffeeScript to JavaScript
coffee: {
options: {
bare: true
},
dist: {
files: [{
expand: true,
cwd: '<%= config.app.scripts %>/',
src: '{,*/}*.{coffee,litcoffee,coffee.md}',
dest: '.tmp/scripts',
ext: '.js'
}]
},
},
// Compiles Sass to CSS and generates necessary files if requested
compass: {
options: {
config: 'config.rb'
},
dist: {
options: {
debugInfo: false
}
},
server: {
options: {
debugInfo: true
}
}
},
// Add vendor prefixed styles
autoprefixer: {
options: {
browsers: ['last 1 version']
},
dist: {
files: [{
expand: true,
cwd: '.tmp/styles/',
src: '{,*/}*.css',
dest: '.tmp/styles/'
}]
}
},
// Automatically inject Bower components into the HTML file
bowerInstall: {
app: {
src: ['<%= config.app.snippets %>/{,*/}*.jade'],
ignorePath: '<%= config.app.root %>/',
exclude: ['<%= config.app.root %>/bower_components/bootstrap-sass/vendor/assets/javascripts/bootstrap.js', ],
},
sass: {
src: ['<%= config.app.styles %>/{,*/}*.{scss,sass}'],
ignorePath: '<%= config.app.root %>/bower_components/'
}
},
// Reads HTML for usemin blocks to enable smart builds that automatically
// concat, minify and revision files. Creates configurations in memory so
// additional tasks can operate on them
useminPrepare: {
options: {
dest: '<%= config.dist.assets %>'
},
html: '<%= config.dist.snippets %>/{,*/}*.php'
},
// Performs rewrites based on rev and the useminPrepare configuration
usemin: {
options: {
assetDirs: '<%= config.dist.assets %>',
basedir: '',
dirs: '<%= config.app.root %>'
},
html: '<%= config.dist.snippets %>/{,*/}*.php',
css: '<%= config.dist.styles %>/{,*/}*.css'
},
// The following *-min tasks produce minified files in the dist folder
imagemin: {
dist: {
files: [{
expand: true,
cwd: '<%= config.app.img %>/',
src: '{,*/}*.{gif,jpeg,jpg,png}',
dest: '<%= config.dist.img %>'
}]
}
},
// Copies remaining files to places other tasks can use
copy: {
all: {
files: [
{
expand: true,
dot: true,
cwd: '<%= config.app.styles %>/',
dest: '.tmp/styles/',
src: '{,*/}*.css'
},
{
// Copy any javascript files to the tem directory
expand: true,
dot: true,
cwd: '<%= config.app.scripts %>/',
dest: '.tmp/scripts/',
src: '{,*/}*.js'
},
{
expand: true,
dot: true,
cwd: '<%= config.app.root %>/',
dest: '<%= config.dist.site %>',
src: [
'*.{ico,png,txt,svg}',
'.htaccess',
'*.php',
]
}
]
},
dist: {
files: [
{
expand: true,
dot: true,
cwd: '<%= config.app.root %>/',
dest: '<%= config.dist.assets %>',
src: [
'images/{,*/}*.{webp,svg}',
'fonts/{,*/}*.*'
]
}
]
}
},
// Renames files for browser caching purposes
rev: {
dist: {
files: {
src: [
'<%= config.dist.scripts %>/{,*/}*.js',
'<%= config.dist.styles %>/{,*/}*.css',
'!<%= config.dist.img %>/{,*/}*.*', // Don't rev images
'<%= config.dist %>/fonts/{,*/}*.*',
'<%= config.dist %>/*.{ico,png}'
]
}
}
},
// Generates a custom Modernizr build that includes only the tests you
// reference in your app
modernizr: {
devFile: '<%= config.app.root %>/bower_components/modernizr/modernizr.js',
outputFile: '<%= config.dist.scripts %>/modernizr-custom.js',
files: [
'<%= config.dist.scripts %>/{,*/}*.js',
'<%= config.dist.styles %>/{,*/}*.css',
'!<%= config.dist.scripts %>/vendor/*'
],
uglify: true,
extra: {
shiv: false,
load: false
}
},
bump: {
options: {
files: ['package.json', 'bower.json'],
push: true,
pushTo: 'origin',
createTag: true,
tagName: 'v%VERSION%',
tagMessage: 'Version %VERSION%',
commitFiles: ['<%= bump.options.files %>', 'CHANGELOG.md'],
commitMessage: 'Bumped version to v%VERSION%'
}
},
changelog: {
options: {
editor: 'atom -w'
}
},
// Run some tasks in parallel to speed up build process
concurrent: {
options: {
logConcurrentOutput: true,
limit: 5
},
server: [
'compass:server',
'newer:coffee',
'newer:copy:all',
'newer:copy:dist'
],
dist: [
'compass:dist',
'coffee',
'copy:all',
'imagemin'
]
}
});
grunt.registerTask('serve', function () {
grunt.task.run([
'clean',
'jadephp:dist',
'concurrent:server',
'autoprefixer',
'connect:livereload',
'watch'
]);
});
grunt.registerTask('server', function (target) {
grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
grunt.task.run([target ? ('serve:' + target) : 'serve']);
});
grunt.registerTask('default', [
'clean',
'jadephp:dist',
'useminPrepare',
'concurrent:dist',
'jshint',
'autoprefixer',
'copy:dist',
'concat',
'uglify',
'cssmin',
'modernizr',
// 'rev',
'usemin',
'connect:dist'
]);
};
{
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-coffee": "~0.7.0",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-compass": "~0.7.2",
"grunt-contrib-jshint": "~0.7.0",
"grunt-contrib-cssmin": "~0.7.0",
"grunt-contrib-connect": "~0.5.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-htmlmin": "~0.1.3",
"grunt-bower-install": "~1.0.0",
"grunt-contrib-imagemin": "~0.5.0",
"grunt-contrib-watch": "~0.5.2",
"grunt-autoprefixer": "~0.5.0",
"grunt-usemin": "~2.0.0",
"grunt-modernizr": "~0.4.0",
"grunt-newer": "~0.6.0",
"grunt-concurrent": "~0.4.0",
"load-grunt-tasks": "~0.2.0",
"grunt-php": "~0.2.0",
"time-grunt": "~0.2.0",
"jshint-stylish": "~0.1.3",
"grunt-contrib-jade": "~0.11.0",
"grunt-conventional-changelog": "~1.1.0",
"grunt-bump": "0.0.14",
"grunt-html-validation": "~0.1.17",
"grunt-uncss": "~0.3.3",
"grunt-jade-php": "~0.1.0",
"connect-livereload": "~0.4.0"
},
"engines": {
"node": ">=0.8.0"
}
}
@craigmdennis
Copy link
Author

You'll need the livereload browser plugin as the snippet isn't injected into the page for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment