Created
March 17, 2009 07:12
-
-
Save deepthawtz/80379 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ==== Parameters | |
| # io<#path>:: An IO containing the full path of the template. | |
| # name<String>:: The name of the method that will be created. | |
| # locals<Array[Symbol]>:: A list of locals to assign from the args passed into the compiled template. | |
| # mod<Module>:: The module that the compiled method will be placed into. | |
| # | |
| # :api: private | |
| def self.compile_template(io, name, locals, mod) | |
| template = ::Erubis::BlockAwareEruby.new(io.read) | |
| _old_verbose, $VERBOSE = $VERBOSE, nil | |
| assigns = locals.inject([]) do |assigns, local| | |
| assigns << "#{local} = _locals[#{local.inspect}]" | |
| end.join(";") | |
| code = "def #{name}(_locals={}); #{assigns}; #{template.src}; end" | |
| mod.module_eval code, File.expand_path(io.path) | |
| $VERBOSE = _old_verbose | |
| name | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment