GithubHelp home page GithubHelp logo

can-view-parser's Introduction

can-view-parser

Build Status

Parses html and magic tags.

API

can-view-parser function

Parse HTML and mustache tokens.

parse(html, handler, [returnIntermediate])

Parse an html string:

var parser = require("can-view-parser");

var html = '<h1><span bob="phillips"></span><span bob="meyers"></span>' +
	'</h1>';

var bobs = {};
var curAttr;

parser(html, {
	attrStart: function(attrName){
		curAttr = attrName;
	},
	attrValue: function(value){
		bobs[curAttr] = value;
	}
});

for(var first in bobs) {
	var last = bobs[first];
	console.log("Hello", first, last);
}
  1. html {String|Object}: A mustache and html string to parse or an intermediate object the represents a previous parsing.
  2. handler {Object}: An object of callbacks.
  3. returnIntermediate {Boolean}: If true, returns a JS object representation of the parsing.

ParseHandler {Object}

An object consisting of callback functions that handle stages in the parsing process.

Object

start(tagName, unary)

Called when parsing a tag begins.

  1. tagName {String}: The name of the tag.
  2. unary {Boolean}: If this tag is unary (has no closing tag).

end(tagName, unary)

Called at the end of parsing a tag.

  1. tagName {String}: The name of the tag.
  2. unary {Boolean}: If this tag is unary (has no closing tag).

close(tagName)

Called when a closing tag is found. If no closing tag exists for this tag (because it is self-closing) this function will not be called.

  1. tagName {String}: The name of the tag.

attrStart(attrName)

Called when an attribute is found on an element.

  1. attrName {String}: The name of the attribute.

attrEnd(attrName)

Called at the end of parsing an attribute; after the attrStart and attrValue functions have been called.

  1. attrName {String}: The name of the attribute.

attrValue(value)

Called when an attribute's value has been found.

  1. value {String}: The value discovered associated with an attribute.

chars(value)

Called when CharacterData is found within a tag.

  1. value {String}: The character data within the tag.

comment(value)

Called when a Comment is found within a tag.

  1. value {String}: The Comment within the tag.

done()

Called at the end of parsing the template.

Contributing

Making a Build

To make a build of the distributables into dist/ in the cloned repository run

npm install
node build

Running the tests

Tests can run in the browser by opening a webserver and visiting the test.html page. Automated tests that run the tests from the command line in Firefox can be run with

npm test

can-view-parser's People

Contributors

daffl avatar greenkeeperio-bot avatar iherndon avatar justinbmeyer avatar kylegifford avatar marshallswain avatar matthewp avatar phillipskevin avatar prashantsharmain avatar sinjhin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.