docpad / docpad-skeleton-bootstrap

Twitter Bootstrap skeleton for DocPad. Simple and flexible HTML, CSS, and Javascript for popular user interface components and interactions.
47 stars 34 forks source link

Cannot add a new helper function to docpad.coffee #18

Open jasonlally opened 10 years ago

jasonlally commented 10 years ago

It seems whenever I try to edit the docpad.coffee file to add another helper, I get an error when issuing docpad run. The new helper function is below getPreparedKeywords, called contentTrim. I do not call contentTrim in any of my templates yet. Here's my updated docpad.cofeee file:

# The DocPad Configuration File
# It is simply a CoffeeScript Object which is parsed by CSON
docpadConfig = {

    # =================================
    # Template Data
    # These are variables that will be accessible via our templates
    # To access one of these within our templates, refer to the FAQ: https://github.com/bevry/docpad/wiki/FAQ

    templateData:

        # Specify some site properties
        site:
            # The production url of our website
            url: "http://website.com"

            # Here are some old site urls that you would like to redirect from
            oldUrls: [
                'www.website.com'
                'website.herokuapp.com'
            ]

            # The default title of our website
            title: "Your Website"

            # The website description (for SEO)
            description: """
                When your website appears in search results in say Google, the text here will be shown underneath your website's title.
                """

            # The website keywords (for SEO) separated by commas
            keywords: """
                place, your, website, keywoards, here, keep, them, related, to, the, content, of, your, website
                """

            # The website author's name
            author: "Your Name"

            # The website author's email
            email: "your@email.com"

            # Styles
            styles: [
                "/styles/twitter-bootstrap.css"
                "/styles/style.css"
            ]

            # Scripts
            scripts: [
                "//cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"
                "//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"
                "/vendor/twitter-bootstrap/dist/js/bootstrap.min.js"
                "/scripts/script.js"
            ]
        # -----------------------------
        # Helper Functions

        # Get the prepared site/document title
        # Often we would like to specify particular formatting to our page's title
        # we can apply that formatting here
        getPreparedTitle: ->
            # if we have a document title, then we should use that and suffix the site's title onto it
            if @document.title
                "#{@document.title} | #{@site.title}"
            # if our document does not have it's own title, then we should just use the site's title
            else
                @site.title

        # Get the prepared site/document description
        getPreparedDescription: ->
            # if we have a document description, then we should use that, otherwise use the site's description
            @document.description or @site.description

        # Get the prepared site/document keywords
        getPreparedKeywords: ->
            # Merge the document keywords with the site keywords
            @site.keywords.concat(@document.keywords or '').join(', ')

        contentTrim: (str) ->
            if str.length > 200 then str.slice(0, 197) + '...' else str

    # =================================
    # Collections
    # These are special collections that our website makes available to us

    collections:
        pages: (database) ->
            database.findAllLive({pageOrder: $exists: true}, [pageOrder:1,title:1])

        posts: (database) ->
            database.findAllLive({tags:$has:'post'}, [date:-1])

    # =================================
    # Plugins

    plugins:
        downloader:
            downloads: [
                {
                    name: 'Twitter Bootstrap'
                    path: 'src/files/vendor/twitter-bootstrap'
                    url: 'https://codeload.github.com/twbs/bootstrap/tar.gz/master'
                    tarExtractClean: true
                }
            ]

    # =================================
    # DocPad Events

    # Here we can define handlers for events that DocPad fires
    # You can find a full listing of events on the DocPad Wiki
    events:

        # Server Extend
        # Used to add our own custom routes to the server before the docpad routes are added
        serverExtend: (opts) ->
            # Extract the server from the options
            {server} = opts
            docpad = @docpad

            # As we are now running in an event,
            # ensure we are using the latest copy of the docpad configuraiton
            # and fetch our urls from it
            latestConfig = docpad.getConfig()
            oldUrls = latestConfig.templateData.site.oldUrls or []
            newUrl = latestConfig.templateData.site.url

            # Redirect any requests accessing one of our sites oldUrls to the new site url
            server.use (req,res,next) ->
                if req.headers.host in oldUrls
                    res.redirect(newUrl+req.url, 301)
                else
                    next()
}

