Class: AwesomeXmlDsl::Partial

Inherits:
Object
  • Object
show all
Defined in:
lib/awesome_xml_dsl/partial.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_name, context, options = {}) ⇒ Partial

Returns a new instance of Partial.



5
6
7
8
9
# File 'lib/awesome_xml_dsl/partial.rb', line 5

def initialize(file_name, context, options = {})
  @context = context
  @file_name = file_name
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



24
25
26
27
28
# File 'lib/awesome_xml_dsl/partial.rb', line 24

def method_missing(m, *args, &block)
  return @options[:locals][m] if @options[:locals]&.key?(m)

  @context.send(m, *args, &block)
end

Instance Method Details

#a(*args) ⇒ Object



15
16
17
# File 'lib/awesome_xml_dsl/partial.rb', line 15

def a(*args)
  @context.a(*args)
end

#evalObject



19
20
21
22
# File 'lib/awesome_xml_dsl/partial.rb', line 19

def eval
  contents = File.read @file_name
  instance_eval contents, @file_name
end

#tag(name, options = {}, &block) ⇒ Object



11
12
13
# File 'lib/awesome_xml_dsl/partial.rb', line 11

def tag(name, options = {}, &block)
  @context.tag name, options.deep_merge(@options), &block
end