Skip to content
This repository was archived by the owner on Oct 6, 2023. It is now read-only.

Commit 751f277

Browse files
committed
add raw tag
1 parent c449dea commit 751f277

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

lib/liquid/LiquidTagRaw.cfc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<cfcomponent extends="LiquidBlock" hint="
2+
temporarily disable tag processing to avoid syntax conflicts.
3+
4+
example:
5+
{% raw %}{% comment %} test {% endcomment %}{% endraw %}
6+
7+
will render:
8+
{% comment %} test {% endcomment %}
9+
">
10+
11+
<cffunction name="parse">
12+
<cfargument name="tokens" type="array" required="true">
13+
<cfset var loc = {}>
14+
<cfset loc.tag_regexp = createObject("component", "LiquidRegexp").init('^#application.LiquidConfig.LIQUID_TAG_START#\s*(\w+)\s*(.*)?#application.LiquidConfig.LIQUID_TAG_END#$')>
15+
16+
<cfif !IsArray(arguments.tokens)>
17+
<cfreturn>
18+
</cfif>
19+
20+
<cfloop condition="#ArrayLen(arguments.tokens)#">
21+
22+
<cfset loc.temp = array_shift(arguments.tokens)>
23+
<cfset arguments.tokens = loc.temp.arr>
24+
<cfset loc.token = loc.temp.value>
25+
<cfset loc.tag_regexp.match(loc.token)>
26+
27+
<cfif loc.tag_regexp.match(loc.token)>
28+
29+
<!--- if we found the proper block delimitor just end parsing here and let the outer block proceed --->
30+
<cfif loc.tag_regexp.matches[2] eq this.block_delimiter()>
31+
<cfreturn this.end_tag()>
32+
</cfif>
33+
34+
</cfif>
35+
36+
<cfset arrayAppend(this._nodelist, loc.token)>
37+
38+
</cfloop>
39+
40+
<cfset this.assert_missing_delimitation()>
41+
</cffunction>
42+
43+
</cfcomponent>

tests/index.cfm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
<cfelse>
1616

17-
<cfset test = createObject("component", "cfml-liquid.tests.tests.StandardFilterTest")>
18-
<cfset test.runTest("test", "test_remove_first")>
17+
<cfset test = createObject("component", "cfml-liquid.tests.tests.RawTest")>
18+
<cfset test.runTest("test", "test_output_in_raw")>
1919

2020
</cfif>
2121

tests/tests/RawTest.cfc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<cfcomponent output="false" extends="cfml-liquid.tests.Test">
2+
3+
<cffunction name="setup">
4+
<cfset loc.template = application.liquid.template()>
5+
</cffunction>
6+
7+
<cffunction name="test_tag_in_raw">
8+
<cfset loc.e = "{% comment %} test {% endcomment %}">
9+
<cfset loc.t = "{% raw %}{% comment %} test {% endcomment %}{% endraw %}">
10+
<cfset assert_template_result(loc.e, loc.t, loc.template)>
11+
</cffunction>
12+
13+
<cffunction name="test_output_in_raw">
14+
<cfset loc.e = "{{ test }}">
15+
<cfset loc.t = "{% raw %}{{ test }}{% endraw %}">
16+
</cffunction>
17+
18+
</cfcomponent>

0 commit comments

Comments
 (0)