Exemplo n.º 1
0
import Parser from 'parse/Parser/_Parser';
import conditional from 'parse/Parser/expressions/conditional';
import flattenExpression from 'parse/Parser/utils/flattenExpression';
import parseJSON from 'utils/parseJSON';

var methodCallPattern = /^([a-zA-Z_$][a-zA-Z_$0-9]*)\(/,
	ExpressionParser;

ExpressionParser = Parser.extend({
	converters: [ conditional ]
});

// TODO clean this up, it's shocking
export default function ( tokens ) {
	var result,
		match,
		parser,
		args,
		token,
		colonIndex,
		directiveName,
		directiveArgs,
		parsed;

	if ( typeof tokens === 'string' ) {
		if ( match = methodCallPattern.exec( tokens ) ) {
			result = { m: match[1] };
			args = '[' + tokens.slice( result.m.length + 1, -1 ) + ']';

			parser = new ExpressionParser( args );
			result.a = flattenExpression( parser.result[0] );
Exemplo n.º 2
0
StandardParser = Parser.extend({
	init: function ( str, options ) {
		// config
		setDelimiters( options, this );

		this.sectionDepth = 0;

		this.interpolate = {
			script: !options.interpolate || options.interpolate.script !== false,
			style: !options.interpolate || options.interpolate.style !== false
		};

		if ( options.sanitize === true ) {
			options.sanitize = {
				// blacklist from https://code.google.com/p/google-caja/source/browse/trunk/src/com/google/caja/lang/html/html4-elements-whitelist.json
				elements: 'applet base basefont body frame frameset head html isindex link meta noframes noscript object param script style title'.split( ' ' ),
				eventAttributes: true
			};
		}

		this.sanitizeElements = options.sanitize && options.sanitize.elements;
		this.sanitizeEventAttributes = options.sanitize && options.sanitize.eventAttributes;
		this.includeLinePositions = options.includeLinePositions;
	},

	postProcess: function ( items, options ) {
		if ( this.sectionDepth > 0 ) {
			this.error( 'A section was left open' );
		}

		cleanup( items, options.stripComments !== false, options.preserveWhitespace, !options.preserveWhitespace, !options.preserveWhitespace, options.rewriteElse !== false );
		return items;
	},

	converters: [
		mustache,
		comment,
		element,
		text
	]
});