All Projects → meeroslav → gulp-inject-partials

meeroslav / gulp-inject-partials

Licence: MIT License
A recursive injection of partials based on their path name. Implementation of specific case of gulp-inject.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to gulp-inject-partials

email-framework
A simple, gulp powered framework to develop and test responsive emails.
Stars: ✭ 19 (-26.92%)
Mutual labels:  gulp, partials
file-include-webpack-plugin
A webpack plugin to include files using @@ include syntax in html files, like gulp-file-include
Stars: ✭ 16 (-38.46%)
Mutual labels:  gulp, partials
i-Cut
🔨 个人技术栈
Stars: ✭ 18 (-30.77%)
Mutual labels:  gulp
speedy
Development environment for static pages using Gulp - Pug & Sass & browser-sync & babelify & browserify
Stars: ✭ 13 (-50%)
Mutual labels:  gulp
gDorks
Vulnerable website scraper
Stars: ✭ 25 (-3.85%)
Mutual labels:  injection
landing
This project builds the static and internationalized landing page of Upplication.
Stars: ✭ 26 (+0%)
Mutual labels:  gulp
gulp-tape
👻 Run Tape tests in Gulp.
Stars: ✭ 14 (-46.15%)
Mutual labels:  gulp
middleman-gulp
A Middleman 4 template using Gulp.js via the external pipeline
Stars: ✭ 42 (+61.54%)
Mutual labels:  gulp
nosqlilab
A lab for playing with NoSQL Injection
Stars: ✭ 90 (+246.15%)
Mutual labels:  injection
react-flux-gulp-starter
A universal boilerplate for building React/Flux apps using Gulp and ES6.
Stars: ✭ 46 (+76.92%)
Mutual labels:  gulp
generator-angular-pro
AngularJS project generator for scalable, enterprise-grade web and mobile applications
Stars: ✭ 43 (+65.38%)
Mutual labels:  gulp
anyfs
Portable file system for Node
Stars: ✭ 17 (-34.62%)
Mutual labels:  gulp
generator-espress
an opinionated yeoman generator that scaffolds a mvc express webapp completely in es6
Stars: ✭ 20 (-23.08%)
Mutual labels:  gulp
brage-ghost-theme
A Ghost theme built with Gulp
Stars: ✭ 44 (+69.23%)
Mutual labels:  gulp
Proxybound
Linux applications proxifier
Stars: ✭ 81 (+211.54%)
Mutual labels:  injection
bulletproof-email
A Gulp workflow for maintainable email templates
Stars: ✭ 71 (+173.08%)
Mutual labels:  gulp
gulp-webpack-boilerplate
A good foundation for your next frontend project.
Stars: ✭ 56 (+115.38%)
Mutual labels:  gulp
design-studio one-page-template
Free responsive flat designed one page template
Stars: ✭ 67 (+157.69%)
Mutual labels:  gulp
spring-boot-angular2-starter
Starter application. Spring Boot, Angular 2, TypeScript, Gulp, Gradle, SCSS.
Stars: ✭ 35 (+34.62%)
Mutual labels:  gulp
EVA2
Another version of EVA using anti-debugging techs && using Syscalls
Stars: ✭ 223 (+757.69%)
Mutual labels:  injection

gulp-inject-partials

NPM version Build Status Dependency Status Code Climate

A recursive injection of partials based on their path name for gulp.

Gulp-inject-partials parses target file, located defined placeholders and injects file contents based on their relative path. See Basic usage and More examples below. Gulp-inject-partials is based/inspired by gulp-inject.

Note: NodeJs v4 or above is required.

Installation

Install gulp-inject-partials as a development dependancy:

npm install --save-dev gulp-inject-partials

Basic usage

Each pair of comments are the injection placeholders (aka. tags, see options.start and options.end).

index.html

<!DOCTYPE html>
<html>
<head>
  <title>My index</title>
</head>
<body>
  <!-- partial:partial/_mypartial.html -->
  <!-- partial -->
</body>
</html>

partial/_mypartial.html

<div>
  This text is in partial
</div>

gulpfile.js

var gulp = require('gulp');
var injectPartials = require('gulp-inject-partials');

gulp.task('index', function () {
  return gulp.src('./src/index.html')
           .pipe(injectPartials())
           .pipe(gulp.dest('./src'));
});

Results in

