Class: Kumogata2::Plugin::Ruby::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/kumogata2/plugin/ruby/context.rb

Constant Summary collapse

IGNORE_METHODS =
[:system]

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Context

Returns a new instance of Context.



4
5
6
# File 'lib/kumogata2/plugin/ruby/context.rb', line 4

def initialize(options)
  @options = options
end

Instance Method Details

#post(&block) ⇒ Object



35
36
37
# File 'lib/kumogata2/plugin/ruby/context.rb', line 35

def post(&block)
  @_post = block
end

#template(&block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kumogata2/plugin/ruby/context.rb', line 8

def template(&block)
  key_converter = proc do |key|
    key = key.to_s
    key.gsub!('__', '::') unless @options.skip_replace_underscore?
    key
  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