Guest User

Untitled

a guest
Mar 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. //helpers.js
  2. module.exports = {
  3. truncate: (str, len) => {
  4. //code
  5. return str;
  6. },
  7.  
  8. stripTags: input => input.replace(/<(?:.|n)*?>/gm, ''),
  9.  
  10. formatDate: (date, format) => moment(date).format(format),
  11.  
  12. select: function (selected, options) {
  13. return options.fn(this).replace(new RegExp(` value="${selected}"`), '$&selected="selected"').replace(new RegExp(`>${selected}</option>`), 'selected="selected"$&');
  14. },
  15. };
  16.  
  17. //sets application locals so I can call these functions from a pug template
  18. app.locals = {
  19. truncate,
  20. stripTags,
  21. formatDate,
  22. select,
  23. };
  24.  
  25. #{formatDate(story.date, 'MMMM Do YYYY')}
  26.  
  27. select(name='status' id='status')
  28. #{select(story.status)}
  29. option(value='Public' selected) Public
  30. option(value='Private') Private
  31. option(value='Unpublished') Unpublished
  32. label(for='status') Status
  33.  
  34. Cannot read property 'fn' of undefined
  35.  
  36. <select name ='status' id='status'>
  37. {{#select story.status}}
  38. <option value='Public' selected> Public </option
  39. <option value='Private'> Private </option
  40. <option value='Unpublished'> Unpublished </option>
  41. {{#/select}}
  42.  
  43. Warning
  44. Filters are rendered at compile time. This makes them fast, but it also means that they cannot support dynamic content or options.
  45.  
  46. By default, compilation in the browser does not have access to JSTransformer-based filters, unless the JSTransformer modules are explicitly packed and made available through a CommonJS platform (such as Browserify or Webpack). In fact, the page you are reading right now uses Browserify to make the filters available in the browser.
  47.  
  48. Templates pre-compiled on the server do not have this limitation.
Add Comment
Please, Sign In to add comment