# Export our DocPad Configuration
module.exports = docpadConfig
error: Something went wrong with the action
error: An error occured:
TypeError: string is not a function
    at Object.docpadConfig.templateData.getPreparedKeywords (/Users/jasonlallymoci/Documents/workspace/twitter-bootstrap.docpad/docpad.coffee:28:82)
    at Object.eval (eval at <anonymous> (/Users/jasonlallymoci/Documents/workspace/twitter-bootstrap.docpad/node_modules/docpad-plugin-eco/node_modules/eco/lib/compiler.js:19:12), <anonymous>:53:34)
    at Object.eval (eval at <anonymous> (/Users/jasonlallymoci/Documents/workspace/twitter-bootstrap.docpad/node_modules/docpad-plugin-eco/node_modules/eco/lib/compiler.js:19:12), <anonymous>:103:8)
    at eval (eval at <anonymous> (/Users/jasonlallymoci/Documents/workspace/twitter-bootstrap.docpad/node_modules/docpad-plugin-eco/node_modules/eco/lib/compiler.js:19:12), <anonymous>:105:6)
    at Function.eco.render (/Users/jasonlallymoci/Documents/workspace/twitter-bootstrap.docpad/node_modules/docpad-plugin-eco/node_modules/eco/lib/index.js:26:25)
    at EcoPlugin.render (/Users/jasonlallymoci/Documents/workspace/twitter-bootstrap.docpad/node_modules/docpad-plugin-eco/out/eco.plugin.js:22:35)
    at ambi (/Users/jasonlallymoci/Documents/workspace/twitter-bootstrap.docpad/node_modules/docpad/node_modules/ambi/out/lib/ambi.js:25:27)
    at Task.<anonymous> (/Users/jasonlallymoci/Documents/workspace/twitter-bootstrap.docpad/node_modules/docpad/node_modules/event-emitter-grouped/out/lib/event-emitter-grouped.js:38:23)
    at ambi (/Users/jasonlallymoci/Documents/workspace/twitter-bootstrap.docpad/node_modules/docpad/node_modules/ambi/out/lib/ambi.js:23:18)
    at fire (/Users/jasonlallymoci/Documents/workspace/twitter-bootstrap.docpad/node_modules/docpad/node_modules/taskgroup/out/lib/taskgroup.js:159:23)
    at b (domain.js:183:18)
    at Domain.run (domain.js:123:23)
    at Task.fire (/Users/jasonlallymoci/Documents/workspace/twitter-bootstrap.docpad/node_modules/docpad/node_modules/taskgroup/out/lib/taskgroup.js:166:25)
    at processImmediate [as _immediateCallback] (timers.js:330:15)
balupton commented 10 years ago

Strange, is your repo's source up somewhere?

jasonlally commented 10 years ago

The full source is here:

https://github.com/jasonlally/jasonlally.github.io/tree/source

I'm running node 0.10.22, npm 1.3.15, docpad 6.57.1

jasonlally commented 10 years ago

I think I found a way to fix my problem. I don't know why exactly, but I was using WebStorm to work on my site and I think it was doing something strange to my whitespace. Anyway, it seems when I edit my docpad.coffee file in Sublime Text, I'm fine.

jasonlally commented 10 years ago

Nevermind, that's not the case. Hmmmm...this is really weird, I can't figure out why sometimes it wants to compile correctly and other times it doesn't.

lucor commented 10 years ago

Check for tabs in your code. You may try to use auto Reformat Code and re-indent manually if needed.

goboca commented 9 years ago

Exactly same problem here using Brackets 1.3 on Windows. Using Notepad++ everything is just fine.