Skip to content

Commit

Permalink
feat(debugger): add debugger tag
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jul 7, 2018
1 parent d102d75 commit 772cdb7
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 4 deletions.
7 changes: 5 additions & 2 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

const edge = require('..')
const { join } = require('path')
const http = require('http')

edge.mount(join(__dirname, './views'))
console.log(edge.render('user', { title: 'Hello' }))
http.createServer((req, res) => {
edge.mount(join(__dirname, './views'))
res.end(edge.render('user', { title: 'Hello' }))
}).listen(3000)
6 changes: 5 additions & 1 deletion examples/views/alert.edge
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<h2> {{ title }} </h2>
@if($slots.title)
{{{ $slots.title({ title }) }}}
@else
<h2> {{ title }} </h2>
@endif
1 change: 1 addition & 0 deletions examples/views/partial.edge
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Inside slot: {{ slotTitle() }}</h1>
7 changes: 6 additions & 1 deletion examples/views/user.edge
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
@!component('alert', title = 'Hey')
@debugger
@component('alert', title = 'Hey')
@slot('title', props)
@include('partial')
@endslot
@endcomponent
@!component('alert', title = 'Wow')
9 changes: 9 additions & 0 deletions examples/views/user.presenter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = class User {
constructor (state) {
this.state = state
}

slotTitle (ctx) {
return ctx.resolve('props').title.toUpperCase()
}
}
7 changes: 7 additions & 0 deletions fixtures/debugger/compiled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function (template, ctx) {
let out = ''
debugger;
out += 'Hello'
out += '\n'
return out
})(template, ctx)
2 changes: 2 additions & 0 deletions fixtures/debugger/index.edge
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@debugger
Hello
2 changes: 2 additions & 0 deletions fixtures/debugger/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
1 change: 1 addition & 0 deletions fixtures/debugger/index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello
26 changes: 26 additions & 0 deletions src/Tags/Debugger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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 DebuggerTag {
public static block = false
public static seekable = false
public static selfclosed = false
public static tagName = 'debugger'

/**
* Compiles else block node to Javascript else statement
*/
public compile (parser: Parser, buffer: EdgeBuffer, token: IBlockNode) {
buffer.writeStatement('debugger;')
}
}
1 change: 1 addition & 0 deletions src/Tags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export { IncludeTag as include } from './Include'
export { EachTag as each } from './Each'
export { ComponentTag as component } from './Component'
export { SlotTag as slot } from './Slot'
export { DebuggerTag as debugger } from './Debugger'

0 comments on commit 772cdb7

Please sign in to comment.