Skip to content

Commit

Permalink
feat(tag): add debugger tag
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Mar 28, 2017
1 parent 34a4bcc commit 65ac9cd
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path')
const edge = require('../index')
const viewsPath = path.join(__dirname, '/views')
edge.registerViews(viewsPath)
edge.configure({cache: true})
edge.configure({cache: false})
edge.registerPresenters(path.join(__dirname, '/presenters'))

require('http').createServer((req, res) => {
Expand Down
73 changes: 73 additions & 0 deletions src/Tags/Debugger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict'

/*
* 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.
*/

const BaseTag = require('./BaseTag')

/**
* The debugger tag for runtime debugging
* inside chrome dev tools.
*
* @class DebuggerTag
* @extends {BaseTag}
* @static
*/
class DebuggerTag extends BaseTag {
/**
* Tag name to be used for registering
* the tag
*
* @method tagName
*
* @return {String}
*/
get tagName () {
return 'debugger'
}

/**
* Whether or not the tag is block level
* tag. Which is no in this case.
*
* @method isBlock
*
* @return {Boolean}
*/
get isBlock () {
return false
}

/**
* Compile the template
*
* @method compile
*
* @param {Object} compiler
* @param {Object} lexer
* @param {Object} buffer
* @param {String} options.body
* @param {Array} options.childs
* @param {Number} options.lineno
*
* @return {void}
*/
compile (compiler, lexer, buffer, { body, childs, lineno }) {
buffer.writeLine('debugger')
}

/**
* Nothing needs to be done in runtime
* for debugger tag
*/
run () {
}
}

module.exports = DebuggerTag
3 changes: 2 additions & 1 deletion src/Tags/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ module.exports = {
componentTag: new (require('./ComponentTag'))(),
slotTag: new (require('./SlotTag'))(),
sectionTag: new (require('./SectionTag'))(),
yieldTag: new (require('./YieldTag'))()
yieldTag: new (require('./YieldTag'))(),
debugger: new (require('./Debugger'))()
}
10 changes: 1 addition & 9 deletions src/Template/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,7 @@ class TemplateCompiler {
* @return {void}
*/
parsePlainLine ({ body, lineno }) {
/**
* Adding support of debugger to do runtime debugging
* of templates via chrome dev tools.
*/
if (body.trim() === '@debugger') {
this.buffer.writeLine('debugger')
} else {
this.buffer.writeToOutput(this._interpolateMustache(body, lineno))
}
this.buffer.writeToOutput(this._interpolateMustache(body, lineno))
}

/**
Expand Down

0 comments on commit 65ac9cd

Please sign in to comment.