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

Version Path
ruby2js-2.0.17 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.16 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.15 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.14 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.13 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.12 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.11 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.10 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.9 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.8 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.7 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.6 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.5 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.4 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.3 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.2 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.1 lib/ruby2js/filter/angular-route.rb
ruby2js-2.0.0 lib/ruby2js/filter/angular-route.rb
ruby2js-1.15.1 lib/ruby2js/filter/angular-route.rb
ruby2js-1.15.0 lib/ruby2js/filter/angular-route.rb