How to use the handlebars/handlebars.runtime.registerHelper function in handlebars

To help you get started, we’ve selected a few handlebars examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MeoMix / StreamusWebsite / src / common / shim / handlebars.helpers.shim.js View on Github external
// Give Handlebars additional functionality in the form of helper methods.
import Handlebars from 'handlebars/handlebars.runtime';

// Provide handlebars with the ability to look up a model's attributes from within a template.
Handlebars.registerHelper('get', (model, attribute) => {
  return model.get(attribute);
});

Handlebars.registerHelper('ternary', (test, yes, no) => {
  return test ? yes : no;
});
github Leeft / Star-Citizen-WebGL-Map / src / scmap / ui / helpers.js View on Github external
}

  str = '<a data-toggle-next="next" data-title="' + UI.htmlEscape( safeTitle ) +
    '" href="#"><i class="fa fa-fw fa-lg ' + icon + '">' +
    '</i>' + title + '</a>\n` + '         <div hidden="" class="ui-section">';

  if ( 'fn' in options ) {
    str += options.fn( this );
  }

  str += '</div>';
  sectionLevel -= 1;
  return new Handlebars.SafeString( str );
});

Handlebars.registerHelper( 'tabHeader', function( title ) {
  return new Handlebars.SafeString( '<h1 class="padleft">' + title + '</h1>' );
});