<!DOCTYPE html>
<html>
<head>
  <title>My index</title>
</head>
<body>
  <!-- partial:views/_mypartial.html -->
  <div>
  This text is in partial
</div>
  <!-- partial -->
</body>
</html>

More examples

Injecting nested partials

Nesting partials works same way as single level injection. When injecting partials, gulp-inject-partials will parse parent file in search for partials to inject. Once it finds a partial will then recursively parse child partial.

index.html

<!DOCTYPE html>
<html>
<head>
  <title>My index</title>
</head>
<body>
  <!-- partial:views/_mypartial.html -->
  <!-- partial -->
</body>
</html>

views/_mypartial.html

<div>
  This is in partial
  <!-- partial:_mypartial2.html -->
  <!-- partial -->
  <!-- partial:_mypartial3.html -->
  <!-- partial -->
</div>

views/_mypartial2.html

<div>
  This text is in partial 2
</div>

views/_mypartial3.html

<div>
  This text is in partial 3
</div>

gulpfile.js

var gulp = require('gulp');
var injectPartials = require('gulp-inject-partials');

gulp.task('index', function () {
  return gulp.src('./src/index.html')
           .pipe(injectPartials())
           .pipe(gulp.dest('./src'));
});

Results in

<!DOCTYPE html>
<html>
<head>
  <title>My index</title>
</head>
<body>
  <!-- partial:views/_mypartial.html -->
  <div>
  This is in partial
  <!-- partial:_mypartial2.html -->
  <div>
  This text is in partial 2
</div>
  <!-- partial -->
  <!-- partial:_mypartial3.html -->
  <div>
  This text is in partial 3
</div>
  <!-- partial -->
</div>
  <!-- partial -->
</body>
</html>

Setting the custom start and/or end tag

It's possible to change start and end tag by setting option.start and options.end respectivelly.

index.html

<!DOCTYPE html>
<html>
<head>
  <title>My index</title>
</head>
<body>
  <## partial/_mypartial.html>
  </##>
</body>
</html>

partial/_mypartial.html

<div>
  This text is in partial
</div>

gulpfile.js

var gulp = require('gulp');
var injectPartials = require('gulp-inject-partials');

gulp.task('index', function () {
  return gulp.src('./src/index.html')
           .pipe(injectPartials({
              start: '<## {{path}}>',
              end: '</##>'
           }))
           .pipe(gulp.dest('./src'));
});

Results in

<!DOCTYPE html>
<html>
<head>
  <title>My index</title>
</head>
<body>
  <!-- partial:views/_mypartial.html -->
  <div>
  This text is in partial
</div>
  <!-- partial -->
</body>
</html>

Remove tags after insertion

For production purposes we would like inject tags to be removed and have a clean html. This is possible with options.removeTags.

index.html

<!DOCTYPE html>
<html>
<head>
  <title>My index</title>
</head>
<body>
  <!-- partial:partial/_mypartial.html -->
  <!-- partial -->
</body>
</html>

partial/_mypartial.html

<div>
  This text is in partial
</div>

gulpfile.js

var gulp = require('gulp');
var injectPartials = require('gulp-inject-partials');

gulp.task('index', function () {
  return gulp.src('./src/index.html')
           .pipe(injectPartials({
              removeTags: true
           }))
           .pipe(gulp.dest('./src'));
});

Results in

<!DOCTYPE html>
<html>
<head>
  <title>My index</title>
</head>
<body>
  <div>
  This text is in partial
</div>
</body>
</html>

API

inject(options)

options.start

Type: string
Param (optional): path - relative path to source file
Default: <!-- partial:{{path}} -->
Used to dynamically set starting placeholder tag, which might contain relative path to source file. Even thou this parameter is optional, whithout it no file would be injected.

options.end

Type: string
Param (optional): path - relative path to source file
Default: <!-- partial -->
Used to dynamically set ending placeholder tag, which might contain relative path to source file.

options.removeTags

Type: boolean
Default: false
When true the start and end tags will be removed when injecting files.

options.quiet

Type: boolean
Default: false
When true gulp task will not render any information to console.

options.prefix

Type: string
Default: (Empty string)
Prefix path to prepend to every route processed e.g. relative/path/to/partials/. Note that full route is still relative.

options.ignoreError

Type: 'boolean' Default: false When true ignores missing files during the injection and shows just info message

License

MIT © Miroslav Jonas

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].