Search code examples
pluginsdocpad

Docpad Plugin Contactify Issue: docpad is not defined


I am trying to get the Docpad Contactify Plugin to work as expected, but I am not having any luck and I was hoping to get some help here, if at all possible.

So the plugin in question is https://github.com/thaume/docpad-plugin-contactify and it doesn't install properly via nom, so I added it via /plugins/. Anyhow, when running it clean, I get a 'ReferenceError: docpad is not defined' caused by this line...

    config = docpad.getConfig().plugins.contactify

so I changed it to...

config = @getConfig()

however then I receive the following error...

TypeError: Object function ContactifyPlugin() {
    return ContactifyPlugin.__super__.constructor.apply(this, arguments);
  } has no method 'getConfig'

Just looking for a way to send mail and this is the only Docpad plugin that does it, so I am kinda desperate to get it operational. Any input at all would be appreciated!


Solution

  • There appears to be an issue with contactify and the docpad version. I had it running under docpad 6.46 and everything seemed ok. When I updated to 6.66, contactify broke. There seems to be two relevant changes. The context of the plugin seems to have changed so that docpad is no longer directly available in the function(BasePlugin) context and docpad itself no longer has a getConfig method (instead you need to access the config property directly).

    Moving the offending code inside the serverExtend method seems to fix the context issue where docpad itself is a property of the plugin this context.

        ContactifyPlugin.prototype.serverExtend = function(opts) {
    
                docpad = this.docpad;
                config = docpad.config.plugins.contactify;
                smtp = nodemailer.createTransport('SMTP', config.transport);
                var server;
                server = opts.server;
                ...
    

    Coffeescript version:

            serverExtend: (opts) ->
                    docpad = @docpad                    
                    config = docpad.config.plugins.contactify
                    smtp = nodemailer.createTransport('SMTP', config.transport)  
    
                    {server} = opts
                    ...