inject-template
Inject template into innerHTML
Last updated 3 years ago by basicelements .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install inject-template 
SYNC missed versions from official npm registry.

inject-template NPM version Build Status Dependency Status Coverage percentage

Inject template into innerHTML

Installation

$ npm install --save inject-template

Usage

  • An template tag in the desired element 1
  • An html template 2
var injectTemplate = require('inject-template');

let result = injectTemplate.inject({path: 'rainbow.js'}) // injects content from rainbow.html
// dosomething with result ...

result

class Rainbow extends HTMLElement {
  constructor() {
    super();
    this.innerHTML = 'BIG RAINBOW';
  }
  ...
}

rainbow.js 1

class Rainbow extends HTMLElement {
  constructor() {
    super();
    // @template rainbow
  }
  ...
}

rainbow.html 2

<template>
  BIG RAINBOW
</template>

Named templates

var injectTemplate = require('inject-template');

let result = injectTemplate.inject({path: 'rainbow.js', name: 'rainbow-template'}) // injects content from rainbow-template.html

Custom templates path

var injectTemplate = require('inject-template');

let result = injectTemplate.inject({path: 'rainbow.js', templatePath: 'templates'}) // injects content from templates/rainbow.html

API

injectTemplate.inject({options})

injectTemplate.injectSync({options})

options

path

Type: string
Default: null

Path to file containing the template tag

templatePath

Type: string
Default: null

Path to the template (use when your template is in another directory).

When undefined inject-template assumes the template in in the same directory of the element

content

Type: string
Default: null

The content of the element (used in gulp-inject-html-template)

When streaming files, you can pass trough the content so inject-template doesn't need to read the element.

License

MIT © Glenn Vandeuren

Current Tags

  • 1.1.0                                ...           latest (3 years ago)

11 Versions

  • 1.1.0                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 0.2.2                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.2                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 12
Dependencies (0)
None
Dev Dependencies (16)

Copyright 2014 - 2017 © taobao.org |