-
-
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.
feat(component): implement component tag
- Loading branch information
1 parent
726142a
commit 01e8e95
Showing
29 changed files
with
347 additions
and
5 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,2 @@ | ||
{{ $slots.heading }} | ||
{{ $slots.main }} |
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,15 @@ | ||
(function (template, ctx) { | ||
let out = '' | ||
out += template.renderWithState('components-named-slots/alert', {}, { 'heading': (function (template, ctx) { | ||
let out = '' | ||
out += ' This is title' | ||
out += '\n' | ||
return out | ||
})(template, ctx), 'main': (function (template, ctx) { | ||
let out = '' | ||
out += ' This is then body' | ||
out += '\n' | ||
return out | ||
})(template, ctx) }) | ||
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,6 @@ | ||
@component('components-named-slots/alert') | ||
@slot('heading') | ||
This is title | ||
@endslot | ||
This is then body | ||
@endcomponent |
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,3 @@ | ||
This is title | ||
|
||
This is then body |
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 @@ | ||
{{ title }} | ||
{{ $slots.main }} |
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 = '' | ||
out += template.renderWithState('components-props/alert', { 'title': 'H1' }, { 'main': (function (template, ctx) { | ||
let out = '' | ||
out += 'Hello world' | ||
out += '\n' | ||
return out | ||
})(template, ctx) }) | ||
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 @@ | ||
@component('components-props/alert', { 'title': 'H1' }) | ||
Hello world | ||
@endcomponent |
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,2 @@ | ||
H1 | ||
Hello world |
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 @@ | ||
{{ $slots.main }} |
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,11 @@ | ||
(function (template, ctx) { | ||
let out = '' | ||
out += template.renderWithState('components-state/alert', {}, { 'main': (function (template, ctx) { | ||
let out = '' | ||
out += ' Hello ' | ||
out += `${ctx.escape(ctx.resolve('username'))}` | ||
out += '\n' | ||
return out | ||
})(template, ctx) }) | ||
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 @@ | ||
@component('components-state/alert') | ||
Hello {{ username }} | ||
@endcomponent |
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 @@ | ||
Hello 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 @@ | ||
{{ $slots.main }} |
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 = '' | ||
out += template.renderWithState('components/alert', {}, { 'main': (function (template, ctx) { | ||
let out = '' | ||
out += ' Hello world' | ||
out += '\n' | ||
return out | ||
})(template, ctx) }) | ||
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 @@ | ||
@component('components/alert') | ||
Hello world | ||
@endcomponent |
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 world |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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 { parseSequenceExpression, ObjectifyString } from '../utils' | ||
|
||
export class ComponentTag { | ||
public static block = true | ||
public static seekable = true | ||
public static selfclosed = true | ||
|
||
/** | ||
* Compiles else block node to Javascript else statement | ||
*/ | ||
public compile (parser: Parser, buffer: EdgeBuffer, token: IBlockNode) { | ||
const parsed = parser.generateAst(token.properties.jsArg, token.lineno) | ||
const expression = parser.parseStatement(parsed.body[0]) | ||
let [name, props] = parseSequenceExpression(expression, parser) | ||
|
||
const slots = {} | ||
token.children.forEach((child) => { | ||
let name = `'main'` | ||
if (child.type === 'block' && (child as IBlockNode).properties.name === 'slot') { | ||
name = (child as IBlockNode).properties.jsArg | ||
} | ||
|
||
slots[name] = slots[name] || new EdgeBuffer() | ||
parser.processToken(child, slots[name]) | ||
}) | ||
|
||
const obj = new ObjectifyString() | ||
Object.keys(slots).forEach((slot) => { | ||
obj.add(slot, slots[slot].flush()) | ||
}) | ||
|
||
buffer.writeLine(`template.renderWithState(${name}, ${props}, ${obj.flush()})`) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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' | ||
|
||
export class SlotTag { | ||
public static block = true | ||
public static seekable = true | ||
public static selfclosed = false | ||
|
||
/** | ||
* Compiles else block node to Javascript else statement | ||
*/ | ||
public compile (parser: Parser, buffer: EdgeBuffer, token: IBlockNode) { | ||
token.children.forEach((child, index) => { | ||
parser.processToken(child, buffer) | ||
}) | ||
} | ||
} |
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
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
Oops, something went wrong.