Sha256: 5d9fce771d9242964250058c1fe052b632a01e44ab4b83a62ac5bb9ca7eaed33

Contents?: true

Size: 1.18 KB

Versions: 26

Compression:

Stored size: 1.18 KB

Contents

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

26 entries across 26 versions & 1 rubygems

Version Path
ruby2js-2.1.24 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.23 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.22 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.21 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.20 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.19 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.18 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.17 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.16 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.15 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.14 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.13 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.12 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.11 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.10 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.9 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.8 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.7 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.6 lib/ruby2js/filter/angular-route.rb
ruby2js-2.1.5 lib/ruby2js/filter/angular-route.rb