瀏覽代碼

Simplified tag RegEx. Fixed bug preventing section modifiers inside comments.

Justin Hileman 15 年之前
父節點
當前提交
9b8454f2ba
共有 2 個文件被更改,包括 4 次插入3 次删除
  1. 3 2
      Mustache.php
  2. 1 1
      examples/comments/comments.mustache

+ 3 - 2
Mustache.php

@@ -177,7 +177,7 @@ class Mustache {
 
 		$otag  = $this->prepareRegEx($this->otag);
 		$ctag  = $this->prepareRegEx($this->ctag);
-		$this->tagRegEx = '/' . $otag . "(#|\/|=|!|>|\\{|&)?([^\/#]+?)\\1?" . $ctag . "+/";
+		$this->tagRegEx = '/' . $otag . "([#\^\/=!>\\{&])?(.+?)\\1?" . $ctag . "+/";
 		$html = '';
 		$matches = array();
 		while (preg_match($this->tagRegEx, $template, $matches, PREG_OFFSET_CAPTURE)) {
@@ -210,6 +210,7 @@ class Mustache {
 	protected function renderTag($modifier, $tag_name, &$context) {
 		switch ($modifier) {
 			case '#':
+			case '^':
 				if ($this->throwSectionExceptions) {
 					throw new MustacheException('Unclosed section: ' . $tag_name, MustacheException::UNCLOSED_SECTION);
 				} else {
@@ -310,7 +311,7 @@ class Mustache {
 
 		$otag  = $this->prepareRegEx($this->otag);
 		$ctag  = $this->prepareRegEx($this->ctag);
-		$this->tagRegEx = '/' . $otag . "(#|\/|=|!|>|\\{|&)?([^\/#\^]+?)\\1?" . $ctag . "+/";
+		$this->tagRegEx = '/' . $otag . "([#\^\/=!>\\{&])?(.+?)\\1?" . $ctag . "+/";
 		return '';
 	}
 

+ 1 - 1
examples/comments/comments.mustache

@@ -1 +1 @@
-<h1>{{title}}{{! just something interesting... or not... }}</h1>
+<h1>{{title}}{{! just something interesting... #or ^not... }}</h1>