coffee_routes 1.0.0
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 +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +2 -0
- data/coffee_routes.gemspec +23 -0
- data/lib/action_dispatch/routing/json_formatter.rb +44 -0
- data/lib/coffee_routes/version.rb +3 -0
- data/lib/coffee_routes.rb +15 -0
- data/vendor/assets/javascripts/coffee_routes.coffee.erb +20 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 44cd1b2975b9222ab24713caa6259aa1fe450fb4
|
4
|
+
data.tar.gz: 9f7e13213a0a31b4e64b3b367afefef42b4373f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97ec04405e3752d4791dce0e8a684d82c7db42f2b30b21e6dd896690cf703e86c19a7d44fa3da011c9b7f62fa8fa4eb363bf84b13449d926ca500f0ee72ae27f
|
7
|
+
data.tar.gz: d813bdbff830be7d5fdd17a0ef654a98df6a0e00a3e6486c0d34649609b2c6856b15152f91114e7528500e4581b0f74c26c0daacd242f87efde3c8585b45d688
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Dan Wentworth
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# CoffeeRoutes
|
2
|
+
|
3
|
+
Access your Rails named routes from coffeescript.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'coffee_routes'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install coffee_routes
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Include coffee_routes in your application.coffeee
|
24
|
+
|
25
|
+
```coffee
|
26
|
+
#= require coffee_routes
|
27
|
+
```
|
28
|
+
|
29
|
+
You should now have the CoffeeRoutes object in your global javascript scope.
|
30
|
+
|
31
|
+
To access a named route, just call the CoffeeRoute.path helper
|
32
|
+
|
33
|
+
```coffee
|
34
|
+
CoffeeRoutes.path('project_item')
|
35
|
+
=> "/projects/:project_id/item/:id"
|
36
|
+
```
|
37
|
+
|
38
|
+
To substitute in the parameter values pass in a hash.
|
39
|
+
|
40
|
+
```coffee
|
41
|
+
CoffeeRoutes.path('project_item', {"project_id" : "project-awesome", "id" : 5})
|
42
|
+
=> "/projects/project-awesome/items/5"
|
43
|
+
```
|
44
|
+
|
45
|
+
You can also get the HTTP verb that should be used with the named route.
|
46
|
+
|
47
|
+
```coffee
|
48
|
+
CoffeeRoutes.method('project_item')
|
49
|
+
=> "GET"
|
50
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'coffee_routes/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "coffee_routes"
|
8
|
+
spec.version = CoffeeRoutes::VERSION
|
9
|
+
spec.authors = ["Dan Wentworth"]
|
10
|
+
spec.email = ["dan@atechmedia.com"]
|
11
|
+
spec.summary = %q{Access your named Rails routes from your coffeescript}
|
12
|
+
spec.homepage = "http://darkphnx.com"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_dependency "actionpack", ">= 3.2"
|
23
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# ActionDispatch::Routing::RoutesInspector says people shouldn't use
|
2
|
+
# it, but lets pretend we didn't see it.
|
3
|
+
|
4
|
+
|
5
|
+
module ActionDispatch
|
6
|
+
module Routing
|
7
|
+
class JSONFormatter
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@buffer = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
# Serialize the buffer has as json
|
14
|
+
def result
|
15
|
+
ActiveSupport::JSON.encode(@buffer)
|
16
|
+
end
|
17
|
+
|
18
|
+
# No need for a title, we only want the data
|
19
|
+
def section_title(title)
|
20
|
+
end
|
21
|
+
|
22
|
+
def section(routes)
|
23
|
+
@buffer.merge! draw_section(routes)
|
24
|
+
end
|
25
|
+
|
26
|
+
# No need for a header, we only want data
|
27
|
+
def header(routes)
|
28
|
+
end
|
29
|
+
|
30
|
+
# No routes will be represented by an empty object
|
31
|
+
def no_routes
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def draw_section(routes)
|
37
|
+
routes.each_with_object({}) do |r, hash|
|
38
|
+
hash[r[:name]] = {:path => r[:path], :verb => r[:verb]}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "coffee_routes/version"
|
2
|
+
require 'action_dispatch/routing/json_formatter'
|
3
|
+
|
4
|
+
module CoffeeRoutes
|
5
|
+
module Rails
|
6
|
+
class Engine < ::Rails::Engine
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.routes(controller=nil)
|
11
|
+
all_routes = ::Rails.application.routes.routes
|
12
|
+
inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
|
13
|
+
inspector.format(ActionDispatch::Routing::JSONFormatter.new, controller)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
window.CoffeeRoutes =
|
2
|
+
routes: <%= CoffeeRoutes.routes %>
|
3
|
+
|
4
|
+
path: (path, params)->
|
5
|
+
params ||= {}
|
6
|
+
if @routes[path]?
|
7
|
+
route = @routes[path]
|
8
|
+
path = route.path.replace(/\(.\:format\)$/, '')
|
9
|
+
path = path.replace /:[a-z0-9_\-]+/gi, (match)->
|
10
|
+
key = match.replace(/^:/, '')
|
11
|
+
if params[key]? then params[key] else match
|
12
|
+
|
13
|
+
if params['format']?
|
14
|
+
path += ".#{params['format']}"
|
15
|
+
|
16
|
+
path
|
17
|
+
|
18
|
+
method: (path)->
|
19
|
+
if @routes[path]?
|
20
|
+
@routes[path].verb
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coffee_routes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Wentworth
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: actionpack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- dan@atechmedia.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- LICENSE.txt
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- coffee_routes.gemspec
|
67
|
+
- lib/action_dispatch/routing/json_formatter.rb
|
68
|
+
- lib/coffee_routes.rb
|
69
|
+
- lib/coffee_routes/version.rb
|
70
|
+
- vendor/assets/javascripts/coffee_routes.coffee.erb
|
71
|
+
homepage: http://darkphnx.com
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.2.2
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Access your named Rails routes from your coffeescript
|
95
|
+
test_files: []
|