Class: Dominate::Scope

Inherits:
Struct
  • Object
show all
Defined in:
lib/dominate/scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config

Returns:

  • (Object)

    the current value of config



2
3
4
# File 'lib/dominate/scope.rb', line 2

def config
  @config
end

#instanceObject

Returns the value of attribute instance

Returns:

  • (Object)

    the current value of instance



2
3
4
# File 'lib/dominate/scope.rb', line 2

def instance
  @instance
end

#root_docObject

Returns the value of attribute root_doc

Returns:

  • (Object)

    the current value of root_doc



2
3
4
# File 'lib/dominate/scope.rb', line 2

def root_doc
  @root_doc
end

Instance Method Details

#apply(data, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/dominate/scope.rb', line 4

def apply data, &block
  root_doc.each do |doc|
    if data.is_a? Array
      doc = apply_list doc, data, &block
    else
      doc = apply_data doc, data, &block
    end
  end

  root_doc
end

#apply_instanceObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dominate/scope.rb', line 16

def apply_instance
  root_doc.traverse do |x|
    if defined?(x.attributes) && x.attributes.keys.include?('data-instance')
      method  = x.attr 'data-instance'

      begin
        x.inner_html = instance.instance_eval method
      rescue
        x.inner_html = ''
      end
    end
  end

  root_doc
end