Skip to content

Instantly share code, notes, and snippets.

@jlbruno
Last active March 22, 2024 18:36
Show Gist options
  • Select an option

  • Save jlbruno/decf823aa7e60a3e210db0a50e34dd34 to your computer and use it in GitHub Desktop.

Select an option

Save jlbruno/decf823aa7e60a3e210db0a50e34dd34 to your computer and use it in GitHub Desktop.

Revisions

  1. jlbruno renamed this gist Feb 13, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. jlbruno revised this gist Nov 29, 2022. 2 changed files with 80 additions and 4 deletions.
    73 changes: 72 additions & 1 deletion ObjectDebug.js
    Original file line number Diff line number Diff line change
    @@ -15,4 +15,75 @@ function debug(debugObject, debugLabel) {



    module.exports.debug = debug;
    /**
    * Allows you to console.log from within a backend script or isscript block
    * Exposes some of the built in console logging methods
    * Pass in as many arguments as you'd like, they'll get output in a comma delimted list
    */
    var console = function() {

    var str = function(args) {
    var temp = '';
    // loop through arguments and add argument to string
    for (var i = 0, j = args.length; i < j; i++){
    var comma = ((i === 0) ? '' : ', ');
    temp = temp + comma + args[i];
    }
    return temp;
    }


    function log() {
    var string = "<script>console.log('" + str(arguments) + "');</script>";
    response.writer.print(string);
    }


    function debug() {
    var string = "<script>console.debug('" + str(arguments) + "');</script>";
    response.writer.print(string);
    }

    function info() {
    var string = "<script>console.info('" + str(arguments) + "');</script>";
    response.writer.print(string);
    }

    function warn() {
    var string = "<script>console.warn('" + str(arguments) + "');</script>";
    response.writer.print(string);
    }

    function error() {
    var string = "<script>console.error('" + str(arguments) + "');</script>";
    response.writer.print(string);
    }


    function group() {
    var string = "<script>console.group('" + str(arguments) + "');</script>";
    response.writer.print(string);
    }

    function groupEnd() {
    var string = "<script>console.groupEnd('" + str(arguments) + "');</script>";
    response.writer.print(string);
    }

    return {
    log: log,
    debug: debug,
    info: info,
    warn: warn,
    error: error,
    group: group,
    groupEnd: groupEnd
    }
    }();



    module.exports = {
    debug: debug,
    console: console
    }
    11 changes: 8 additions & 3 deletions test.isml
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,9 @@
    <isscript>
    var ObjectDebug = require('*/cartridge/scripts/util/ObjectDebug');
    ObjectDebug.debug(pdict, 'pdict');
    </isscript>
    var Debug = require('*/cartridge/scripts/util/DebugHelper');

    // pass in an object to see it in the debugger when running a debug session
    Debug.debug(pdict, "pdict");

    // call the console methods to output a value to your browser's console
    Debug.console.log('product name', pdict.product.name);
    </isscript>
  3. jlbruno revised this gist Aug 16, 2022. 2 changed files with 9 additions and 7 deletions.
    12 changes: 7 additions & 5 deletions ObjectDebug.js
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,16 @@
    'use strict';

    /**
    * A place to debug what's in pdict
    * A place to debug an object from an isml file
    * Useful to pass in pdict to see what it contains
    *
    * @param pdict Pipeline dictionary
    * @param debugObject Object you'd like to see in the debugger
    * @param debugLabel Optional label for the debugObject
    *
    **/
    function debug(object) {
    var temp = object; // put breakpoint here
    return temp;
    function debug(debugObject, debugLabel) {
    // debugObject and debugLabel will show in debugger
    return true; // put breakpoint here
    }


    4 changes: 2 additions & 2 deletions test.isml
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    <isscript>
    var PdictDebug = require('~/cartridge/scripts/util/PdictDebug');
    PdictDebug.debug(pdict);
    var ObjectDebug = require('*/cartridge/scripts/util/ObjectDebug');
    ObjectDebug.debug(pdict, 'pdict');
    </isscript>
  4. jlbruno renamed this gist Feb 4, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions PdictDebug.js → ObjectDebug.js
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,8 @@
    * @param pdict Pipeline dictionary
    *
    **/
    function debug(pdict) {
    var temp = pdict; // put breakpoint here
    function debug(object) {
    var temp = object; // put breakpoint here
    return temp;
    }

  5. jlbruno created this gist Feb 4, 2022.
    16 changes: 16 additions & 0 deletions PdictDebug.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    'use strict';

    /**
    * A place to debug what's in pdict
    *
    * @param pdict Pipeline dictionary
    *
    **/
    function debug(pdict) {
    var temp = pdict; // put breakpoint here
    return temp;
    }



    module.exports.debug = debug;
    4 changes: 4 additions & 0 deletions test.isml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    <isscript>
    var PdictDebug = require('~/cartridge/scripts/util/PdictDebug');
    PdictDebug.debug(pdict);
    </isscript>