Sha256: a3d7405c0a2286005f3b7a20f0e8f5dacdf6fcda5cfbac09d660d36e70ac7120

Contents?: true

Size: 1.76 KB

Versions: 8

Compression:

Stored size: 1.76 KB

Contents

const handlebars = require('handlebars')
const async = require('async')
const path = require('path')
const template = require('../modules/templates')
const fileHelper = require('../modules/file')
const slugify = require('underscore.string/slugify')

module.exports = function (grunt) {
  grunt.registerMultiTask('builder', function () {
    var promise = this.async()
    var 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) {
        const dest = file.dest
        const datum = grunt.file.readJSON(file.src[0])
        generatePages(datum, datum.pages, dest)
      })
      callback(null, 'done')
    }

    function generatePages (data, pages, dest) {
      pages.map(function (page) {
        const model = {
          project: data.project,
          navigation: data.navigation,
          page: page,
          pages: data.pages
        }
        const outputFilePath = dest + slugify(page.section) + '/' + page.page
        const 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

8 entries across 8 versions & 2 rubygems

Version Path
reustyle-2.0.11 grunt/tasks/builder.js
reustyle-2.0.10 grunt/tasks/builder.js
reustyle-2.0.9 grunt/tasks/builder.js
reustyle-2.0.8 grunt/tasks/builder.js
reustyle-2.0.7 grunt/tasks/builder.js
ustyle-1.19.2 grunt/tasks/builder.js
ustyle-1.16.2 grunt/tasks/builder.js
ustyle-1.16.1 grunt/tasks/builder.js