-
-
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
54a5ff1
commit cc4dc87
Showing
14 changed files
with
100 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,10 @@ | ||
(function (template, ctx) { | ||
let out = '' | ||
if(ctx.resolve('username')) { | ||
out += ctx.resolve('username') | ||
} else { | ||
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 @@ | ||
@yield(username) | ||
Hello guest | ||
@endyield |
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 @@ | ||
{} |
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,8 @@ | ||
(function (template, ctx) { | ||
let out = '' | ||
if(ctx.resolve('greeting')) { | ||
out += ctx.resolve('greeting') | ||
} else { | ||
} | ||
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 @@ | ||
@!yield(greeting) |
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 @@ | ||
{ | ||
"greeting": "Hello <strong>virk</strong>" | ||
} |
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 <strong>virk</strong> |
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 += ctx.resolve('username') | ||
} else { | ||
} | ||
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 @@ | ||
@!yield(username) |
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 @@ | ||
{ | ||
"username": "virk" | ||
} |
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 @@ | ||
virk |
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,58 @@ | ||
/* | ||
* 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 { allowExpressions } from '../utils' | ||
|
||
export class YieldTag { | ||
public static block = true | ||
public static seekable = true | ||
public static selfclosed = true | ||
public static tagName = 'if' | ||
|
||
/** | ||
* Expressions which are not allowed by the sequence | ||
* expression | ||
* | ||
* @type {Array} | ||
*/ | ||
private static allowedExpressions = ['Identifier', 'Literal', 'MemberExpression', 'CallExpression'] | ||
|
||
/** | ||
* Compiles the if block node to a Javascript if statement | ||
*/ | ||
public static compile (parser: Parser, buffer: EdgeBuffer, token: IBlockNode) { | ||
const parsed = parser.parseJsArg(token.properties.jsArg, token.lineno) | ||
allowExpressions('yield', parsed, this.allowedExpressions) | ||
|
||
/** | ||
* Start if block | ||
*/ | ||
const parsedString = parser.statementToString(parsed) | ||
|
||
/** | ||
* If main content is truthy | ||
*/ | ||
buffer.writeStatement(`if(${parsedString}) {`) | ||
buffer.indent() | ||
buffer.writeLine(parsedString) | ||
buffer.dedent() | ||
buffer.writeStatement('} else {') | ||
|
||
/** | ||
* Else write fallback | ||
*/ | ||
buffer.indent() | ||
token.children.forEach((child, index) => (parser.processToken(child, buffer))) | ||
buffer.dedent() | ||
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