-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41715b2
commit 60b2c0a
Showing
6 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(function (template, ctx) { | ||
let out = '' | ||
if(!ctx.resolve('username')) { | ||
out += ' Hello Guest' | ||
out += '\n' | ||
} | ||
return out | ||
})(template, ctx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@unless(username) | ||
Hello Guest | ||
@endunless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello Guest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* edge | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { Parser } from 'edge-parser' | ||
import { EdgeBuffer } from 'edge-parser/build/src/EdgeBuffer' | ||
import { IBlockNode } from 'edge-lexer/build/src/Contracts' | ||
import { disAllowExpressions } from '../utils' | ||
|
||
export class UnlessTag { | ||
public static block = true | ||
public static seekable = true | ||
public static selfclosed = false | ||
public static tagName = 'unless' | ||
|
||
/** | ||
* Expressions which are not allowed by the sequence | ||
* expression | ||
* | ||
* @type {Array} | ||
*/ | ||
protected bannedExpressions = ['SequenceExpression'] | ||
|
||
/** | ||
* Compiles the if block node to a Javascript if statement | ||
*/ | ||
public compile (parser: Parser, buffer: EdgeBuffer, token: IBlockNode) { | ||
const parsed = parser.parseJsArg(token.properties.jsArg, token.lineno) | ||
disAllowExpressions('unless', parsed, this.bannedExpressions) | ||
|
||
/** | ||
* Start if block | ||
*/ | ||
buffer.writeStatement(`if(!${parser.statementToString(parsed)}) {`) | ||
|
||
/** | ||
* Indent upcoming code | ||
*/ | ||
buffer.indent() | ||
|
||
/** | ||
* Process of all kids recursively | ||
*/ | ||
token.children.forEach((child, index) => { | ||
parser.processToken(child, buffer) | ||
}) | ||
|
||
/** | ||
* Remove identation | ||
*/ | ||
buffer.dedent() | ||
|
||
/** | ||
* Close if block | ||
*/ | ||
buffer.writeStatement('}') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters