Ruby scripting in the Webby "environment"

How to load Webby::Resources into memory.

As I mentioned in my previous post, I’m in the process of converting my blog from being a Rails app using Typo to being a static site generated by Webby.

I’ve found myself wanting to be able to write Ruby scripts with access to the Webby “environment” e.g. the @pages instance variable.

I couldn’t find any documentation about this, so with a bit of delving into the source code and a bit of experimentation, I came up with the following code. I thought I’d share it here in case it was of use to anyone else. And if anyone knows a better way of doing it, please let me know.

Note that I think this script has to run at the top level of the project.

require 'webby'

# load Sitefile, setup load path
main =
main.init([]) 'webby'

# load helpers
include BlogHelper
include UrlHelper

# load pages, layouts, etc.
builder =
@pages = Webby::Resources.pages