eastwood 0.3.8 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/eastwood.js.coffee.erb +3 -3
- data/gemfiles/rails-3.1.0.gemfile.lock +1 -1
- data/gemfiles/rails-3.2.0.gemfile.lock +1 -1
- data/lib/eastwood/config.rb +25 -3
- data/lib/eastwood/context/{hash_route.rb → client_route.rb} +4 -4
- data/lib/eastwood/context.rb +5 -5
- data/lib/eastwood/version.rb +1 -1
- data/lib/eastwood.rb +1 -1
- data/spec/requests/eastwood_spec.rb +18 -0
- data/spec/support/rails_template.rb +4 -0
- data/spec/unit/config_spec.rb +31 -3
- data/spec/unit/context_spec.rb +14 -14
- data/spec/unit/format_spec.rb +1 -1
- metadata +18 -18
@@ -16,12 +16,12 @@ app.exports =
|
|
16
16
|
###*
|
17
17
|
* Routes
|
18
18
|
###
|
19
|
-
<% if
|
19
|
+
<% if server_routes.any? or client_routes.any? %>
|
20
20
|
app.routes =
|
21
|
-
<%
|
21
|
+
<% server_routes.each do |key, route| %>
|
22
22
|
<%= route.coffee_name %> : ( <%= route.coffee_args %> ) -> "<%= route.coffee_path %>"
|
23
23
|
<% end %>
|
24
|
-
<%
|
24
|
+
<% client_routes.each do |key, route| %>
|
25
25
|
<%= route.coffee_name %> : ( <%= route.coffee_args %> ) -> "<%= route.coffee_path %>"
|
26
26
|
<% end %>
|
27
27
|
<% end %>
|
data/lib/eastwood/config.rb
CHANGED
@@ -9,11 +9,19 @@ module Eastwood
|
|
9
9
|
module ClassMethods
|
10
10
|
|
11
11
|
def hash( name, route )
|
12
|
-
hashes[ name ] = route
|
12
|
+
hashes[ name ] = [ route, 'hash' ]
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
15
|
+
def path( name, route )
|
16
|
+
paths[ name ] = [ route, 'path' ]
|
17
|
+
end
|
18
|
+
|
19
|
+
def url( name, route )
|
20
|
+
urls[ name ] = [ route, 'url' ]
|
21
|
+
end
|
22
|
+
|
23
|
+
def custom_routes
|
24
|
+
hashes.merge paths.merge urls
|
17
25
|
end
|
18
26
|
|
19
27
|
def export( *args )
|
@@ -33,6 +41,20 @@ module Eastwood
|
|
33
41
|
@@javascript_route_style = :underscore
|
34
42
|
@@javascript_namespace = nil
|
35
43
|
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def hashes
|
48
|
+
@@hashes ||= Hash.new
|
49
|
+
end
|
50
|
+
|
51
|
+
def paths
|
52
|
+
@@paths ||= Hash.new
|
53
|
+
end
|
54
|
+
|
55
|
+
def urls
|
56
|
+
@@urls ||= Hash.new
|
57
|
+
end
|
36
58
|
end
|
37
59
|
end
|
38
60
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Eastwood
|
2
2
|
module Context
|
3
|
-
class
|
3
|
+
class ClientRoute < Struct.new( :key, :route, :suffix )
|
4
4
|
include RouteHelpers
|
5
5
|
|
6
6
|
def name
|
@@ -8,15 +8,15 @@ module Eastwood
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def parts
|
11
|
-
|
11
|
+
route.scan( /:(\w+)/ ).flatten.map &:to_sym
|
12
12
|
end
|
13
13
|
|
14
14
|
def path
|
15
|
-
|
15
|
+
route
|
16
16
|
end
|
17
17
|
|
18
18
|
def coffee_name
|
19
|
-
style_for_javascript "#{name}
|
19
|
+
style_for_javascript "#{name}_#{suffix}"
|
20
20
|
end
|
21
21
|
|
22
22
|
def coffee_args
|
data/lib/eastwood/context.rb
CHANGED
@@ -13,18 +13,18 @@ module Eastwood
|
|
13
13
|
env === 'test' ? '( @window = { } )' : 'window'
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def server_routes
|
17
17
|
# TODO would kind of like to find a better way to transform
|
18
18
|
# these values into my routes, but keep as a hash
|
19
19
|
# http://www.ruby-forum.com/topic/185611
|
20
20
|
named_routes.merge( named_routes ) { |key, route| route_class.new route, route_format }
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def client_routes
|
24
24
|
# TODO would kind of like to find a better way to transform
|
25
25
|
# these values into my routes, but keep as a hash
|
26
26
|
# http://www.ruby-forum.com/topic/185611
|
27
|
-
|
27
|
+
custom_routes.merge( custom_routes ){ |key, (route, suffix)| ClientRoute.new key, route, suffix }
|
28
28
|
end
|
29
29
|
|
30
30
|
def exports
|
@@ -45,8 +45,8 @@ module Eastwood
|
|
45
45
|
[ '', false ].include? Eastwood.default_route_format
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
49
|
-
Eastwood.
|
48
|
+
def custom_routes
|
49
|
+
Eastwood.custom_routes
|
50
50
|
end
|
51
51
|
|
52
52
|
def named_routes
|
data/lib/eastwood/version.rb
CHANGED
data/lib/eastwood.rb
CHANGED
@@ -7,7 +7,7 @@ module Eastwood
|
|
7
7
|
module Context
|
8
8
|
autoload :ActionRoute, 'eastwood/context/action_route'
|
9
9
|
autoload :JourneyRoute, 'eastwood/context/journey_route'
|
10
|
-
autoload :
|
10
|
+
autoload :ClientRoute, 'eastwood/context/client_route'
|
11
11
|
autoload :RouteHelpers, 'eastwood/context/route_helpers'
|
12
12
|
end
|
13
13
|
|
@@ -78,6 +78,24 @@ describe 'eastwood.js' do
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
describe 'about_path' do
|
82
|
+
it 'should be defined' do
|
83
|
+
context.eval( "typeof #{routes}.about_path" ).should eq( 'function' )
|
84
|
+
end
|
85
|
+
it 'should return the correct path' do
|
86
|
+
context.call( "#{routes}.about_path", 'foo' ).should eq( '/about/foo' )
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'google_url' do
|
91
|
+
it 'should be defined' do
|
92
|
+
context.eval( "typeof #{routes}.google_url" ).should eq( 'function' )
|
93
|
+
end
|
94
|
+
it 'should return the correct url' do
|
95
|
+
context.call( "#{routes}.google_url" ).should eq( 'http://www.google.com/search' )
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
81
99
|
describe 'exports' do
|
82
100
|
it 'should be defined' do
|
83
101
|
context.eval( "typeof #{exports}" ).should eq( 'object' )
|
@@ -21,6 +21,10 @@ Eastwood.configure do |config|
|
|
21
21
|
config.hash :user, '#/users/:id'
|
22
22
|
config.hash :post, '#/users/:id/posts/:slug'
|
23
23
|
|
24
|
+
config.path :about, '/about/:topic'
|
25
|
+
|
26
|
+
config.url :google, 'http://www.google.com/search'
|
27
|
+
|
24
28
|
config.export :string => 'foo',
|
25
29
|
:float => 123.45,
|
26
30
|
:boolean => true
|
data/spec/unit/config_spec.rb
CHANGED
@@ -29,12 +29,40 @@ describe Eastwood do
|
|
29
29
|
|
30
30
|
describe 'adding a hash' do
|
31
31
|
before do
|
32
|
-
Eastwood.hash :
|
32
|
+
Eastwood.hash :myhash, '#/bar'
|
33
33
|
end
|
34
34
|
|
35
|
-
subject { Eastwood.
|
35
|
+
subject { Eastwood.custom_routes }
|
36
36
|
|
37
|
-
it { should include( :
|
37
|
+
it { should include( :myhash => [ '#/bar', 'hash' ] ) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#path' do
|
42
|
+
it { should respond_to( :path ) }
|
43
|
+
|
44
|
+
describe 'adding a path' do
|
45
|
+
before do
|
46
|
+
Eastwood.path :mypath, '/foo/bar'
|
47
|
+
end
|
48
|
+
|
49
|
+
subject { Eastwood.custom_routes }
|
50
|
+
|
51
|
+
it { should include( :mypath => [ '/foo/bar', 'path' ] ) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#url' do
|
56
|
+
it { should respond_to( :url ) }
|
57
|
+
|
58
|
+
describe 'adding a url' do
|
59
|
+
before do
|
60
|
+
Eastwood.url :myurl, 'http://www.foo.com'
|
61
|
+
end
|
62
|
+
|
63
|
+
subject { Eastwood.custom_routes }
|
64
|
+
|
65
|
+
it { should include( :myurl => [ 'http://www.foo.com', 'url' ] ) }
|
38
66
|
end
|
39
67
|
end
|
40
68
|
|
data/spec/unit/context_spec.rb
CHANGED
@@ -25,14 +25,14 @@ describe 'the Sprockets context class' do
|
|
25
25
|
it { should delegate( :env ).to( Eastwood, :env ) }
|
26
26
|
end
|
27
27
|
|
28
|
-
describe '#
|
29
|
-
it { should respond_to( :
|
30
|
-
its( :
|
28
|
+
describe '#server_routes' do
|
29
|
+
it { should respond_to( :server_routes ) }
|
30
|
+
its( :server_routes ){ should be_a( Hash ) }
|
31
31
|
end
|
32
32
|
|
33
|
-
describe '#
|
34
|
-
it { should respond_to( :
|
35
|
-
its( :
|
33
|
+
describe '#client_routes' do
|
34
|
+
it { should respond_to( :client_routes ) }
|
35
|
+
its( :client_routes ){ should be_a( Hash ) }
|
36
36
|
end
|
37
37
|
|
38
38
|
describe '#exports' do
|
@@ -70,11 +70,11 @@ describe 'the Sprockets context class' do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
describe 'routes' do
|
73
|
+
describe 'sever routes' do
|
74
74
|
let( :context ){ ::Rails.application.assets.context_class.new nil, nil, nil }
|
75
75
|
|
76
76
|
describe 'eastwood_engine' do
|
77
|
-
subject { context.
|
77
|
+
subject { context.server_routes[ :eastwood_engine ] }
|
78
78
|
|
79
79
|
its( :name ){ should eq( 'eastwood_engine' ) }
|
80
80
|
its( :path ){ should eq( '/eastwood' ) }
|
@@ -86,7 +86,7 @@ describe 'routes' do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
describe 'match' do
|
89
|
-
subject { context.
|
89
|
+
subject { context.server_routes[ :match ] }
|
90
90
|
|
91
91
|
its( :name ){ should eq( 'match' ) }
|
92
92
|
its( :path ){ should eq( '/foo.:format' ) }
|
@@ -98,7 +98,7 @@ describe 'routes' do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
describe 'match with segment' do
|
101
|
-
subject { context.
|
101
|
+
subject { context.server_routes[ :match_with_segment ] }
|
102
102
|
|
103
103
|
its( :name ){ should eq( 'match_with_segment' ) }
|
104
104
|
its( :path ){ should eq( '/foo/:id.:format' ) }
|
@@ -110,11 +110,11 @@ describe 'routes' do
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
-
describe '
|
113
|
+
describe 'client routes' do
|
114
114
|
let( :context ){ ::Rails.application.assets.context_class.new nil, nil, nil }
|
115
115
|
|
116
116
|
describe 'home' do
|
117
|
-
subject { context.
|
117
|
+
subject { context.client_routes[ :home ] }
|
118
118
|
|
119
119
|
its( :name ){ should eq( 'home' ) }
|
120
120
|
its( :path ){ should eq( '#/home' ) }
|
@@ -126,7 +126,7 @@ describe 'hashes' do
|
|
126
126
|
end
|
127
127
|
|
128
128
|
describe 'user' do
|
129
|
-
subject { context.
|
129
|
+
subject { context.client_routes[ :user ] }
|
130
130
|
|
131
131
|
its( :name ){ should eq( 'user' ) }
|
132
132
|
its( :path ){ should eq( '#/users/:id' ) }
|
@@ -138,7 +138,7 @@ describe 'hashes' do
|
|
138
138
|
end
|
139
139
|
|
140
140
|
describe 'post' do
|
141
|
-
subject { context.
|
141
|
+
subject { context.client_routes[ :post ] }
|
142
142
|
|
143
143
|
its( :name ){ should eq( 'post' ) }
|
144
144
|
its( :path ){ should eq( '#/users/:id/posts/:slug' ) }
|
data/spec/unit/format_spec.rb
CHANGED
@@ -46,7 +46,7 @@ describe 'route formatting' do
|
|
46
46
|
|
47
47
|
describe 'including the format in routes' do
|
48
48
|
let( :context ){ ::Rails.application.assets.context_class.new nil, nil, nil }
|
49
|
-
subject { context.
|
49
|
+
subject { context.server_routes[ :match ] }
|
50
50
|
|
51
51
|
context 'default format' do
|
52
52
|
its( :coffee_args ){ should eq( "format='.json'" ) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eastwood
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-04-21 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &120730 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *120730
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: coffee-rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &120430 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *120430
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &120180 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *120180
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: appraisal
|
49
|
-
requirement: &
|
49
|
+
requirement: &119830 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - =
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.4.1
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *119830
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec-rails
|
60
|
-
requirement: &
|
60
|
+
requirement: &119480 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - =
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 2.9.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *119480
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: shoulda
|
71
|
-
requirement: &
|
71
|
+
requirement: &119100 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - =
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 3.0.1
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *119100
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: execjs
|
82
|
-
requirement: &
|
82
|
+
requirement: &118100 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - =
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 1.3.0
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *118100
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: simplecov
|
93
|
-
requirement: &
|
93
|
+
requirement: &116830 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - =
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: 0.6.1
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *116830
|
102
102
|
description: Start your client side out right
|
103
103
|
email:
|
104
104
|
- jeremy.ruppel@gmail.com
|
@@ -125,7 +125,7 @@ files:
|
|
125
125
|
- lib/eastwood/config.rb
|
126
126
|
- lib/eastwood/context.rb
|
127
127
|
- lib/eastwood/context/action_route.rb
|
128
|
-
- lib/eastwood/context/
|
128
|
+
- lib/eastwood/context/client_route.rb
|
129
129
|
- lib/eastwood/context/journey_route.rb
|
130
130
|
- lib/eastwood/context/route_helpers.rb
|
131
131
|
- lib/eastwood/engine.rb
|