Pattern Library Utilities

utility

declaration
utility

@fileOverview
Uses Gulpjs to import html patterns

@author Scott Nath

@requires NPM:pattern-importer

var utility = require('../utility');

getDefaultOptions

function
getDefaultOptions()

Function to get default options for an implementation of patternlab-import

var getDefaultOptions = function () {
  'use strict';

  // default options for angularTemplatecache gulp task
  var options = {
    config: {
      compilePatternsOnImport: false,
      dataSource: 'pattern',
      dataFileName: 'pattern.yml',
      htmlTemplateDest: './source/_patterns',
      stylesDest: './source/css/scss',
      scriptsDest: './source/js',
      cssCompiler: 'sass', // sass, less, stylus, none
      templateEngine: 'twig',
      templateEngineOptions: {
        base: 'node_modules/pattern-library/patterns/',
        async: false
      },
      templateDonut: {
        twig: './node_modules/pattern-importer/templates/donut.twig'
      },
      convertCategoryTitles: true
    },
    src: ['./node_modules/pattern-library/patterns

gulpImportPatterns

method
exports.gulpImportPatterns()

@param Type Description
gulp Object gulpjs
projectOptions Object custom options

/pattern.yml'],
taskName: 'patterns-import', // default task name
dependencies: [] // gulp tasks which should be run before this task
};

return options;
};

/**
Gulp task to import raw patterns and convert them to browser-ready html/css/js

exports.gulpImportPatterns = function (gulp, projectOptions) {
  'use strict';
  var options = utility.mergeOptions(getDefaultOptions(), projectOptions);

the gulp task

gulp.task(options.taskName, options.dependencies, function () {

    return gulp.src(options.src)
      .pipe(utility.patternImporter(options.config))
      .pipe(gulp.dest('./'));

  });

};