Module: Ruby2JS::Filter::AngularRoute

Includes:
SEXP
Defined in:
lib/ruby2js/filter/angular-route.rb

Instance Method Summary collapse

Methods included from SEXP

#s

Instance Method Details

#on_case(node) ⇒ Object

input:

case $routeProvider
when '/path'
  templateUrl = 'partials/path.html'
else
  redirectTo '/path'
end

output:

AppName.config(["$routeProvider", function($routeProvider) {
  $routeProvider.when("/path", {templateUrl: 'partials/path.html'}).
  otherwise({redirectTo: "/path"}))


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby2js/filter/angular-route.rb', line 22

def on_case(node)
  rp = :$routeProvider
  return super unless @ngApp and node.children.first == s(:gvar, rp)
  @ngAppUses << :ngRoute
  code = s(:lvar, rp)

  node.children[1..-2].each do |child|
    code = s(:sendw, code, :when, child.children.first,
      AngularRB.hash(child.children[1..-1]))
  end

  if node.children.last
    code = s(:sendw, code, :otherwise, 
      AngularRB.hash(node.children[-1..-1]))
  end

  s(:send, @ngApp, :config, s(:array, s(:str, rp.to_s), s(:block, 
      s(:send, nil, :proc), s(:args, s(:arg, rp)), code)))
end