asset_pipeline_routes 0.2.0 → 0.2.1
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.
- checksums.yaml +4 -4
 - data/README.md +1 -0
 - data/lib/asset_pipeline_routes/path_processor.rb +15 -7
 - data/lib/asset_pipeline_routes/version.rb +1 -1
 - data/spec/fixtures/coffee_with_function_invocation.coffee +1 -0
 - data/spec/fixtures/coffee_with_function_invocation_arguments.coffee +2 -0
 - data/spec/path_processor_spec.rb +14 -6
 - metadata +6 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: ae12a66e8ec65bbe232bbb057054e21b7ee9c219
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: cf3c727032a3fc1c052e9f65088153f144c961e0
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 87e847796f67c2e133f04713176e573cb9cb1689098cba6afc7a6343e8da007a49b601fd9dcf218f5fc9ccaeb8ce0a7be47f5c1255c00cd5c884ced07382cb91
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 539976ab1266359444692807c92197201980497baf233b88da4863cd47eb6c4031d157fdad042a4a69894c7d73669cf799dfd24765b6a703e53f5f4ddcc6b249
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # asset\_pipeline\_routes
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            [](https://travis-ci.org/nicolai86/asset_pipeline_routes)
         
     | 
| 
      
 4 
     | 
    
         
            +
            [](http://badge.fury.io/rb/asset_pipeline_routes)
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
6 
     | 
    
         
             
            `asset_pipeline_routes` defines a `r` shorthand function which you can use inside your javascript assets.
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
         @@ -11,19 +11,27 @@ module AssetPipelineRoutes 
     | 
|
| 
       11 
11 
     | 
    
         
             
                end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
                def evaluate context, locals
         
     | 
| 
       14 
     | 
    
         
            -
                   
     | 
| 
       15 
     | 
    
         
            -
                     
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
                  re = %r{
         
     | 
| 
      
 15 
     | 
    
         
            +
                    (?<=[^[[:word:]]])r(?<re>
         
     | 
| 
      
 16 
     | 
    
         
            +
                      \(
         
     | 
| 
      
 17 
     | 
    
         
            +
                        (?:
         
     | 
| 
      
 18 
     | 
    
         
            +
                          (?> [^()]+ )
         
     | 
| 
      
 19 
     | 
    
         
            +
                          |
         
     | 
| 
      
 20 
     | 
    
         
            +
                          \g<re>
         
     | 
| 
      
 21 
     | 
    
         
            +
                        )*
         
     | 
| 
      
 22 
     | 
    
         
            +
                      \)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    )
         
     | 
| 
      
 24 
     | 
    
         
            +
                  }x
         
     | 
| 
      
 25 
     | 
    
         
            +
                  data.gsub re do |match|
         
     | 
| 
      
 26 
     | 
    
         
            +
                    str = match[2..-2]
         
     | 
| 
      
 27 
     | 
    
         
            +
                    parts = str.split(',').map(&:strip).reject(&:blank?)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    route = parts.shift.to_sym
         
     | 
| 
       19 
29 
     | 
    
         | 
| 
       20 
30 
     | 
    
         
             
                    expanded = if r.respond_to? route
         
     | 
| 
       21 
31 
     | 
    
         
             
                      r.send route, *parts
         
     | 
| 
       22 
32 
     | 
    
         
             
                    else
         
     | 
| 
       23 
33 
     | 
    
         
             
                      "''"
         
     | 
| 
       24 
34 
     | 
    
         
             
                    end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                    wrap ? "(#{expanded})" : expanded
         
     | 
| 
       27 
35 
     | 
    
         
             
                  end
         
     | 
| 
       28 
36 
     | 
    
         
             
                end
         
     | 
| 
       29 
37 
     | 
    
         
             
              end
         
     | 
| 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            console.log(r(project_ticket_path))
         
     | 
    
        data/spec/path_processor_spec.rb
    CHANGED
    
    | 
         @@ -26,15 +26,15 @@ describe AssetPipelineRoutes::PathProcessor do 
     | 
|
| 
       26 
26 
     | 
    
         
             
              end
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
              it "replaces calls to r() with route" do
         
     | 
| 
       29 
     | 
    
         
            -
                @env['simple_route.js'].to_s.should == "var Bar ='/users';\n"
         
     | 
| 
      
 29 
     | 
    
         
            +
                @env['simple_route.js'].to_s.should == "var Bar = '/users';\n"
         
     | 
| 
       30 
30 
     | 
    
         
             
              end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
              it "replaces calls with unknown route to ''" do
         
     | 
| 
       33 
     | 
    
         
            -
                @env['unknown_route.js'].to_s.should == "var Bar ='';\n"
         
     | 
| 
      
 33 
     | 
    
         
            +
                @env['unknown_route.js'].to_s.should == "var Bar = '';\n"
         
     | 
| 
       34 
34 
     | 
    
         
             
              end
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
              it "works with variables" do
         
     | 
| 
       37 
     | 
    
         
            -
                @env['simple_route_with_variable.js'].to_s.should == "var x = 2;\nvar Bar ='/users/'+x+'';\n"
         
     | 
| 
      
 37 
     | 
    
         
            +
                @env['simple_route_with_variable.js'].to_s.should == "var x = 2;\nvar Bar = '/users/'+x+'';\n"
         
     | 
| 
       38 
38 
     | 
    
         
             
              end
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
       40 
40 
     | 
    
         
             
              it "works with coffeescript" do
         
     | 
| 
         @@ -42,11 +42,11 @@ describe AssetPipelineRoutes::PathProcessor do 
     | 
|
| 
       42 
42 
     | 
    
         
             
              end
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
              it "works with unqualified routes" do
         
     | 
| 
       45 
     | 
    
         
            -
                @env['unqualified_routes.js'].to_s.should == "var url ='/users/{{id}}';\n"
         
     | 
| 
      
 45 
     | 
    
         
            +
                @env['unqualified_routes.js'].to_s.should == "var url = '/users/{{id}}';\n"
         
     | 
| 
       46 
46 
     | 
    
         
             
              end
         
     | 
| 
       47 
47 
     | 
    
         | 
| 
       48 
48 
     | 
    
         
             
              it "works with partially qualified nested routes" do
         
     | 
| 
       49 
     | 
    
         
            -
                @env['nested_routes.js'].to_s.should == "var project_path ='/projects/'+2+'/tickets/{{id}}';\n"
         
     | 
| 
      
 49 
     | 
    
         
            +
                @env['nested_routes.js'].to_s.should == "var project_path = '/projects/'+2+'/tickets/{{id}}';\n"
         
     | 
| 
       50 
50 
     | 
    
         
             
              end
         
     | 
| 
       51 
51 
     | 
    
         | 
| 
       52 
52 
     | 
    
         
             
              it "does not replace false positives" do
         
     | 
| 
         @@ -58,6 +58,14 @@ describe AssetPipelineRoutes::PathProcessor do 
     | 
|
| 
       58 
58 
     | 
    
         
             
              end
         
     | 
| 
       59 
59 
     | 
    
         | 
| 
       60 
60 
     | 
    
         
             
              it "works with function argument" do
         
     | 
| 
       61 
     | 
    
         
            -
                @env["argument_function.js"].to_s.should == "var url ='/users/'+fetchUserId()+'';\n"
         
     | 
| 
      
 61 
     | 
    
         
            +
                @env["argument_function.js"].to_s.should == "var url = '/users/'+fetchUserId()+'';\n"
         
     | 
| 
      
 62 
     | 
    
         
            +
              end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
              it "works with coffeescript method invocation" do
         
     | 
| 
      
 65 
     | 
    
         
            +
                @env['coffee_with_function_invocation.js'].to_s.should == "(function() {\n  console.log('/projects/{{project_id}}/tickets/{{id}}');\n\n}).call(this);\n"
         
     | 
| 
      
 66 
     | 
    
         
            +
              end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
              it "works with coffeescript method invocation" do
         
     | 
| 
      
 69 
     | 
    
         
            +
                @env['coffee_with_function_invocation_arguments.js'].to_s.should == "(function() {\n  var x;\n\n  x = 2;\n\n  console.log('/projects/' + 2 + '/tickets/' + x + '');\n\n}).call(this);\n"
         
     | 
| 
       62 
70 
     | 
    
         
             
              end
         
     | 
| 
       63 
71 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: asset_pipeline_routes
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Raphael Randschau
         
     | 
| 
         @@ -137,6 +137,8 @@ files: 
     | 
|
| 
       137 
137 
     | 
    
         
             
            - lib/asset_pipeline_routes.rb
         
     | 
| 
       138 
138 
     | 
    
         
             
            - spec/asset_pipeline_routes_spec.rb
         
     | 
| 
       139 
139 
     | 
    
         
             
            - spec/fixtures/argument_function.js
         
     | 
| 
      
 140 
     | 
    
         
            +
            - spec/fixtures/coffee_with_function_invocation.coffee
         
     | 
| 
      
 141 
     | 
    
         
            +
            - spec/fixtures/coffee_with_function_invocation_arguments.coffee
         
     | 
| 
       140 
142 
     | 
    
         
             
            - spec/fixtures/false_positive.js
         
     | 
| 
       141 
143 
     | 
    
         
             
            - spec/fixtures/function_argument.js
         
     | 
| 
       142 
144 
     | 
    
         
             
            - spec/fixtures/nested_routes.js
         
     | 
| 
         @@ -150,8 +152,9 @@ files: 
     | 
|
| 
       150 
152 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       151 
153 
     | 
    
         
             
            - README.md
         
     | 
| 
       152 
154 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       153 
     | 
    
         
            -
            homepage:  
     | 
| 
       154 
     | 
    
         
            -
            licenses: 
     | 
| 
      
 155 
     | 
    
         
            +
            homepage: http://blog.nicolai86.eu
         
     | 
| 
      
 156 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 157 
     | 
    
         
            +
            - MIT
         
     | 
| 
       155 
158 
     | 
    
         
             
            metadata: {}
         
     | 
| 
       156 
159 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       157 
160 
     | 
    
         
             
            rdoc_options: []
         
     |