Class: DeRjs::Rewriter::Erbify

Inherits:
Parser::Rewriter
  • Object
show all
Defined in:
lib/de_rjs/rewriter/erbify.rb

Defined Under Namespace

Classes: MustTranslateManually

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



6
7
8
# File 'lib/de_rjs/rewriter/erbify.rb', line 6

def on_send(node)
  rewrite_page_calls(node)
end

#rewrite_page_calls(node) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/de_rjs/rewriter/erbify.rb', line 10

def rewrite_page_calls(node)
  receiver_node, method_name, *arg_nodes = *node

  if receiver_node.to_a.last == :page
    case method_name
    when :replace_html, :replace
      rewrite_replace_html(receiver_node, method_name, *arg_nodes)

    when :insert_html
      rewrite_insert_html(receiver_node, method_name, *arg_nodes)

    when :redirect_to
      rewrite_redirect_to(receiver_node, method_name, *arg_nodes)

    when :visual_effect
      rewrite_visual_effect(receiver_node, method_name, *arg_nodes)

    when :[]
      rewrite_square_bracket(receiver_node, method_name, *arg_nodes)

    else
      # All others such as :
      # page.alert
      # page.hide
      # page.redirect_to
      # page.reload
      # page.replace
      # page.select
      # page.show
      rewrite_all_args(receiver_node, method_name, *arg_nodes)
    end
  end

  # page[:html_id].some_method
  if receiver_node.to_a.first.to_a.last == :page && receiver_node.to_a[1] == :[]
    rewrite_square_bracket(*receiver_node.to_a)
    rewrite_square_replace(receiver_node, method_name, *arg_nodes) if [:replace, :replace_html].include?(method_name)
  end
end