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-1.14.1 lib/ruby2js/filter/angular-route.rb
ruby2js-1.14.0 lib/ruby2js/filter/angular-route.rb
ruby2js-1.13.1 lib/ruby2js/filter/angular-route.rb
ruby2js-1.13.0 lib/ruby2js/filter/angular-route.rb
ruby2js-1.12.2 lib/ruby2js/filter/angular-route.rb
ruby2js-1.12.1 lib/ruby2js/filter/angular-route.rb
ruby2js-1.12.0 lib/ruby2js/filter/angular-route.rb
ruby2js-1.11.1 lib/ruby2js/filter/angular-route.rb
ruby2js-1.11.0 lib/ruby2js/filter/angular-route.rb
ruby2js-1.10.0 lib/ruby2js/filter/angular-route.rb
ruby2js-1.9.3 lib/ruby2js/filter/angular-route.rb
ruby2js-1.9.2 lib/ruby2js/filter/angular-route.rb
ruby2js-1.9.1 lib/ruby2js/filter/angular-route.rb
ruby2js-1.9.0 lib/ruby2js/filter/angular-route.rb
ruby2js-1.8.0 lib/ruby2js/filter/angular-route.rb
ruby2js-1.7.0 lib/ruby2js/filter/angular-route.rb
ruby2js-1.6.0 lib/ruby2js/filter/angular-route.rb
ruby2js-1.5.0 lib/ruby2js/filter/angular-route.rb
ruby2js-1.4.0 lib/ruby2js/filter/angular-route.rb
ruby2js-1.3.0 lib/ruby2js/filter/angular-route.rb