gulp-ex-file-include
a plugin of gulp for file include
install
npm install gulp-ex-file-include
options
- options - type:
string
, just as prefix, default@@
, and basepath is default@file
-
options - type:
object
- prefix:
string
, default@@
- suffix:
string
, default''
- basepath:
string
, default@file
, it could be@root
,@file
,your-basepath
- filters:
object
, filters of include content - context:
object
, context ofif
statement - indent:
boolean
, defaultfalse
- prefix:
-
options.basepath - type:
string
, it could be@root
, include file relative to the dir wheregulp
running in@file
, include file relative to the dir wherefile
in exampleyour-basepath
include file relative to the basepath you give
example
- @@include options - type:
JSON
index.html
@@include('./view.html') @@include('./var.html', { "name": "haoxin", "age": 12345, "socials": { "fb": "facebook.com/include", "tw": "twitter.com/include" } })
view.html
view
var.html
@@name@@age@@socials.fb@@socials.tw
gulpfile.js
var fileinclude = gulp = ; gulp;
and the result is:
view haoxin12345facebook.com/includetwitter.com/include
filters
@@include(markdown('view.md')) @@include('./var.html', { "name": "haoxin", "age": 12345 })
view.md
view====
var fileinclude = markdown = gulp = ; gulp;
include
statement
index.html
@@include('file.html', { "fileName": "index.txtIndex.txtIndex", "arr": []})
include
statement + data.json
index.html
@@include('article.html', 'data.json')
data.json
include
statement + variable
- index.html
@@inlcude("list.html", { "title": "列表", "list": [ { "title": "My post title", "text": "lorem ipsum..." }, { "title": "Another post", "text": "lorem ipsum..." }, { "title": "One more post", "text": "lorem ipsum..." } ] })
- list.html
@@title @@loop("item.html", `list`)
- item.html
@@title @@text
if
statement
;
@@include('some.html', { "nav": true })
@@if (name === 'test' && nav === true) {
@@include('test.html')
}
for
statement
;
@@for (var i = 0; i < arr.length; i++) { `+arr[i]+`}
loop
statement
- index.html
@@loop('loop-article.html', [ { "title": "My post title", "text": "lorem ipsum..." }, { "title": "Another post", "text": "lorem ipsum..." }, { "title": "One more post", "text": "lorem ipsum..." } ])
- loop-article.html
@@title @@text
loop
statement + data.json
data.json
"title": "My post title" "text": "<p>lorem ipsum...</p>" "title": "Another post" "text": "<p>lorem ipsum...</p>" "title": "One more post" "text": "<p>lorem ipsum...</p>"
- loop-article.html
@@loop("loop-article.html", "data.json")
loop
statement + variable
- index.html
@@inlcude("loop-article.html", { "list": [ { "title": "My post title", "text": "lorem ipsum..." }, { "title": "Another post", "text": "lorem ipsum..." }, { "title": "One more post", "text": "lorem ipsum..." } ] })
- loop-article.html
@@loop("loop-article.html", `list`)
webRoot
built-in context variable
The webRoot
field of the context contains the relative path from the source document to
the source root (unless the value is already set in the context options).
example
support/contact/index.html
Support Contact Info Home
and the result is:
Support Contact Info Home
License
MIT