js-routes 0.8.5 → 0.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +0 -1
- data/Readme.md +13 -3
- data/VERSION +1 -1
- data/js-routes.gemspec +2 -2
- data/lib/routes.js +34 -29
- data/spec/js_routes/rails_routes_compatibility_spec.rb +4 -0
- metadata +3 -3
    
        data/Rakefile
    CHANGED
    
    | @@ -13,7 +13,6 @@ require 'rake' | |
| 13 13 |  | 
| 14 14 | 
             
            require 'jeweler'
         | 
| 15 15 | 
             
            Jeweler::Tasks.new do |gem|
         | 
| 16 | 
            -
              # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
         | 
| 17 16 | 
             
              gem.name = "js-routes"
         | 
| 18 17 | 
             
              gem.homepage = "http://github.com/railsware/js-routes"
         | 
| 19 18 | 
             
              gem.license = "MIT"
         | 
    
        data/Readme.md
    CHANGED
    
    | @@ -20,7 +20,19 @@ Require js routes file in `application.js` or other bundle | |
| 20 20 | 
             
            */
         | 
| 21 21 | 
             
            ```
         | 
| 22 22 |  | 
| 23 | 
            -
             | 
| 23 | 
            +
            Also in order to flush asset pipeline cache sometimes you might need to run:
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            ``` sh
         | 
| 26 | 
            +
            rake tmp:cache:clear
         | 
| 27 | 
            +
            ```
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            This cache is not flushed on server restart in development environment. 
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            **Important:** If routes.js file is not updated after some configuration change you need to run this command again.
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            ### Advanced Setup
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            If you need to customize routes file create initializer, like `config/initializers/jsroutes.rb`:
         | 
| 24 36 |  | 
| 25 37 | 
             
            ``` ruby
         | 
| 26 38 | 
             
            JsRoutes.setup do |config|
         | 
| @@ -41,8 +53,6 @@ Available options: | |
| 41 53 | 
             
              * Example: `http://yourdomain.com`. This will cause route helpers to generate full path only. 
         | 
| 42 54 |  | 
| 43 55 |  | 
| 44 | 
            -
            ### Advanced Setup
         | 
| 45 | 
            -
             | 
| 46 56 | 
             
            You can generate routes files on the application side like this:
         | 
