Sha256: 6f9a4798054979574403fd6a3d3d6d99db153573666c1351643f52d59cc38646

Contents?: true

Size: 1.87 KB

Versions: 19

Compression:

Stored size: 1.87 KB

Contents

'use strict';

module.exports = function(grunt){

  grunt.registerMultiTask('builder', function() {

    var handlebars  = require('handlebars'),
        async       = require('async'),
        path        = require('path'),
        fs          = require('fs'),
        template    = require('../modules/templates'),
        fileHelper  = require('../modules/file'),
        slugify     = require("underscore.string/slugify"),
        promise     = this.async(),
        files       = this.files;

    var options = this.options({
      templates: './styleguide/**/*.tpl'
    });

    async.waterfall([
        init,
        generateStyleguide
    ], completeTask);

    function completeTask(){
      promise();
    }

    function init(callback){
      template.registerHelpers();
      generateTemplates(options.templates);
      callback(null);
    }

    function generateStyleguide(callback){
      files.forEach(function(file){
        var dest = file.dest,
            datum = grunt.file.readJSON(file.src[0]);
        generatePages(datum, datum.pages, dest);
      });
      callback(null, 'done');
    }

    function generatePages(data, pages, dest){
      pages.map(function(page){
        var model = {
          project: data.project,
          navigation: data.navigation,
          page: page,
          pages: data.pages
        };
        var outputFilePath = dest + slugify(page.section) + "/" + page.page,
            template = handlebars.compile(grunt.file.read(page.template))(model);

        fileHelper.writeFile(template, outputFilePath, "Build");
      });
    }

    function generateTemplates(templatePath){
      var templates = {};

      grunt.file.expand(templatePath).forEach(function(file){
        var templateName = path.basename(file, '.tpl');
        templates[templateName] = grunt.file.read(file);
      });

      handlebars.registerPartial(templates);
    }

  });
}

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ustyle-1.15.3 grunt/tasks/builder.js
ustyle-1.14.11 grunt/tasks/builder.js
ustyle-1.14.10 grunt/tasks/builder.js
ustyle-1.14.0 grunt/tasks/builder.js
ustyle-1.12.6 grunt/tasks/builder.js
ustyle-1.12.1 grunt/tasks/builder.js
ustyle-1.12.0 grunt/tasks/builder.js
ustyle-1.11.1 grunt/tasks/builder.js
ustyle-1.10.0 grunt/tasks/builder.js
ustyle-1.8.7 grunt/tasks/builder.js
ustyle-1.8.1 grunt/tasks/builder.js
ustyle-1.8.0 grunt/tasks/builder.js
ustyle-1.7.0 grunt/tasks/builder.js
ustyle-1.6.1 grunt/tasks/builder.js
ustyle-1.5.8 grunt/tasks/builder.js
ustyle-1.4.1 grunt/tasks/builder.js
ustyle-1.4.0 grunt/tasks/builder.js
ustyle-1.3.12 grunt/tasks/builder.js
ustyle-1.3.6 grunt/tasks/builder.js