Sha256: c65d574fc1103a0ed41f647d811a92489c076a4a923d9d20896554fb6850b292
Contents?: true
Size: 1.2 KB
Versions: 40
Compression:
Stored size: 1.2 KB
Contents
require 'parser/current' require 'ruby2js/filter/angularrb' module Ruby2JS module Filter module AngularRoute include SEXP # 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"})) 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 end DEFAULTS.push AngularRoute end end
Version data entries
40 entries across 40 versions & 1 rubygems