ember-routes 0.0.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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/ember-routes.gemspec +34 -0
- data/lib/ember_route_helpers/route.rb +18 -0
- data/lib/ember_routes.rb +14 -0
- data/lib/ember_routes/config.rb +22 -0
- data/lib/ember_routes/generator.rb +87 -0
- data/lib/ember_routes/path_helpers.rb +5 -0
- data/lib/ember_routes/route.rb +18 -0
- data/lib/ember_routes/version.rb +3 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9992a1cdf2bc58dc808d6b5b684d9ed36a783da0
|
4
|
+
data.tar.gz: 7b5d2327c5638982d7b23f7533c2b2cb7ff55a61
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1fd4a7bdfb12d93e3f5b7ed494158de5f7e731158e4bcf8ea0aedaba47766f4032d84d05b101ed7ff69ea291fce899315f37b262fa18e78f4c167bc350d133f
|
7
|
+
data.tar.gz: d6d6f37ee07ac2b8fe3314119da17bd52d021c51aa07bbdb00f0780670eaa4eed937e845e7b3b0ddb22eea32a028743ef6b0390f3c82d588d2594ac24af1d0f5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Brendan Asselstine
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# EmberRoutes
|
2
|
+
|
3
|
+
This gem makes integration testing Rails-backed Ember apps a little easier.
|
4
|
+
|
5
|
+
Given a Rails project with an embedded Ember app, whether using [ember-cli-rails](https://github.com/rwz/ember-cli-rails) or otherwise, you will likely want to run integration tests using Capybara.
|
6
|
+
|
7
|
+
Unfortunately, Ember's route definitions are tucked away in a router.js file, and are not available to the Ruby spec code.
|
8
|
+
|
9
|
+
EmberRoutes tries to address this by allowing you to express your Ember routes using a similar syntax, then generating corresponding path helpers and placing them within a PathHelpers module.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'ember-routes'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install ember-routes
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
To define your Ember application routes, call `EmberRoutes.configure` like so:
|
30
|
+
|
31
|
+
```
|
32
|
+
EmberRoutes.configure do |config|
|
33
|
+
config.prefix = prefix # A string to prefix the path helper names. Defaults to ''
|
34
|
+
config.base_url = base_url # The base url for the application, it will prefix the paths. Defaults to ''
|
35
|
+
config.routes do
|
36
|
+
route 'foo', :path => '/foo' do
|
37
|
+
route 'bar', :path => '/bar' do
|
38
|
+
route 'show', :path => '/:id'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
If you're using Rails, the above configuration can be placed in it's own initializer such as `config/initializers/ember_routes.rb` or in the rails_helper file.
|
46
|
+
|
47
|
+
Running the configuration will generate the path helpers and place them within the EmberRails::PathHelpers module. You can them include them like so:
|
48
|
+
|
49
|
+
```
|
50
|
+
#spec/spec_helper
|
51
|
+
|
52
|
+
include EmberRails::PathHelpers
|
53
|
+
|
54
|
+
```
|
55
|
+
|
56
|
+
The above configuration will generate the following path helpers:
|
57
|
+
|
58
|
+
```
|
59
|
+
foo_path #/foo
|
60
|
+
foo_bar_path #/foo/bar
|
61
|
+
foo_bar_show_path #/foo/bar/:id
|
62
|
+
```
|
63
|
+
|
64
|
+
Note that paths that include parameters (defined using the colon notation) will insert the parameters into
|
65
|
+
the path itself. For example, given the above configuration:
|
66
|
+
|
67
|
+
```
|
68
|
+
foo_bar_show_path(:id => 12, :sort => 'ASC')
|
69
|
+
#=> /foo/bar/12?sort=ASC
|
70
|
+
```
|
71
|
+
|
72
|
+
## Development
|
73
|
+
|
74
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
75
|
+
|
76
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/asseltine/ember-routes
|
81
|
+
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ember/route/helpers"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ember_routes/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ember-routes"
|
8
|
+
spec.version = EmberRoutes::VERSION
|
9
|
+
spec.authors = ["Brendan Asselstine"]
|
10
|
+
spec.email = ["mail.asselstine@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Generate Ruby path helpers using a similar syntax as Ember routes.}
|
13
|
+
spec.description = %q{The ember-routes gem was created to facilitate easier testing with
|
14
|
+
Capybara by providing path helpers for the Ember app. The path helpers are described in a similar syntax to the Ember routes engine.}
|
15
|
+
spec.homepage = "https://github.com/asselstine/ember-routes"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
19
|
+
# delete this section to allow pushing this gem to any host.
|
20
|
+
if spec.respond_to?(:metadata)
|
21
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
22
|
+
else
|
23
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec"
|
34
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module EmberRoutes
|
2
|
+
class Route
|
3
|
+
attr_accessor :name, :path, :children
|
4
|
+
def initialize(name, opts = {})
|
5
|
+
@name = name.to_s
|
6
|
+
@path = opts.fetch(:path, name)
|
7
|
+
@children = []
|
8
|
+
end
|
9
|
+
def route(*arguments, &block)
|
10
|
+
p = Route.new(*arguments)
|
11
|
+
self.children << p
|
12
|
+
if block_given?
|
13
|
+
p.instance_eval(&block)
|
14
|
+
end
|
15
|
+
p
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/ember_routes.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'ember_routes/config'
|
2
|
+
require 'ember_routes/generator'
|
3
|
+
require 'ember_routes/path_helpers'
|
4
|
+
require 'ember_routes/route'
|
5
|
+
|
6
|
+
module EmberRoutes
|
7
|
+
def self.configure
|
8
|
+
c = Config.new
|
9
|
+
yield c
|
10
|
+
gen = Generator.new(c, PathHelpers)
|
11
|
+
gen.generate
|
12
|
+
c
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module EmberRoutes
|
2
|
+
class Config
|
3
|
+
|
4
|
+
attr_accessor :base_url, :prefix
|
5
|
+
attr_reader :root
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@root = Route.new('root', :path => '/')
|
9
|
+
@base_url = ''
|
10
|
+
@prefix = ''
|
11
|
+
end
|
12
|
+
|
13
|
+
def config(&block)
|
14
|
+
generate_methods
|
15
|
+
end
|
16
|
+
|
17
|
+
def routes(&block)
|
18
|
+
@root.instance_eval &block
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module EmberRoutes
|
2
|
+
class Generator
|
3
|
+
|
4
|
+
def self.args_to_hash(*args)
|
5
|
+
parameters = {}
|
6
|
+
if args.any?
|
7
|
+
if args.is_a?(Array)
|
8
|
+
parameters = args.reduce({}) { |carry, elem| carry.merge(elem) }
|
9
|
+
else
|
10
|
+
parameters = args
|
11
|
+
end
|
12
|
+
end
|
13
|
+
parameters
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.format_path(path, path_params, parameters)
|
17
|
+
path_params.each do |param_name|
|
18
|
+
val = parameters[param_name.to_sym]
|
19
|
+
raise "#{path} missing #{param_name}" unless val
|
20
|
+
path = path.gsub(":"+param_name, val.to_s)
|
21
|
+
parameters.delete(param_name.to_sym)
|
22
|
+
end
|
23
|
+
[path, parameters]
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(config, context)
|
27
|
+
@config = config
|
28
|
+
@context = context
|
29
|
+
@stack = []
|
30
|
+
end
|
31
|
+
|
32
|
+
def generate
|
33
|
+
@stack = []
|
34
|
+
visit @config.root
|
35
|
+
end
|
36
|
+
|
37
|
+
def visit(route)
|
38
|
+
@stack.push route
|
39
|
+
path = @config.base_url + current_path
|
40
|
+
path_params = path.scan(/:(\w+)/).map { |arr| arr[0] }
|
41
|
+
helper = Proc.new { |*args|
|
42
|
+
formatted_path = path
|
43
|
+
if (args.length)
|
44
|
+
formatted_path, parameters = Generator.format_path(path, path_params, Generator.args_to_hash(*args))
|
45
|
+
end
|
46
|
+
if parameters.any?
|
47
|
+
formatted_path += "?" + URI.encode_www_form(parameters)
|
48
|
+
end
|
49
|
+
formatted_path
|
50
|
+
}
|
51
|
+
_method = current_method
|
52
|
+
define_helper = Proc.new {
|
53
|
+
define_method _method, helper
|
54
|
+
}
|
55
|
+
@context.class_eval &define_helper
|
56
|
+
route.children.each do |child|
|
57
|
+
visit(child)
|
58
|
+
end
|
59
|
+
@stack.pop
|
60
|
+
end
|
61
|
+
|
62
|
+
def current_method
|
63
|
+
if @stack.length > 1
|
64
|
+
name = @stack[1..-1].map(&:name).join('_')
|
65
|
+
else
|
66
|
+
name = @stack.first.name
|
67
|
+
end
|
68
|
+
@config.prefix + name + "_path"
|
69
|
+
end
|
70
|
+
|
71
|
+
def current_path
|
72
|
+
@stack.map(&:path).join('').gsub(/\/\//,'/')
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.underscore(camel_cased_word)
|
76
|
+
camel_cased_word.to_s
|
77
|
+
.gsub(/^\//, '')
|
78
|
+
.gsub(/\/$/, '')
|
79
|
+
.gsub(/\//, '_')
|
80
|
+
.gsub(/::/, '/')
|
81
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
82
|
+
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
|
83
|
+
.tr("-", "_")
|
84
|
+
.downcase
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module EmberRoutes
|
2
|
+
class Route
|
3
|
+
attr_accessor :name, :path, :children
|
4
|
+
def initialize(name, opts = {})
|
5
|
+
@name = name.to_s
|
6
|
+
@path = opts.fetch(:path, name)
|
7
|
+
@children = []
|
8
|
+
end
|
9
|
+
def route(*arguments, &block)
|
10
|
+
p = Route.new(*arguments)
|
11
|
+
self.children << p
|
12
|
+
if block_given?
|
13
|
+
p.instance_eval(&block)
|
14
|
+
end
|
15
|
+
p
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ember-routes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brendan Asselstine
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-25 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: |-
|
56
|
+
The ember-routes gem was created to facilitate easier testing with
|
57
|
+
Capybara by providing path helpers for the Ember app. The path helpers are described in a similar syntax to the Ember routes engine.
|
58
|
+
email:
|
59
|
+
- mail.asselstine@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- ember-routes.gemspec
|
74
|
+
- lib/ember_route_helpers/route.rb
|
75
|
+
- lib/ember_routes.rb
|
76
|
+
- lib/ember_routes/config.rb
|
77
|
+
- lib/ember_routes/generator.rb
|
78
|
+
- lib/ember_routes/path_helpers.rb
|
79
|
+
- lib/ember_routes/route.rb
|
80
|
+
- lib/ember_routes/version.rb
|
81
|
+
homepage: https://github.com/asselstine/ember-routes
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata:
|
85
|
+
allowed_push_host: https://rubygems.org
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.4.5
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Generate Ruby path helpers using a similar syntax as Ember routes.
|
106
|
+
test_files: []
|