kschiess/parslet — pull request #119 by karlentwistle (2014-11-25 11:25:51+00:00)
Title: Node Transformer data modules

Node interpreter now takes an optional data module. The optional data module can supply helper methods to parslet transformers. An example use case would be needing to make an external API call.

We're using a monkey patched version of Parslet at the moment because we need to reference external plugin dependancies. These look like https://github.com/alphagov/smart-answers/blob/master/lib/smartdown_plugins/animal-example-simple/build_time.rb In this example we use the return value of pokemon_regions to build an element using Parslet::Transform. In our DSL we have a notion of references to external 'build_time' functions. When the transformer is run the external 'build_time' functions are available and can return their output to then be be used to transform them into objects.

I made this pull request to hopefully demonstrate this behaviour to you and perhaps to make this behaviour part of Parslet. If you agree this is a sensible approach. If not we'd love some pointers on a better way to do this.