/* title: shown to user, name: internal name, icon: font awesome icon class */
Handlebars.registerHelper( 'jQueryUiTab', function( title, name, icon, options ) {
  let hidden = 'style="display: none;"';
  let attrs = [], str = '';
  let $menuItem;
  let id = 'sc-map-ui-tab-' + UI.makeSafeForCSS( name );

  //for ( let prop in options.hash ) {
  //   attrs.push( prop + '="' + options.hash[prop] + '"' );
  //}

  $menuItem = $(
    '<li>' +</li>
github Leeft / Star-Citizen-WebGL-Map / src / scmap / ui / helpers.js View on Github external
if ( 'fn' in options ) {
    str += options.fn( this );
  }

  str += '';
  sectionLevel -= 1;
  return new Handlebars.SafeString( str );
});

Handlebars.registerHelper( 'tabHeader', function( title ) {
  return new Handlebars.SafeString( '<h1 class="padleft">' + title + '</h1>' );
});

/* title: shown to user, name: internal name, icon: font awesome icon class */
Handlebars.registerHelper( 'jQueryUiTab', function( title, name, icon, options ) {
  let hidden = 'style="display: none;"';
  let attrs = [], str = '';
  let $menuItem;
  let id = 'sc-map-ui-tab-' + UI.makeSafeForCSS( name );

  //for ( let prop in options.hash ) {
  //   attrs.push( prop + '="' + options.hash[prop] + '"' );
  //}

  $menuItem = $(
    '<li>' +
    '<a href="#' + UI.htmlEscape( id ) + '" data-tab="' + UI.htmlEscape( name ) + '" title="' + UI.htmlEscape( title ) + '">' +
    '<i class="fa fa-fw fa-2x ' + UI.htmlEscape( icon ) + '"></i>' +
    '</a>' +
    '</li>'
  );
github Leeft / Star-Citizen-WebGL-Map / src / scmap / ui / helpers.js View on Github external
const hours   = Math.floor( sec_num / 3600 );

  let minutes = Math.floor( ( sec_num - ( hours * 3600 ) ) / 60 );

  if ( minutes &lt; 10 ) {
    minutes = '0' + minutes;
  }

  return new Handlebars.SafeString( `${ hours }:${ minutes }` );
});

Handlebars.registerHelper( 'plusOne', function( number ) {
  return new Handlebars.SafeString( number + 1 );
});

Handlebars.registerHelper( 'minusOne', function( number ) {
  return new Handlebars.SafeString( number - 1 );
});

Handlebars.registerHelper( 'checked', function( isChecked ) {
  return new Handlebars.SafeString( isChecked ? 'checked' : '' );
});

Handlebars.registerHelper( 'checkboxOption', function( id, defaultChecked, title, description, options ) {
  let attrs = [];
  let checked = '';

  if ( defaultChecked ) {
    checked = 'checked';
  }

  for ( let prop in options.hash ) {
github Leeft / Star-Citizen-WebGL-Map / src / scmap / ui / helpers.js View on Github external
return new Handlebars.SafeString( `${ hours }:${ minutes }` );
});

Handlebars.registerHelper( 'plusOne', function( number ) {
  return new Handlebars.SafeString( number + 1 );
});

Handlebars.registerHelper( 'minusOne', function( number ) {
  return new Handlebars.SafeString( number - 1 );
});

Handlebars.registerHelper( 'checked', function( isChecked ) {
  return new Handlebars.SafeString( isChecked ? 'checked' : '' );
});

Handlebars.registerHelper( 'checkboxOption', function( id, defaultChecked, title, description, options ) {
  let attrs = [];
  let checked = '';

  if ( defaultChecked ) {
    checked = 'checked';
  }

  for ( let prop in options.hash ) {
    if ( prop === 'icon' ) {
      title = `${ title } <i class="fa fa-lg fa-fw ${ options.hash[ prop ] }'"></i>`;
    } else {
      attrs.push( prop + '="' + UI.htmlEscape( options.hash[ prop ] ) + '"' );
    }
  }

  return new Handlebars.SafeString(
github Leeft / Star-Citizen-WebGL-Map / src / scmap / ui / helpers.js View on Github external
str += options.fn( this );
  }
  str += '';

  UI.Tabs.push({ id: '#' + id, name: name, index: tabCounter++ });

  return new Handlebars.SafeString( str );
});

Handlebars.registerHelper( 'bigButton', function( id, cssClass, title ) {
  return new Handlebars.SafeString(
    `<button id="${ id }" class="big-button"><i class="fa ${ cssClass } fa-fw fa-lg"></i>${ title }</button><br>`
  );
});

Handlebars.registerHelper( 'commoditiesList', function( commodities ) {
  if ( !commodities.length ) {
    return new Handlebars.SafeString( '—' );
  }

  return new Handlebars.SafeString(
    $.map( commodities, function( elem, i ) {
      const commodity = SCMAP.getCommodityById( elem );
      return ( commodity ) ? commodity.name : '???';
    }).join( ', ' )
  );
});

Handlebars.registerHelper( 'markdown', function( markdownText ) {
  return new Handlebars.SafeString( markdown.markdown.toHTML( markdownText || '' ) );
});
github Leeft / Star-Citizen-WebGL-Map / src / scmap / ui / helpers.js View on Github external
Handlebars.registerHelper( 'systemLink', function( system, options ) {
  let noIcons = false, noTarget = false;
  if ( 'noIcons' in options.hash ) {
    noIcons = ( options.hash.noIcons ) ? true : false;
  }
  if ( 'noTarget' in options.hash ) {
    noTarget = ( options.hash.noTarget ) ? true : false;
  }
  if ( ! ( system instanceof StarSystem ) ) {
    return '';
  }
  return new Handlebars.SafeString( createInfoLink( system, noIcons, noTarget ).outerHtml() );
});

Handlebars.registerHelper( 'routeNavLinks', function( prev, next, options ) {
  let str = '', $elem;

  if ( !prev &amp;&amp; !next ) {
    return new Handlebars.SafeString( '' );
  }

  if ( prev instanceof StarSystem ) {
    $elem = $( '<a></a>' );
    if ( ( prev.faction instanceof Faction ) &amp;&amp; ( prev.faction.color instanceof Color ) ) {
      $elem.css( 'color', prev.faction.color.getStyle() );
    }
    $elem.addClass( 'system-link' );
    $elem.attr( 'data-goto', 'system' );
    $elem.attr( 'data-system', prev.id );
    $elem.attr( 'href', '#system=' + encodeURIComponent( prev.name ) );
    $elem.attr( 'title', 'Previous jump, coming from ' + prev.name + ' (' + prev.faction.name + ' territory)' );
github Leeft / Star-Citizen-WebGL-Map / src / scmap / ui / helpers.js View on Github external
$.map( commodities, function( elem, i ) {
      const commodity = SCMAP.getCommodityById( elem );
      return ( commodity ) ? commodity.name : '???';
    }).join( ', ' )
  );
});

Handlebars.registerHelper( 'markdown', function( markdownText ) {
  return new Handlebars.SafeString( markdown.markdown.toHTML( markdownText || '' ) );
});

Handlebars.registerHelper( 'colourGetStyle', function( colour ) {
  return new Handlebars.SafeString( colour.getStyle() );
});

Handlebars.registerHelper( 'systemLink', function( system, options ) {
  let noIcons = false, noTarget = false;
  if ( 'noIcons' in options.hash ) {
    noIcons = ( options.hash.noIcons ) ? true : false;
  }
  if ( 'noTarget' in options.hash ) {
    noTarget = ( options.hash.noTarget ) ? true : false;
  }
  if ( ! ( system instanceof StarSystem ) ) {
    return '';
  }
  return new Handlebars.SafeString( createInfoLink( system, noIcons, noTarget ).outerHtml() );
});

Handlebars.registerHelper( 'routeNavLinks', function( prev, next, options ) {
  let str = '', $elem;
github Leeft / Star-Citizen-WebGL-Map / src / scmap / ui / helpers.js View on Github external
import Faction from '../faction';
import UI from '../ui';
import { hasSessionStorage } from '../../helpers/functions';
import { Color } from '../../scmap/three';
import { createInfoLink } from '../ui/star-system';

import Handlebars from 'handlebars/handlebars.runtime';
import markdown from 'markdown';
import $ from 'jquery';

let sectionLevel = 1;
let tabCounter = 0;

let storage = {};

Handlebars.registerHelper( 'distanceLY', function( distance ) {
  if ( ! distance ) {
    return new Handlebars.SafeString('');
  }

  return new Handlebars.SafeString( `${ distance.toFixed(1) } ly` );
});

Handlebars.registerHelper( 'uiSection', function( title, shouldOpen, options ) {
  let opened = ( shouldOpen ) ? true : false;
  let icon = 'fa-caret-right';
  let hidden = 'style="display: none;"';
  let attrs = [], str;
  let oldLevel = sectionLevel++;
  let safeTitle = 'panel' + title.replace( /[^\w]/g, '' );

  if ( hasSessionStorage() ) {
github Leeft / Star-Citizen-WebGL-Map / src / scmap / ui / helpers.js View on Github external
return new Handlebars.SafeString('');
  }

  const sec_num = parseInt( duration, 10 );
  const hours   = Math.floor( sec_num / 3600 );

  let minutes = Math.floor( ( sec_num - ( hours * 3600 ) ) / 60 );

  if ( minutes &lt; 10 ) {
    minutes = '0' + minutes;
  }

  return new Handlebars.SafeString( `${ hours }:${ minutes }` );
});

Handlebars.registerHelper( 'plusOne', function( number ) {
  return new Handlebars.SafeString( number + 1 );
});

Handlebars.registerHelper( 'minusOne', function( number ) {
  return new Handlebars.SafeString( number - 1 );
});

Handlebars.registerHelper( 'checked', function( isChecked ) {
  return new Handlebars.SafeString( isChecked ? 'checked' : '' );
});

Handlebars.registerHelper( 'checkboxOption', function( id, defaultChecked, title, description, options ) {
  let attrs = [];
  let checked = '';

  if ( defaultChecked ) {