class Kumogata2::Plugin::Ruby::Context
Constants
- IGNORE_METHODS
Public Class Methods
new(options)
click to toggle source
# File lib/kumogata2/plugin/ruby/context.rb, line 4 def initialize(options) @options = options end
Public Instance Methods
post(&block)
click to toggle source
# File lib/kumogata2/plugin/ruby/context.rb, line 37 def post(&block) @_post = block end
template(&block)
click to toggle source
# File lib/kumogata2/plugin/ruby/context.rb, line 8 def template(&block) key_converter = proc do |k| k.to_s. gsub('_____', '-'). gsub('____', '.'). gsub('___', ':'). gsub('__', '::') end value_converter = proc do |v| case v when Hash, Array v else v.to_s end end @_template = Dslh.eval({ key_conv: key_converter, value_conv: value_converter, scope_hook: proc {|scope| define_template_func(scope, @options.path_or_url) }, filename: @options.path_or_url, ignore_methods: IGNORE_METHODS, }, &block) end
Private Instance Methods
define_template_func(scope, path_or_url)
click to toggle source
# File lib/kumogata2/plugin/ruby/context.rb, line 43 def define_template_func(scope, path_or_url) scope.instance_eval(<<-EOS) def _include(file, args = {}) path = file.dup unless path =~ %r|\\A/| or path =~ %r|\\A\\w+://| path = File.expand_path(File.join(File.dirname(#{path_or_url.inspect}), path)) end open(path) {|f| instance_eval(f.read) } end def _path(path, value = nil, &block) if block value = Dslh::ScopeBlock.nest(binding, 'block') end @__hash__[path] = value end EOS end