-
-
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
5383d69
commit a76e7ac
Showing
7 changed files
with
87 additions
and
3 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,24 @@ | ||
let out = ""; | ||
let $lineNumber = 1; | ||
let $filename = "{{__dirname}}index.edge"; | ||
try { | ||
template.loop(state.users, function (user) { | ||
out += "\n"; | ||
$lineNumber = 2; | ||
let index = 0; | ||
$lineNumber = 3; | ||
index = index + 1; | ||
out += " "; | ||
$lineNumber = 4; | ||
out += `${template.escape(index)}`; | ||
}); | ||
$lineNumber = 6; | ||
state.index = (state.index || 0) + 1; | ||
out += ""; | ||
out += "\n"; | ||
$lineNumber = 8; | ||
out += `${template.escape(state.index)}`; | ||
} catch (error) { | ||
template.reThrow(error, $filename, $lineNumber); | ||
} | ||
return out; |
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 @@ | ||
@each(user in users) | ||
@let(index = 0) | ||
@assign(index = index + 1) | ||
{{ index }} | ||
@end | ||
@assign(index = (index || 0) + 1) | ||
|
||
{{ index }} |
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 @@ | ||
{ | ||
"users": ["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,2 @@ | ||
1 | ||
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,48 @@ | ||
/* | ||
* edge.js | ||
* | ||
* (c) EdgeJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { expressions } from 'edge-parser' | ||
import lodash from '@poppinss/utils/lodash' | ||
|
||
import { TagContract } from '../types.js' | ||
import { isSubsetOf, parseJsArg, unallowedExpression } from '../utils.js' | ||
|
||
/** | ||
* The assign tag is used to re-assign value to an existing variable | ||
*/ | ||
export const assignTag: TagContract = { | ||
block: false, | ||
seekable: true, | ||
tagName: 'assign', | ||
noNewLine: true, | ||
|
||
/** | ||
* Compiles else block node to Javascript else statement | ||
*/ | ||
compile(parser, buffer, token) { | ||
const parsed = parseJsArg(parser, token) | ||
|
||
isSubsetOf(parsed, [expressions.AssignmentExpression], () => { | ||
throw unallowedExpression( | ||
`Invalid expression for the @assign tag`, | ||
token.filename, | ||
parser.utils.getExpressionLoc(parsed) | ||
) | ||
}) | ||
|
||
buffer.writeExpression(parser.utils.stringify(parsed), token.filename, token.loc.start.line) | ||
}, | ||
|
||
/** | ||
* Add methods to the template for running the loop | ||
*/ | ||
boot(template) { | ||
template.macro('setValue', lodash.set) | ||
}, | ||
} |
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
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