npm.io
0.1.0 • Published 11 years agoCLI

hbs-extract

Licence
MIT
Version
0.1.0
Deps
7
Vulns
5
Weekly
0

hbs-extract

Install

npm install -g hbs-extract

Usage

  Usage: hbs-extract [options] <hbs_template, default value: "index.hbs">

  Options:

    -h, --help               output usage information
    -o, --output [filename]  output result to a json file.
    -V, --version            output the version number

Example

<html>
	<head>
		<title>
			{{title}}
		</title>
	</head>

	<body>
    {{body}}
    {{#each people}}
      <div>
        <h1>name:</h1>{{name}}
        <div>
          Works:
          <ul>
            {{#each work}}
              <li>
              {{content}}
              </li>
            {{/each}}
          </ul>
            {{mycar.title}}
        </div>
      </div>
     {{/each}}
     {{footer.content}}
	</body>
</html>

Result

{
    "title": "",
    "body": "",
    "people": [{
        "name": "",
        "work": [{
            "content": ""
        }],
        "mycar": {
            "title": ""
        }
    }],
    "footer": {
        "content": ""
    }
}

API

hbs_extract.fromFile(hbs_file)

-hbs_file: path to hbs file

return a promise

hbs_extract.fromFile(hbs_file)
  .then(function(result) {
    // console.log(result)
  });
hbs_extract.raw(hbs_content)

-hbs_content: string

return data

var data = hbs_extract.raw(hbs_str);

Keywords