| 47 57 |  | 
| 48 58 | 
             
            ``` ruby
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.8. | 
| 1 | 
            +
            0.8.6
         | 
    
        data/js-routes.gemspec
    CHANGED
    
    | @@ -5,11 +5,11 @@ | |
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |s|
         | 
| 7 7 | 
             
              s.name = "js-routes"
         | 
| 8 | 
            -
              s.version = "0.8. | 
| 8 | 
            +
              s.version = "0.8.6"
         | 
| 9 9 |  | 
| 10 10 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 11 | 
             
              s.authors = ["Bogdan Gusiev"]
         | 
| 12 | 
            -
              s.date = "2013-01- | 
| 12 | 
            +
              s.date = "2013-01-24"
         | 
| 13 13 | 
             
              s.description = "Generates javascript file that defines all Rails named routes as javascript helpers"
         | 
| 14 14 | 
             
              s.email = "agresso@gmail.com"
         | 
| 15 15 | 
             
              s.extra_rdoc_files = [
         | 
    
        data/lib/routes.js
    CHANGED
    
    | @@ -41,7 +41,7 @@ | |
| 41 41 |  | 
| 42 42 | 
             
                clean_path: function(path) {
         | 
| 43 43 | 
             
                  path = path.split("://");
         | 
| 44 | 
            -
                  last_index = path.length - 1;
         | 
| 44 | 
            +
                  var last_index = path.length - 1;
         | 
| 45 45 | 
             
                  path[last_index] = path[last_index].replace(/\/+/g, "/").replace(/\/$/m, '');
         | 
| 46 46 | 
             
                  return path.join("://");
         | 
| 47 47 | 
             
                },
         | 
| @@ -65,9 +65,14 @@ | |
| 65 65 | 
             
                },
         | 
| 66 66 |  | 
| 67 67 | 
             
                path_identifier: function(object) {
         | 
| 68 | 
            -
                  if ( | 
| 69 | 
            -
             | 
| 68 | 
            +
                  if (object === 0) {
         | 
| 69 | 
            +
            	return '0';
         | 
| 70 70 | 
             
                  }
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                  if (! object) { // null, undefined, false or ''
         | 
| 73 | 
            +
            	return '';
         | 
| 74 | 
            +
                  }
         | 
| 75 | 
            +
             | 
| 71 76 | 
             
                  if (typeof(object) == "object") {
         | 
| 72 77 | 
             
                    var property = object.to_param || object.id || object;
         | 
| 73 78 | 
             
                    if (typeof(property) == "function") {
         | 
| @@ -109,7 +114,7 @@ | |
| 109 114 | 
             
                    throw new Error("Too many parameters provided for path");
         | 
| 110 115 | 
             
                  }
         | 
| 111 116 |  | 
| 112 | 
            -
                  parameters = this.prepare_parameters(required_parameters, args, opts);
         | 
| 117 | 
            +
                  var parameters = this.prepare_parameters(required_parameters, args, opts);
         | 
| 113 118 | 
             
                  // Array#indexOf is not supported by IE <= 8, so we use custom method
         | 
| 114 119 | 
             
                  if (Utils.smartIndexOf(optional_parts, 'format') !== -1) {
         | 
| 115 120 | 
             
                    this.set_default_format(parameters);
         | 
| @@ -127,23 +132,42 @@ | |
| 127 132 | 
             
                 * and parsed route binary tree.
         | 
| 128 133 | 
             
                 * Binary tree is serialized in the following way:
         | 
| 129 134 | 
             
                 * [node type, left node, right node ]
         | 
| 135 | 
            +
                 *
         | 
| 136 | 
            +
                 *@param  {Boolean} optional  Marks the currently visited branch as optional. If set to `true`, this method will not throw when encountering a missing parameter (used in recursive calls).
         | 
| 130 137 | 
             
                 */
         | 
| 131 | 
            -
                visit: function(route, options) {
         | 
| 138 | 
            +
                visit: function(route, options, optional) {
         | 
| 132 139 | 
             
                  var type = route[0];
         | 
| 133 140 | 
             
                  var left = route[1];
         | 
| 134 141 | 
             
                  var right = route[2];
         | 
| 135 142 | 
             
                  switch (type) {
         | 
| 136 143 | 
             
                    case NodeTypes.GROUP:
         | 
| 137 | 
            -
                      return this. | 
| 144 | 
            +
                      return this.visit(left, options, true)
         | 
| 138 145 | 
             
                    case NodeTypes.STAR:
         | 
| 139 | 
            -
                      return this. | 
| 146 | 
            +
                      return this.visit(left, options, true)
         | 
| 140 147 | 
             
                    case NodeTypes.CAT:
         | 
| 141 | 
            -
                       | 
| 148 | 
            +
                      var leftPart = this.visit(left, options, optional),
         | 
| 149 | 
            +
                          rightPart = this.visit(right, options, optional);
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                      if (optional && ! (leftPart && rightPart))
         | 
| 152 | 
            +
                        return '';
         | 
| 153 | 
            +
             | 
| 154 | 
            +
                      return leftPart + rightPart;
         | 
| 155 | 
            +
                    case NodeTypes.LITERAL:
         | 
| 156 | 
            +
                      return left;
         | 
| 157 | 
            +
                    case NodeTypes.SLASH:
         | 
| 158 | 
            +
                      return left;
         | 
| 159 | 
            +
                    case NodeTypes.DOT:
         | 
| 160 | 
            +
                      return left;
         | 
| 142 161 | 
             
                    case NodeTypes.SYMBOL:
         | 
| 143 162 | 
             
                      var value = options[left];
         | 
| 144 | 
            -
             | 
| 163 | 
            +
             | 
| 164 | 
            +
                      if (value || value === 0) {
         | 
| 145 165 | 
             
                        delete options[left];
         | 
| 146 | 
            -
                        return this.path_identifier(value); | 
| 166 | 
            +
                        return this.path_identifier(value);
         | 
| 167 | 
            +
                      }
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                      if (optional) {
         | 
| 170 | 
            +
                        return '';  // missing parameter
         | 
| 147 171 | 
             
                      } else {
         | 
| 148 172 | 
             
                        throw new ParameterMissing("Route parameter missing: " + left);
         | 
| 149 173 | 
             
                      }
         | 
| @@ -152,28 +176,9 @@ | |
| 152 176 | 
             
                     * Please send your PR if you do
         | 
| 153 177 | 
             
                     */
         | 
| 154 178 | 
             
                    //case NodeTypes.OR:
         | 
| 155 | 
            -
                    case NodeTypes.LITERAL:
         | 
| 156 | 
            -
                      return left;
         | 
| 157 | 
            -
                    case NodeTypes.SLASH:
         | 
| 158 | 
            -
                      return left;
         | 
| 159 | 
            -
                    case NodeTypes.DOT:
         | 
| 160 | 
            -
                      return left;
         | 
| 161 179 | 
             
                    default:
         | 
| 162 180 | 
             
                      throw new Error("Unknown Rails node type");
         | 
| 163 181 | 
             
                  }
         | 
| 164 | 
            -
                  
         | 
| 165 | 
            -
                },
         | 
| 166 | 
            -
             | 
| 167 | 
            -
                visit_group: function(left, options) {
         | 
| 168 | 
            -
                  try {
         | 
| 169 | 
            -
                    return this.visit(left, options);
         | 
| 170 | 
            -
                  } catch(e) {
         | 
| 171 | 
            -
                    if (e instanceof ParameterMissing) {
         | 
| 172 | 
            -
                      return "";
         | 
| 173 | 
            -
                    } else {
         | 
| 174 | 
            -
                      throw e;
         | 
| 175 | 
            -
                    }
         | 
| 176 | 
            -
                  }
         | 
| 177 182 | 
             
                },
         | 
| 178 183 |  | 
| 179 184 | 
             
                get_prefix: function(){
         | 
| @@ -15,6 +15,10 @@ describe JsRoutes, "compatibility with Rails"  do | |
| 15 15 | 
             
                evaljs("Routes.inbox_path(1)").should == routes.inbox_path(1)
         | 
| 16 16 | 
             
              end
         | 
| 17 17 |  | 
| 18 | 
            +
              it "should support 0 as a member parameter" do
         | 
| 19 | 
            +
                evaljs("Routes.inbox_path(0)").should == routes.inbox_path(0)
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
             | 
| 18 22 | 
             
              it "should generate nested routing with one parameter" do
         | 
| 19 23 | 
             
                evaljs("Routes.inbox_messages_path(1)").should == routes.inbox_messages_path(1)
         | 
| 20 24 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: js-routes
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.8. | 
| 4 | 
            +
              version: 0.8.6
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013-01- | 
| 12 | 
            +
            date: 2013-01-24 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: rails
         | 
| @@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 135 135 | 
             
                  version: '0'
         | 
| 136 136 | 
             
                  segments:
         | 
| 137 137 | 
             
                  - 0
         | 
| 138 | 
            -
                  hash:  | 
| 138 | 
            +
                  hash: -2317376881540244004
         | 
| 139 139 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 140 140 | 
             
              none: false
         | 
| 141 141 | 
             
              requirements:
         |