hoboken 0.0.1.beta → 0.0.1.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/Rakefile +10 -0
- data/lib/hoboken.rb +124 -8
- data/lib/hoboken/actions.rb +16 -0
- data/lib/hoboken/templates/test/support/rack_test_assertions.rb.tt +24 -0
- data/lib/hoboken/templates/test/unit/app_test.rb.tt +1 -1
- data/lib/hoboken/version.rb +1 -1
- data/test/fixtures/Gemfile +4 -0
- data/test/fixtures/Gemfile.pristine +2 -0
- data/test/unit/hoboken_actions_test.rb +129 -0
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d93ed494dde1289a45fcfb75ffa80285d0995020
|
4
|
+
data.tar.gz: cd9319eef83037bf07083d0cc0740fc94fc0b415
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b4f2c2ccccb2ac0fecd1e76236fe52669478facb48a61d0791ab574fac940001e0dfa7f3b9127d4436d3b323010968432a86e72cb4844df6bce31cb405bb2f0
|
7
|
+
data.tar.gz: 6019310cb5cdb8005948b4ed8a9b5fc275a2c927ba40a771a9c3a72fa13881db4891339964b67f2f87c3a95aef779d308e743161d8959cf4437d3155bd19c645
|
data/README.md
CHANGED
@@ -38,9 +38,10 @@ To see a list of options for the generate command:
|
|
38
38
|
|
39
39
|
Additional generators are available for existing projects generated using Hoboken:
|
40
40
|
|
41
|
-
$ hoboken add:metrics # Add Rake tasks for metrics (flog, flay, simplecov)
|
42
|
-
$ hoboken add:i18n # Internationalization support using sinatra-r18n
|
43
41
|
$ hoboken add:heroku # Heroku deployment support
|
42
|
+
$ hoboken add:i18n # Internationalization support using sinatra-r18n
|
43
|
+
$ hoboken add:metrics # Add metrics (flog, flay, simplecov)
|
44
|
+
$ hoboken add:omniauth # OmniAuth authentication (allows you to select a provider)
|
44
45
|
$ hoboken add:sprockets # Rack-based asset packaging system
|
45
46
|
|
46
47
|
## Contributing
|
data/Rakefile
CHANGED
data/lib/hoboken.rb
CHANGED
@@ -3,10 +3,122 @@ require "thor/util"
|
|
3
3
|
require "fileutils"
|
4
4
|
require_relative "hoboken/version"
|
5
5
|
require_relative "hoboken/generate"
|
6
|
+
require_relative "hoboken/actions"
|
6
7
|
|
7
8
|
module Hoboken
|
9
|
+
class OmniAuth < Thor::Group
|
10
|
+
include Thor::Actions
|
11
|
+
include Hoboken::Actions
|
12
|
+
|
13
|
+
attr_reader :provider
|
14
|
+
|
15
|
+
def self.source_root
|
16
|
+
File.dirname(__FILE__)
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_gem
|
20
|
+
@provider = ask("Specify a provider (i.e. twitter, facebook. etc.): ").downcase
|
21
|
+
provider_version = ask("Specify provider version: ")
|
22
|
+
gem gem_name, provider_version
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup_middleware
|
26
|
+
insert_into_file("app.rb", after: /require "sinatra("|\/base")/) do
|
27
|
+
"\nrequire \"#{gem_name}\""
|
28
|
+
end
|
29
|
+
|
30
|
+
snippet = <<-CODE
|
31
|
+
|
32
|
+
use OmniAuth::Builder do
|
33
|
+
provider :#{provider}, ENV["#{provider.upcase}_KEY"], ENV["#{provider.upcase}_SECRET"]
|
34
|
+
end
|
35
|
+
|
36
|
+
CODE
|
37
|
+
|
38
|
+
text = modular? ? indent(snippet, 4) : snippet
|
39
|
+
insert_into_file("app.rb", after: /use Rack::Session::Cookie.+\n/) { text }
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_routes
|
43
|
+
routes = <<-CODE
|
44
|
+
|
45
|
+
|
46
|
+
get "/login" do
|
47
|
+
'<a href="/auth/#{provider}">Login</a>'
|
48
|
+
end
|
49
|
+
|
50
|
+
get "/auth/:provider/callback" do
|
51
|
+
# TODO: Insert real authentication logic...
|
52
|
+
MultiJson.encode(request.env['omniauth.auth'])
|
53
|
+
end
|
54
|
+
|
55
|
+
get "/auth/failure" do
|
56
|
+
# TODO: Insert real error handling logic...
|
57
|
+
halt 401, params[:message]
|
58
|
+
end
|
59
|
+
CODE
|
60
|
+
|
61
|
+
if modular?
|
62
|
+
insert_into_file("app.rb", after: /get.+?end$/m) { indent(routes, 4) }
|
63
|
+
else
|
64
|
+
append_file("app.rb", routes)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def add_tests
|
69
|
+
inject_into_class("test/unit/app_test.rb", "AppTest") do
|
70
|
+
<<-CODE
|
71
|
+
setup do
|
72
|
+
OmniAuth.config.test_mode = true
|
73
|
+
end
|
74
|
+
|
75
|
+
test "GET /login" do
|
76
|
+
get "/login"
|
77
|
+
assert_equal('<a href="/auth/#{provider}">Login</a>', last_response.body)
|
78
|
+
end
|
79
|
+
|
80
|
+
test "GET /auth/#{provider}/callback" do
|
81
|
+
auth_hash = {
|
82
|
+
"provider" => "#{provider}",
|
83
|
+
"uid" => "123545",
|
84
|
+
"info" => {
|
85
|
+
"name" => "John Doe"
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
OmniAuth.config.mock_auth[:#{provider}] = auth_hash
|
90
|
+
get "/auth/fitbit/callback"
|
91
|
+
assert_equal(MultiJson.encode(auth_hash), last_response.body)
|
92
|
+
end
|
93
|
+
|
94
|
+
test "GET /auth/failure" do
|
95
|
+
OmniAuth.config.mock_auth[:#{provider}] = :invalid_credentials
|
96
|
+
get "/auth/failure"
|
97
|
+
assert_response :not_authorized
|
98
|
+
end
|
99
|
+
|
100
|
+
CODE
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def reminders
|
105
|
+
say "\nGemfile updated... don't forget to 'bundle install'"
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def gem_name
|
111
|
+
"omniauth-#{provider}"
|
112
|
+
end
|
113
|
+
|
114
|
+
def modular?
|
115
|
+
@modular ||= File.readlines("app.rb").grep(/Sinatra::Base/).any?
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
8
119
|
class Sprockets < Thor::Group
|
9
120
|
include Thor::Actions
|
121
|
+
include Hoboken::Actions
|
10
122
|
|
11
123
|
def self.source_root
|
12
124
|
File.dirname(__FILE__)
|
@@ -19,9 +131,9 @@ module Hoboken
|
|
19
131
|
end
|
20
132
|
|
21
133
|
def add_gems
|
22
|
-
|
23
|
-
|
24
|
-
|
134
|
+
gem "sprockets", "2.10.0", group: :assets
|
135
|
+
gem "uglifier", "2.1.1", group: :assets
|
136
|
+
gem "yui-compressor", "0.9.6", group: :assets
|
25
137
|
end
|
26
138
|
|
27
139
|
def copy_sprockets_helpers
|
@@ -107,13 +219,14 @@ TEXT
|
|
107
219
|
|
108
220
|
class Heroku < Thor::Group
|
109
221
|
include Thor::Actions
|
222
|
+
include Hoboken::Actions
|
110
223
|
|
111
224
|
def self.source_root
|
112
225
|
File.dirname(__FILE__)
|
113
226
|
end
|
114
227
|
|
115
228
|
def add_gem
|
116
|
-
|
229
|
+
gem "foreman", "0.63.0", group: :development
|
117
230
|
end
|
118
231
|
|
119
232
|
def procfile
|
@@ -157,13 +270,14 @@ TASK
|
|
157
270
|
|
158
271
|
class Internationalization < Thor::Group
|
159
272
|
include Thor::Actions
|
273
|
+
include Hoboken::Actions
|
160
274
|
|
161
275
|
def self.source_root
|
162
276
|
File.dirname(__FILE__)
|
163
277
|
end
|
164
278
|
|
165
279
|
def add_gem
|
166
|
-
|
280
|
+
gem "sinatra-r18n", "1.1.5"
|
167
281
|
insert_into_file("app.rb", after: /require "sinatra("|\/base")/) do
|
168
282
|
"\nrequire \"sinatra/r18n\""
|
169
283
|
end
|
@@ -184,15 +298,16 @@ TASK
|
|
184
298
|
|
185
299
|
class Metrics < Thor::Group
|
186
300
|
include Thor::Actions
|
301
|
+
include Hoboken::Actions
|
187
302
|
|
188
303
|
def self.source_root
|
189
304
|
File.dirname(__FILE__)
|
190
305
|
end
|
191
306
|
|
192
307
|
def add_gems
|
193
|
-
|
194
|
-
|
195
|
-
|
308
|
+
gem "flog", "2.5.3", group: :test
|
309
|
+
gem "flay", "1.4.3", group: :test
|
310
|
+
gem "simplecov", "0.7.1", require: false, group: :test
|
196
311
|
end
|
197
312
|
|
198
313
|
def copy_task_templates
|
@@ -231,6 +346,7 @@ CODE
|
|
231
346
|
register(Metrics, "add:metrics", "add:metrics", "Add metrics (flog, flay, simplecov)")
|
232
347
|
register(Internationalization, "add:i18n", "add:i18n", "Internationalization support using sinatra-r18n")
|
233
348
|
register(Heroku, "add:heroku", "add:heroku", "Heroku deployment support")
|
349
|
+
register(OmniAuth, "add:omniauth", "add:omniauth", "OmniAuth authentication (allows you to select a provider)")
|
234
350
|
register(Sprockets, "add:sprockets", "add:sprockets", "Rack-based asset packaging system")
|
235
351
|
end
|
236
352
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Hoboken
|
2
|
+
module Actions
|
3
|
+
def gem(name, version, opts={})
|
4
|
+
verbose = opts.has_key?(:verbose) ? opts.delete(:verbose) : true
|
5
|
+
|
6
|
+
parts = [name.inspect, "~> #{version}".inspect]
|
7
|
+
opts.each { |k, v| parts << "#{k}: #{v.inspect}" }
|
8
|
+
|
9
|
+
append_file("Gemfile", "\ngem #{parts.join(", ")}", verbose: verbose)
|
10
|
+
end
|
11
|
+
|
12
|
+
def indent(text, num_spaces)
|
13
|
+
text.gsub(/^/, 1.upto(num_spaces).map { |n| " " }.join)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -29,6 +29,30 @@ module Rack::Test::Assertions
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
def assert_has_session(message=nil)
|
33
|
+
msg = build_message(message, "expected a valid session")
|
34
|
+
assert_block(msg) do
|
35
|
+
last_request.env["rack.session"]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def assert_session_has_key(key, message=nil)
|
40
|
+
assert_has_session
|
41
|
+
msg = build_message(message, "expected session to have key named <?>", key)
|
42
|
+
assert_block(msg) do
|
43
|
+
last_request.env["rack.session"].keys.include?(key)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def assert_session(key, expected, message=nil)
|
48
|
+
assert_session_has_key(key)
|
49
|
+
actual = last_request.env["rack.session"][key]
|
50
|
+
msg = build_message(message, "expected session key <?> to be <?>, but was <?>", key, expected, actual)
|
51
|
+
assert_block(msg) do
|
52
|
+
expected == actual
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
32
56
|
def assert_response(expected, message=nil)
|
33
57
|
status = last_response.status
|
34
58
|
msg = build_message(
|
data/lib/hoboken/version.rb
CHANGED
@@ -0,0 +1,129 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require_relative "../../lib/hoboken/actions.rb"
|
3
|
+
|
4
|
+
module Hoboken
|
5
|
+
require "thor"
|
6
|
+
class Target < Thor::Group
|
7
|
+
include Thor::Actions
|
8
|
+
include Hoboken::Actions
|
9
|
+
end
|
10
|
+
|
11
|
+
class GemActionsTest < Test::Unit::TestCase
|
12
|
+
attr_reader :gemfile_path, :gemfile, :target
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@gemfile_path = File.join("test", "fixtures")
|
16
|
+
@gemfile = File.join(gemfile_path, "Gemfile")
|
17
|
+
@target = Target.new([], {}, destination_root: gemfile_path)
|
18
|
+
FileUtils.copy(File.join(gemfile_path, "Gemfile.pristine"), gemfile)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_gem_appends_to_gemfile
|
22
|
+
target.gem "sinatra", "1.4.4", verbose: false
|
23
|
+
expected =
|
24
|
+
"source \"https://rubygems.org\"\n" +
|
25
|
+
"ruby \"2.0.0\"\n\n" +
|
26
|
+
"gem \"sinatra\", \"~> 1.4.4\""
|
27
|
+
|
28
|
+
assert_equal(expected, File.read(gemfile))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_gem_with_group
|
32
|
+
target.gem "sinatra", "1.4.4", group: :test, verbose: false
|
33
|
+
expected =
|
34
|
+
"source \"https://rubygems.org\"\n" +
|
35
|
+
"ruby \"2.0.0\"\n\n" +
|
36
|
+
"gem \"sinatra\", \"~> 1.4.4\", group: :test"
|
37
|
+
|
38
|
+
assert_equal(expected, File.read(gemfile))
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_gem_with_multiple_groups
|
42
|
+
target.gem "sinatra", "1.4.4", group: [:test, :development], verbose: false
|
43
|
+
expected =
|
44
|
+
"source \"https://rubygems.org\"\n" +
|
45
|
+
"ruby \"2.0.0\"\n\n" +
|
46
|
+
"gem \"sinatra\", \"~> 1.4.4\", group: [:test, :development]"
|
47
|
+
|
48
|
+
assert_equal(expected, File.read(gemfile))
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_gem_with_require
|
52
|
+
target.gem "sinatra", "1.4.4", require: false, verbose: false
|
53
|
+
expected =
|
54
|
+
"source \"https://rubygems.org\"\n" +
|
55
|
+
"ruby \"2.0.0\"\n\n" +
|
56
|
+
"gem \"sinatra\", \"~> 1.4.4\", require: false"
|
57
|
+
|
58
|
+
assert_equal(expected, File.read(gemfile))
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_gem_with_require_and_group
|
62
|
+
target.gem "sinatra", "1.4.4", require: false, group: :test, verbose: false
|
63
|
+
expected =
|
64
|
+
"source \"https://rubygems.org\"\n" +
|
65
|
+
"ruby \"2.0.0\"\n\n" +
|
66
|
+
"gem \"sinatra\", \"~> 1.4.4\", require: false, group: :test"
|
67
|
+
|
68
|
+
assert_equal(expected, File.read(gemfile))
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_gem_with_require_and_multiple_groups
|
72
|
+
target.gem "sinatra", "1.4.4", require: false, group: [:test, :development], verbose: false
|
73
|
+
expected =
|
74
|
+
"source \"https://rubygems.org\"\n" +
|
75
|
+
"ruby \"2.0.0\"\n\n" +
|
76
|
+
"gem \"sinatra\", \"~> 1.4.4\", require: false, group: [:test, :development]"
|
77
|
+
|
78
|
+
assert_equal(expected, File.read(gemfile))
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_gem_multiple
|
82
|
+
target.gem "sinatra", "1.4.4", verbose: false
|
83
|
+
target.gem "thin", "1.4.4", verbose: false
|
84
|
+
expected =
|
85
|
+
"source \"https://rubygems.org\"\n" +
|
86
|
+
"ruby \"2.0.0\"\n\n" +
|
87
|
+
"gem \"sinatra\", \"~> 1.4.4\"\n" +
|
88
|
+
"gem \"thin\", \"~> 1.4.4\""
|
89
|
+
|
90
|
+
assert_equal(expected, File.read(gemfile))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class IndentActionsTest < Test::Unit::TestCase
|
95
|
+
attr_reader :text, :target
|
96
|
+
|
97
|
+
def setup
|
98
|
+
@target = Target.new
|
99
|
+
@text = <<-TEXT
|
100
|
+
|
101
|
+
This is some
|
102
|
+
text that needs
|
103
|
+
to be indented.
|
104
|
+
TEXT
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_indent_with_one_space
|
108
|
+
expected = <<-TEXT
|
109
|
+
|
110
|
+
This is some
|
111
|
+
text that needs
|
112
|
+
to be indented.
|
113
|
+
TEXT
|
114
|
+
|
115
|
+
assert_equal(expected, target.indent(text, 1))
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_indent_with_two_spaces
|
119
|
+
expected = <<-TEXT
|
120
|
+
|
121
|
+
This is some
|
122
|
+
text that needs
|
123
|
+
to be indented.
|
124
|
+
TEXT
|
125
|
+
|
126
|
+
assert_equal(expected, target.indent(text, 2))
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoboken
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Nadler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- bin/hoboken
|
69
69
|
- hoboken.gemspec
|
70
70
|
- lib/hoboken.rb
|
71
|
+
- lib/hoboken/actions.rb
|
71
72
|
- lib/hoboken/generate.rb
|
72
73
|
- lib/hoboken/templates/Gemfile.erb.tt
|
73
74
|
- lib/hoboken/templates/README.md.tt
|
@@ -91,6 +92,9 @@ files:
|
|
91
92
|
- lib/hoboken/templates/views/index.erb.tt
|
92
93
|
- lib/hoboken/templates/views/layout.erb.tt
|
93
94
|
- lib/hoboken/version.rb
|
95
|
+
- test/fixtures/Gemfile
|
96
|
+
- test/fixtures/Gemfile.pristine
|
97
|
+
- test/unit/hoboken_actions_test.rb
|
94
98
|
homepage: https://github.com/bnadlerjr/hoboken
|
95
99
|
licenses:
|
96
100
|
- MIT
|
@@ -115,4 +119,7 @@ rubygems_version: 2.0.3
|
|
115
119
|
signing_key:
|
116
120
|
specification_version: 4
|
117
121
|
summary: Sinatra project generator.
|
118
|
-
test_files:
|
122
|
+
test_files:
|
123
|
+
- test/fixtures/Gemfile
|
124
|
+
- test/fixtures/Gemfile.pristine
|
125
|
+
- test/unit/hoboken_actions_test.rb
|