Class: Weaver::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/weaver/element_types/action.rb

Instance Method Summary collapse

Constructor Details

#initialize(page, anchors, &block) ⇒ Action

Returns a new instance of Action.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/weaver/element_types/action.rb', line 5

def initialize(page, anchors, &block)
  @page = page
  @anchors = anchors

  actionsArray = @anchors['action']

  @anchors['action'] = [] unless @anchors['action']

  actionsArray = @anchors['action']

  @actionName = "action#{actionsArray.length}"
  actionsArray << @actionName

  @code = ''

  instance_eval(&block)
end

Instance Method Details

#generateObject



27
28
29
30
31
32
33
34
# File 'lib/weaver/element_types/action.rb', line 27

def generate
  # puts @code
  <<~FUNCTION
    function #{@actionName}(caller, data) {
    	#{@code}
    }
  FUNCTION
end

#nameObject



36
37
38
# File 'lib/weaver/element_types/action.rb', line 36

def name
  @actionName
end

#script(code) ⇒ Object



23
24
25
# File 'lib/weaver/element_types/action.rb', line 23

def script(code)
  @code = code
end