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.
# load Sitefile, setup load path main = Webby::Apps::Main.new main.init() main.app.init 'webby' main.app.load_rakefile
# load helpers include BlogHelper include UrlHelper
# load pages, layouts, etc. builder = Webby::Builder.new builder.load_files @pages = Webby::Resources.pages