You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.6 KiB

  1. // Generated by CoffeeScript 1.4.0
  2. var __hasProp = {}.hasOwnProperty,
  3. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  4. module.exports = function(BasePlugin) {
  5. var JadePlugin;
  6. return JadePlugin = (function(_super) {
  7. __extends(JadePlugin, _super);
  8. JadePlugin.prototype.name = 'jade';
  9. JadePlugin.prototype.config = {
  10. jadeOptions: {
  11. pretty: false
  12. },
  13. environments: {
  14. development: {
  15. jadeOptions: {
  16. pretty: true
  17. }
  18. }
  19. }
  20. };
  21. function JadePlugin() {
  22. JadePlugin.__super__.constructor.apply(this, arguments);
  23. this.jade = require('jade');
  24. this;
  25. }
  26. JadePlugin.prototype.generateBefore = function() {
  27. var addTemplateDataAsFilter, filters, key, templateData, value;
  28. templateData = this.docpad.getTemplateData();
  29. filters = this.jade.filters;
  30. addTemplateDataAsFilter = function(key, value) {
  31. var _ref;
  32. return (_ref = filters[key]) != null ? _ref : filters[key] = function(str, opts) {
  33. var args;
  34. if (opts.args) {
  35. args = str.split(/\s*\n\s*/);
  36. return value.apply(templateData, args);
  37. } else {
  38. args = [str, opts];
  39. return value.apply(templateData, args);
  40. }
  41. };
  42. };
  43. for (key in templateData) {
  44. if (!__hasProp.call(templateData, key)) continue;
  45. value = templateData[key];
  46. if (Object.prototype.toString.call(value) === '[object Function]') {
  47. addTemplateDataAsFilter(key, value);
  48. }
  49. }
  50. return this;
  51. };
  52. JadePlugin.prototype.render = function(opts, next) {
  53. var config, file, inExtension, jadeOptions, key, templateData, value, _ref;
  54. inExtension = opts.inExtension, templateData = opts.templateData, file = opts.file;
  55. config = this.config;
  56. if (inExtension === 'jade') {
  57. jadeOptions = {
  58. filename: file.get('fullPath')
  59. };
  60. if (config.jadeOptions) {
  61. _ref = config.jadeOptions;
  62. for (key in _ref) {
  63. if (!__hasProp.call(_ref, key)) continue;
  64. value = _ref[key];
  65. jadeOptions[key] = value;
  66. }
  67. }
  68. try {
  69. opts.content = this.jade.compile(opts.content, jadeOptions)(templateData);
  70. } catch (err) {
  71. return next(err);
  72. }
  73. }
  74. return next();
  75. };
  76. return JadePlugin;
  77. })(BasePlugin);
  78. };