Complies in server, Render in browser. online demo, examples
Install
|
|
Usage
Complie htmls
|
|
Use in browser:
|
|
help
|
|
Api
jqfy.compile(html, [opts])
arguments:
html
: stringopts
: objectname
: string|arrayreturnType
: string, (contents|html|root), default: contentstrim
: boolean, default truecomment
: boolean, default truefixReturnType
: boolean, default falsereturnObject
: boolean, default false
html: input html
opts.name: name of generated function as string or array. when you are use nested name, this better to use array.
opts.returnType: default return type of generated function.
opts.trim: remove white unnecessary white spaces.
opts.comment: keep html comments.
opts.fixReturnType: boolean, if true, fix return type of generated function, else generated function check returnType
option.
opts.returnObject: boolean, if true, return object and set output in $
field of object. it will be useful sometimes
return
code of generated function
jqfy.append(html, [opts])
like compile, but save code in memory
jqfy.getCode([name],[opts])
get in memory generated code with umd
arguments
name
: string, defaulttemplates
. name for umd moduleopts
: objectuseShortcutFunctions
: boolean, default false- and all options that available in compile.
name: name of global variable used in umd.
opts.useShortcutFunctions: boolean, if true, we generate some shortcut function and use them. If you are compiling many files, this option cause you got smaller file.
jqfy.flush()
remove in memory codes
Example
|
|
output:
|
|
Custom tags and attributes
script
tag
We write content of script tags to body of function.
jqfy:name
attribute
Whit this attribute you can set variable name.
{{val}}
in text or attribute name and value
render value of data.val
in the output html.
note: in attribute name use {{var}}
without space. for example {{ x }}
not supported in attributes name
example
input html:
|
|
use:
|
|
output:
|
|
How it works
First we parse your html with cheerio then foreach tag generate a code. This code create a jquery object and set id, class and attributes of element, then append jquery object to parent's jquery object. if script tags exist in your html, we append content of script to generated code.