hoboken 0.0.1.beta

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f1a0724865d4b6998165c52a8e631a96f43f636
4
+ data.tar.gz: e76a4320fb46db77356346d6d5fa905c7c9b0f13
5
+ SHA512:
6
+ metadata.gz: bd597e454af06c4981761c4d46541d67c54febbd53defb223d07ff958f8df5f0b3357f667ae0577f201bc5d5f84d4743cae1f4fed8084039707b52b4c77b6f51
7
+ data.tar.gz: 15ae3353f633cbcbbb1b362381809beb38729d7df2aa26b4f5e6302083bb3fb7f6297e50022959915890c4420b87f72892609cba0efafa02ed058e5c7751c507
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hoboken.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Bob Nadler
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,52 @@
1
+ # Hoboken
2
+
3
+ [![Dependency Status](https://gemnasium.com/bnadlerjr/hoboken.png)](https://gemnasium.com/bnadlerjr/hoboken)
4
+
5
+ Generate Sinatra project templates.
6
+
7
+ ## Installation
8
+
9
+ $ gem install hoboken
10
+
11
+ ## Usage
12
+
13
+ To see a list of available commands:
14
+
15
+ $ hoboken
16
+
17
+ Generating a new project:
18
+
19
+ $ hoboken generate [APP_NAME] [OPTIONS]
20
+
21
+ To see a list of options for the generate command:
22
+
23
+ $ hoboken help generate
24
+ Usage:
25
+ hoboken generate [APP_NAME]
26
+
27
+ Options:
28
+ [--ruby-version=RUBY_VERSION] # Ruby version for Gemfile
29
+ # Default: 2.0.0
30
+ [--tiny] # Generate views inline; do not create /public folder
31
+ [--type=TYPE] # Architecture type (classic or modular)
32
+ # Default: classic
33
+ [--git] # Create a Git repository and make initial commit
34
+
35
+ Generate a new Sinatra app
36
+
37
+ ### Additional Generators
38
+
39
+ Additional generators are available for existing projects generated using Hoboken:
40
+
41
+ $ hoboken add:metrics # Add Rake tasks for metrics (flog, flay, simplecov)
42
+ $ hoboken add:i18n # Internationalization support using sinatra-r18n
43
+ $ hoboken add:heroku # Heroku deployment support
44
+ $ hoboken add:sprockets # Rack-based asset packaging system
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/hoboken ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), "../lib/hoboken")
4
+ Hoboken::CLI.start(ARGV)
data/hoboken.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hoboken/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hoboken"
8
+ spec.version = Hoboken::VERSION
9
+ spec.authors = ["Bob Nadler"]
10
+ spec.email = ["bnadlerjr@gmail.com"]
11
+ spec.description = %q{Sinatra project generator.}
12
+ spec.summary = %q{Sinatra project generator.}
13
+ spec.homepage = "https://github.com/bnadlerjr/hoboken"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake", "~> 10.1.0"
23
+
24
+ spec.add_dependency "thor", "~> 0.18.1"
25
+ end
data/lib/hoboken.rb ADDED
@@ -0,0 +1,236 @@
1
+ require "thor"
2
+ require "thor/util"
3
+ require "fileutils"
4
+ require_relative "hoboken/version"
5
+ require_relative "hoboken/generate"
6
+
7
+ module Hoboken
8
+ class Sprockets < Thor::Group
9
+ include Thor::Actions
10
+
11
+ def self.source_root
12
+ File.dirname(__FILE__)
13
+ end
14
+
15
+ def create_assets_folder
16
+ empty_directory("assets")
17
+ FileUtils.cp("public/css/styles.css", "assets/styles.css")
18
+ FileUtils.cp("public/js/app.js", "assets/app.js")
19
+ end
20
+
21
+ def add_gems
22
+ append_file("Gemfile", "\ngem \"sprockets\", \"~> 2.10.0\", group: :assets")
23
+ append_file("Gemfile", "\ngem \"uglifier\", \"~> 2.1.1\", group: :assets")
24
+ append_file("Gemfile", "\ngem \"yui-compressor\", \"~> 0.9.6\", group: :assets")
25
+ end
26
+
27
+ def copy_sprockets_helpers
28
+ copy_file("hoboken/templates/sprockets.rake", "tasks/sprockets.rake")
29
+ copy_file("hoboken/templates/sprockets_chain.rb", "middleware/sprockets_chain.rb")
30
+ copy_file("hoboken/templates/sprockets_helper.rb", "helpers/sprockets.rb")
31
+ end
32
+
33
+ def update_app
34
+ insert_into_file("app.rb", after: /configure :development do\n/) do
35
+ <<CODE
36
+ require File.expand_path('middleware/sprockets_chain', settings.root)
37
+ use Middleware::SprocketsChain, %r{/assets} do |env|
38
+ %w(assets vendor).each do |f|
39
+ env.append_path File.expand_path("../\#{f}", __FILE__)
40
+ end
41
+ end
42
+
43
+ CODE
44
+ end
45
+
46
+ insert_into_file("app.rb", after: /set :root, File.dirname\(__FILE__\)\n/) do
47
+ " helpers Helpers::Sprockets"
48
+ end
49
+
50
+ gsub_file("app.rb", /require "sinatra\/reloader" if development\?/) do
51
+ <<CODE
52
+ if development?
53
+ require "sinatra/reloader"
54
+
55
+ require File.expand_path('middleware/sprockets_chain', settings.root)
56
+ use Middleware::SprocketsChain, %r{/assets} do |env|
57
+ %w(assets vendor).each do |f|
58
+ env.append_path File.expand_path("../\#{f}", __FILE__)
59
+ end
60
+ end
61
+ end
62
+
63
+ helpers Helpers::Sprockets
64
+ CODE
65
+ end
66
+ end
67
+
68
+ def adjust_link_tags
69
+ insert_into_file("views/layout.erb", before: /<\/head>/) do
70
+ <<HTML
71
+ <%= stylesheet_tag :styles %>
72
+
73
+ <%= javascript_tag :app %>
74
+ HTML
75
+ end
76
+
77
+ gsub_file("views/layout.erb", /<link rel="stylesheet" type="text\/css" href="css\/styles.css">/, "")
78
+ gsub_file("views/layout.erb", /<script type="text\/javascript" src="js\/app.js"><\/script>/, "")
79
+ end
80
+
81
+ def directions
82
+ text = <<TEXT
83
+
84
+ Run `bundle install` to get the sprockets gem and its
85
+ dependencies.
86
+
87
+ Running the server in development mode will serve css
88
+ and js files from /assets. In order to serve assets in
89
+ production, you must run `rake assets:precompile`. Read
90
+ the important note below before running this rake task.
91
+ TEXT
92
+
93
+ important = <<TEXT
94
+
95
+ Important Note:
96
+ Any css or js files from the /public folder have been copied
97
+ to /assets, the original files remain intact in /public, but
98
+ will be replaced the first time you run `rake assets:precompile`.
99
+ You may want to backup those files if they are not under source
100
+ control before running the Rake command.
101
+ TEXT
102
+
103
+ say text
104
+ say important, :red
105
+ end
106
+ end
107
+
108
+ class Heroku < Thor::Group
109
+ include Thor::Actions
110
+
111
+ def self.source_root
112
+ File.dirname(__FILE__)
113
+ end
114
+
115
+ def add_gem
116
+ append_file("Gemfile", "\ngem \"foreman\", \"~> 0.63.0\", group: :development")
117
+ end
118
+
119
+ def procfile
120
+ create_file("Procfile") do
121
+ "web: bundle exec thin start -p $PORT -e $RACK_ENV"
122
+ end
123
+ end
124
+
125
+ def env_file
126
+ create_file(".env") do
127
+ "RACK_ENV=development\nPORT=9292"
128
+ end
129
+ append_to_file(".gitignore", ".env") if File.exist?(".gitignore")
130
+ end
131
+
132
+ def slugignore
133
+ create_file(".slugignore") do
134
+ "tags\n/test\n/tmp"
135
+ end
136
+ end
137
+
138
+ def fix_stdout_for_logging
139
+ prepend_file("config.ru", "$stdout.sync = true\n")
140
+ end
141
+
142
+ def replace_server_rake_task
143
+ gsub_file("Rakefile", /desc.*server.*{rack_env}"\)\nend$/m) do
144
+ <<TASK
145
+ desc "Start the development server with Foreman"
146
+ task :server do
147
+ exec("foreman start")
148
+ end
149
+ TASK
150
+ end
151
+ end
152
+
153
+ def reminders
154
+ say "\nGemfile updated... don't forget to 'bundle install'"
155
+ end
156
+ end
157
+
158
+ class Internationalization < Thor::Group
159
+ include Thor::Actions
160
+
161
+ def self.source_root
162
+ File.dirname(__FILE__)
163
+ end
164
+
165
+ def add_gem
166
+ append_file("Gemfile", "\ngem \"sinatra-r18n\", \"~> 1.1.5\"")
167
+ insert_into_file("app.rb", after: /require "sinatra("|\/base")/) do
168
+ "\nrequire \"sinatra/r18n\""
169
+ end
170
+ insert_into_file("app.rb", after: /Sinatra::Base/) do
171
+ "\n register Sinatra::R18n"
172
+ end
173
+ end
174
+
175
+ def translations
176
+ empty_directory("i18n")
177
+ template("hoboken/templates/en.yml.tt", "i18n/en.yml")
178
+ end
179
+
180
+ def reminders
181
+ say "\nGemfile updated... don't forget to 'bundle install'"
182
+ end
183
+ end
184
+
185
+ class Metrics < Thor::Group
186
+ include Thor::Actions
187
+
188
+ def self.source_root
189
+ File.dirname(__FILE__)
190
+ end
191
+
192
+ def add_gems
193
+ append_file("Gemfile", "\ngem \"flog\", \"~> 2.5.3\", group: :test")
194
+ append_file("Gemfile", "\ngem \"flay\", \"~> 1.4.3\", group: :test")
195
+ append_file("Gemfile", "\ngem \"simplecov\", \"~> 0.7.1\", require: false, group: :test")
196
+ end
197
+
198
+ def copy_task_templates
199
+ empty_directory("tasks")
200
+ template("hoboken/templates/metrics.rake.tt", "tasks/metrics.rake")
201
+ end
202
+
203
+ def simplecov_snippet
204
+ insert_into_file "test/unit/test_helper.rb", before: /require "test\/unit"/ do
205
+ <<CODE
206
+
207
+ require 'simplecov'
208
+ SimpleCov.start do
209
+ add_filter "/test/"
210
+ coverage_dir 'tmp/coverage'
211
+ end
212
+
213
+ CODE
214
+ end
215
+ end
216
+
217
+ def reminders
218
+ say "\nGemfile updated... don't forget to 'bundle install'"
219
+ end
220
+ end
221
+
222
+ class CLI < Thor
223
+ desc "version", "Print version and quit"
224
+ def version
225
+ puts "Hoboken v#{Hoboken::VERSION}"
226
+ end
227
+
228
+ register(Generate, "generate", "generate [APP_NAME]", "Generate a new Sinatra app")
229
+ tasks["generate"].options = Hoboken::Generate.class_options
230
+
231
+ register(Metrics, "add:metrics", "add:metrics", "Add metrics (flog, flay, simplecov)")
232
+ register(Internationalization, "add:i18n", "add:i18n", "Internationalization support using sinatra-r18n")
233
+ register(Heroku, "add:heroku", "add:heroku", "Heroku deployment support")
234
+ register(Sprockets, "add:sprockets", "add:sprockets", "Rack-based asset packaging system")
235
+ end
236
+ end
@@ -0,0 +1,133 @@
1
+ require "rbconfig"
2
+
3
+ module Hoboken
4
+ class Generate < Thor::Group
5
+ include Thor::Actions
6
+
7
+ NULL = RbConfig::CONFIG['host_os'] =~ /mingw|mswin/ ? 'NUL' : '/dev/null'
8
+
9
+ argument :name
10
+
11
+ class_option :ruby_version,
12
+ type: :string,
13
+ desc: "Ruby version for Gemfile",
14
+ default: RUBY_VERSION
15
+
16
+ class_option :tiny,
17
+ type: :boolean,
18
+ desc: "Generate views inline; do not create /public folder",
19
+ default: false
20
+
21
+ class_option :type,
22
+ type: :string,
23
+ desc: "Architecture type (classic or modular)",
24
+ default: :classic
25
+
26
+ class_option :git,
27
+ type: :boolean,
28
+ desc: "Create a Git repository and make initial commit",
29
+ default: false
30
+
31
+ def self.source_root
32
+ File.dirname(__FILE__)
33
+ end
34
+
35
+ def app_folder
36
+ empty_directory(snake_name)
37
+ apply_template("classic.rb.tt", "app.rb")
38
+ apply_template("Gemfile.erb.tt", "Gemfile")
39
+ apply_template("config.ru.tt", "config.ru")
40
+ apply_template("README.md.tt", "README.md")
41
+ apply_template("Rakefile.tt", "Rakefile")
42
+ end
43
+
44
+ def view_folder
45
+ empty_directory("#{snake_name}/views")
46
+ apply_template("views/layout.erb.tt", "views/layout.erb")
47
+ apply_template("views/index.erb.tt", "views/index.erb")
48
+ end
49
+
50
+ def inline_views
51
+ return unless options[:tiny]
52
+ combined_views = %w(layout index).map do |f|
53
+ "@@#{f}\n" + File.read("#{snake_name}/views/#{f}.erb")
54
+ end.join("\n")
55
+
56
+ append_to_file("#{snake_name}/app.rb", "\n__END__\n\n#{combined_views}")
57
+ remove_dir("#{snake_name}/views")
58
+ end
59
+
60
+ def public_folder
61
+ return if options[:tiny]
62
+ inside snake_name do
63
+ empty_directory("public")
64
+ %w(css img js).each { |f| empty_directory("public/#{f}") }
65
+ end
66
+ apply_template("styles.css.tt", "public/css/styles.css")
67
+ create_file("#{snake_name}/public/js/app.js", "")
68
+
69
+ %w(favicon hoboken sinatra).each do |f|
70
+ copy_file("templates/#{f}.png", "#{snake_name}/public/img/#{f}.png")
71
+ end
72
+ end
73
+
74
+ def test_folder
75
+ empty_directory("#{snake_name}/test/unit")
76
+ empty_directory("#{snake_name}/test/support")
77
+ apply_template("test/unit/test_helper.rb.tt", "test/unit/test_helper.rb")
78
+ apply_template("test/unit/app_test.rb.tt", "test/unit/app_test.rb")
79
+ apply_template("test/support/rack_test_assertions.rb.tt", "test/support/rack_test_assertions.rb")
80
+ end
81
+
82
+ def make_modular
83
+ return unless "modular" == options[:type]
84
+ empty_directory("#{snake_name}/helpers")
85
+ remove_file("#{snake_name}/app.rb")
86
+ apply_template("modular.rb.tt", "app.rb")
87
+ ["config.ru", "test/unit/test_helper.rb"].each do |f|
88
+ path = File.join(snake_name, f)
89
+ gsub_file(path, /Sinatra::Application/, "#{camel_name}::App")
90
+ end
91
+ end
92
+
93
+ def create_git_repository
94
+ return unless options[:git]
95
+ if system("git --version >#{NULL} 2>&1")
96
+ copy_file("templates/gitignore", "#{snake_name}/.gitignore")
97
+ inside snake_name do
98
+ run("git init .")
99
+ run("git add .")
100
+ run("git commit -m \"Initial commit.\"")
101
+ end
102
+ else
103
+ say "\nYou asked that a Git repository be created for the project, but no Git executable could be found."
104
+ end
105
+ end
106
+
107
+ def directions
108
+ say "\nSuccessfully created #{name}. Don't forget to `bundle install`"
109
+ end
110
+
111
+ private
112
+
113
+ def snake_name
114
+ Thor::Util.snake_case(name)
115
+ end
116
+
117
+ def camel_name
118
+ Thor::Util.camel_case(name)
119
+ end
120
+
121
+ def titleized_name
122
+ snake_name.split("_").map(&:capitalize).join(" ")
123
+ end
124
+
125
+ def author
126
+ `git config user.name`.chomp
127
+ end
128
+
129
+ def apply_template(src, dest)
130
+ template("templates/#{src}", "#{snake_name}/#{dest}")
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+ ruby "<%= options[:ruby_version] %>"
3
+
4
+ gem "rack_csrf", "~> 2.4.0"
5
+ gem "sinatra", "~> 1.4.3"
6
+ gem "thin", "~> 1.5.1"
7
+
8
+ group :development do
9
+ gem "rake", "~> 10.1.0"
10
+ gem "sinatra-reloader", "~> 1.0"
11
+ end
12
+
13
+ group :test do
14
+ gem "contest", "~> 0.1.3"
15
+ end
@@ -0,0 +1,50 @@
1
+ # <%= titleized_name %>
2
+
3
+ TODO: Project description.
4
+
5
+ ## Getting Started
6
+
7
+ ### Starting the Server
8
+
9
+ ### Project Layout
10
+
11
+ ## Notes / Use
12
+
13
+ ## Contributing
14
+
15
+ ### Issues / Roadmap
16
+
17
+ Use GitHub issues for reporting bug and feature requests.
18
+
19
+ ### Patches / Pull Requests
20
+ * Fork the project.
21
+ * Make your feature addition or bug fix.
22
+ * Add tests for it. This is important so I don’t break it in a future version
23
+ unintentionally.
24
+ * Commit, do not mess with Rakefile, version, or history (if you want to have
25
+ your own version, that is fine but bump version in a commit by itself I can
26
+ ignore when I pull).
27
+ * Send me a pull request. Bonus points for topic branches.
28
+
29
+ ## License
30
+ (The MIT License)
31
+
32
+ Copyright (c) <%= Date.today.year %> <%= author %>
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining a copy
35
+ of this software and associated documentation files (the "Software"), to deal
36
+ in the Software without restriction, including without limitation the rights
37
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38
+ copies of the Software, and to permit persons to whom the Software is
39
+ furnished to do so, subject to the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be included in
42
+ all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
50
+ SOFTWARE.
@@ -0,0 +1,23 @@
1
+ require "rake/testtask"
2
+
3
+ task :default => "test:all"
4
+
5
+ # Import any external rake tasks
6
+ Dir.glob('tasks/*.rake').each { |r| import r }
7
+
8
+ desc "Start the development server"
9
+ task :server do
10
+ port = ENV["PORT"] || 9292
11
+ rack_env = ENV["RACK_ENV"] || "development"
12
+ exec("bundle exec thin start -p #{port} -e #{rack_env}")
13
+ end
14
+
15
+ namespace :test do
16
+ Rake::TestTask.new(:unit) do |t|
17
+ t.libs << 'test/unit'
18
+ t.test_files = Dir["test/unit/**/*_test.rb"]
19
+ end
20
+
21
+ desc "Run all tests"
22
+ task :all => %w[test:unit]
23
+ end
@@ -0,0 +1,15 @@
1
+ require "sinatra"
2
+ require "rack/csrf"
3
+
4
+ Dir.glob(File.join("helpers", "**", "*.rb")).each do |helper|
5
+ require_relative helper
6
+ end
7
+
8
+ require "sinatra/reloader" if development?
9
+
10
+ use Rack::Session::Cookie, :secret => "TODO: CHANGE ME"
11
+ use Rack::Csrf, :raise => true
12
+
13
+ get "/" do
14
+ erb :index
15
+ end
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+ require File.expand_path("../app", __FILE__)
3
+ run Sinatra::Application
@@ -0,0 +1 @@
1
+ message: Some message text.
Binary file
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ .bundle
3
+ /tmp
4
+ tags
Binary file
@@ -0,0 +1,37 @@
1
+ unless 'production' == ENV['RACK_ENV']
2
+ require 'flay'
3
+ desc "Analyze code for structural similarities"
4
+ task :flay do
5
+ flay = Flay.new
6
+ files = FileList["app.rb", "app/**/*.rb"]
7
+ flay.process(*files)
8
+ threshold = 200
9
+
10
+ if flay.total > threshold
11
+ puts flay.report
12
+ raise "Flay total too high! #{flay.total} > #{threshold}"
13
+ end
14
+ end
15
+
16
+ require "flog"
17
+ desc 'Analyze code complexity'
18
+ task :flog do
19
+ flog = Flog.new
20
+ flog.flog FileList["app.rb", "app/**/*.rb"]
21
+ threshold = 50
22
+
23
+ bad_methods = flog.totals.select do |name, score|
24
+ score > threshold
25
+ end
26
+
27
+ bad_methods.sort do |a, b|
28
+ a[1] <=> b[1]
29
+ end.each do |name, score|
30
+ puts "%8.1f: %s" % [score, name]
31
+ end
32
+
33
+ unless bad_methods.empty?
34
+ raise "#{bad_methods.size} methods have a flog complexity > #{threshold}"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ require "sinatra/base"
2
+ require "rack/csrf"
3
+
4
+ Dir.glob(File.join("helpers", "**", "*.rb")).each do |helper|
5
+ require_relative helper
6
+ end
7
+
8
+ module <%= camel_name %>
9
+ class App < Sinatra::Base
10
+ set :root, File.dirname(__FILE__)
11
+
12
+ enable :logging
13
+
14
+ use Rack::Session::Cookie, :secret => "TODO: CHANGE ME"
15
+ use Rack::Csrf, :raise => true
16
+
17
+ configure :development do
18
+ require "sinatra/reloader"
19
+ register Sinatra::Reloader
20
+ end
21
+
22
+ get "/" do
23
+ erb :index
24
+ end
25
+ end
26
+ end
Binary file
@@ -0,0 +1,33 @@
1
+ namespace :assets do
2
+ require 'sprockets'
3
+ require 'uglifier'
4
+ require 'yui/compressor'
5
+ sprockets = Sprockets::Environment.new { |env| env.logger = Logger.new(STDOUT) }
6
+ sprockets.css_compressor = YUI::CssCompressor.new
7
+ sprockets.js_compressor = :uglifier
8
+
9
+ %w(assets vendor).each do |f|
10
+ sprockets.append_path File.expand_path("../../#{f}", __FILE__)
11
+ end
12
+
13
+ output_path = File.expand_path('../../public', __FILE__)
14
+
15
+ task :precompile_css do
16
+ asset = sprockets['styles.css']
17
+ outfile = Pathname.new(output_path).join('css/styles.css')
18
+ FileUtils.mkdir_p outfile.dirname
19
+ asset.write_to(outfile)
20
+ puts "successfully compiled css assets"
21
+ end
22
+
23
+ task :precompile_js do
24
+ asset = sprockets['app.js']
25
+ outfile = Pathname.new(output_path).join('js/app.js')
26
+ FileUtils.mkdir_p outfile.dirname
27
+ asset.write_to(outfile)
28
+ puts "successfully compiled javascript assets"
29
+ end
30
+
31
+ desc 'precompile all assets'
32
+ task :precompile => [:precompile_css, :precompile_js]
33
+ end
@@ -0,0 +1,26 @@
1
+ require 'sprockets'
2
+
3
+ module Middleware
4
+ class SprocketsChain
5
+ attr_reader :app, :prefix, :sprockets
6
+
7
+ def initialize(app, prefix)
8
+ @app = app
9
+ @prefix = prefix
10
+ @sprockets = Sprockets::Environment.new
11
+ yield sprockets if block_given?
12
+ end
13
+
14
+ def call(env)
15
+ path_info = env["PATH_INFO"]
16
+ if path_info =~ prefix
17
+ env["PATH_INFO"].sub!(prefix, "")
18
+ sprockets.call(env)
19
+ else
20
+ app.call(env)
21
+ end
22
+ ensure
23
+ env["PATH_INFO"] = path_info
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ module Helpers
2
+ module Sprockets
3
+ def stylesheet_tag(name)
4
+ folder = 'production' == ENV['RACK_ENV'] ? 'css' : 'assets'
5
+ "<link href='/#{folder}/#{name}.css' rel='stylesheet' type='text/css' />"
6
+ end
7
+
8
+ def javascript_tag(name)
9
+ folder = 'production' == ENV['RACK_ENV'] ? 'js' : 'assets'
10
+ "<script type='text/javascript' src='/#{folder}/#{name}.js'></script>"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,50 @@
1
+ body {
2
+ font-family: 'lucida console', monaco, 'andale mono', 'bitstream vera sans mono', monospace;
3
+ font-size: 18px;
4
+ color: #262626;
5
+ margin: 2em;
6
+ }
7
+ h1, h2, h3, h4 {
8
+ font-family: Georgia, 'bitstream vera serif', serif;
9
+ }
10
+ h1 {
11
+ text-indent: 100%;
12
+ white-space: nowrap;
13
+ overflow: hidden;
14
+ line-height: 0;
15
+ margin: 0;
16
+ }
17
+ ul {
18
+ list-style: none;
19
+ }
20
+ table {
21
+ margin-left: 1em;
22
+ }
23
+ th:before {
24
+ content: "# => ";
25
+ }
26
+ th {
27
+ font-weight: normal;
28
+ text-align: left;
29
+ color: #515151;
30
+ padding-left: 2em;
31
+ }
32
+ th, td {
33
+ vertical-align: top;
34
+ }
35
+ a {
36
+ font-weight: bold;
37
+ color: #324d0e;
38
+ }
39
+ footer {
40
+ margin-top: 2em;
41
+ text-align: center;
42
+ }
43
+ .wrapper {
44
+ background: url("../img/sinatra.png") no-repeat bottom right;
45
+ width: 1280px;
46
+ margin: 0 auto;
47
+ }
48
+ .main {
49
+ width: 640px;
50
+ }
@@ -0,0 +1,55 @@
1
+ module Rack::Test::Assertions
2
+ RESPONSE_CODES = {
3
+ :ok => 200,
4
+ :not_authorized => 401,
5
+ :not_found => 404,
6
+ :redirect => 302
7
+ }
8
+
9
+ def assert_body_contains(expected, message=nil)
10
+ msg = build_message(message, "expected body to contain <?>\n#{last_response.body}", expected)
11
+ assert_block(msg) do
12
+ last_response.body.include?(expected)
13
+ end
14
+ end
15
+
16
+ def assert_flash(type=:notice, message=nil)
17
+ msg = build_message(message, "expected <?> flash to exist, but was nil", type.to_s)
18
+ assert_block(msg) do
19
+ last_request.env['rack.session']['flash']
20
+ end
21
+ end
22
+
23
+ def assert_flash_message(expected, type=:notice, message=nil)
24
+ assert_flash(type, message)
25
+ flash = last_request.env['rack.session']['flash'][type.to_s]
26
+ msg = build_message(message, "expected flash to be <?> but was <?>", expected, flash)
27
+ assert_block(msg) do
28
+ expected == flash
29
+ end
30
+ end
31
+
32
+ def assert_response(expected, message=nil)
33
+ status = last_response.status
34
+ msg = build_message(
35
+ message,
36
+ "expected last response to be <?> but was <?>",
37
+ "#{RESPONSE_CODES[expected]}:#{expected}",
38
+ "#{status}:#{RESPONSE_CODES.key(status)}"
39
+ )
40
+
41
+ assert_block(msg) do
42
+ status == RESPONSE_CODES[expected]
43
+ end
44
+ end
45
+
46
+ def assert_redirected_to(expected, msg=nil)
47
+ assert_response(:redirect)
48
+ actual = URI(last_response.location).path
49
+ msg = build_message(message, "expected to be redirected to <?> but was <?>", expected, actual)
50
+
51
+ assert_block(msg) do
52
+ expected == actual
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,8 @@
1
+ require "test_helper"
2
+
3
+ class AppTest < Rack::Test::TestCase
4
+ test "GET /" do
5
+ get "/"
6
+ assert_response :ok
7
+ end
8
+ end
@@ -0,0 +1,36 @@
1
+ ENV["RACK_ENV"] = "test"
2
+
3
+ require "bundler/setup"
4
+ require "test/unit"
5
+ require "contest"
6
+ require "rack/test"
7
+ require_relative "../support/rack_test_assertions"
8
+ require_relative "../../app"
9
+
10
+ class Test::Unit::TestCase
11
+ # Syntactic sugar for defining a memoized helper method.
12
+ def self.let(name, &block)
13
+ ivar = "@#{name}"
14
+ self.class_eval do
15
+ define_method(name) do
16
+ if instance_variable_defined?(ivar)
17
+ instance_variable_get(ivar)
18
+ else
19
+ value = self.instance_eval(&block)
20
+ instance_variable_set(ivar, value)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ class Rack::Test::TestCase < Test::Unit::TestCase
28
+ include Rack::Test::Methods
29
+ include Rack::Test::Assertions
30
+
31
+ private
32
+
33
+ def app
34
+ Sinatra::Application
35
+ end
36
+ end
@@ -0,0 +1,82 @@
1
+ <div class="wrapper">
2
+ <h1>Hoboken</h1>
3
+ <img src="img/hoboken.png" />
4
+ <div class="main">
5
+ <h2>Getting Started</h2>
6
+ <p>Smoke test successful!</p>
7
+ <p>Replace the HTML in this file (located at <code>/views/index.erb</code>) with your own. Define new routes in <code>app.rb</code>.</p>
8
+
9
+ <h3>Project Layout</h3>
10
+ <p>Hoboken has been invoked using the <em><%= options[:type] %></em> option, which has generated the following project structure:</p>
11
+ <table>
12
+ <tr>
13
+ <td>Gemfile</td>
14
+ <th>Your app's dependencies</th>
15
+ </tr>
16
+ <tr>
17
+ <td>README.md</td>
18
+ <th>A sample README</th>
19
+ </tr>
20
+ <tr>
21
+ <td>Rakefile</td>
22
+ <th>Basic app tasks</th>
23
+ </tr>
24
+ <tr>
25
+ <td>app.rb</td>
26
+ <th>The main application file</th>
27
+ </tr>
28
+ <tr>
29
+ <td>config.ru</td>
30
+ <th>Rackup file</th>
31
+ </tr>
32
+ <tr>
33
+ <td>/helpers</td>
34
+ <th>Any helper files</th>
35
+ </tr>
36
+ <tr>
37
+ <td>/public</td>
38
+ <th>Static assets (i.e. css, js, images)</th>
39
+ </tr>
40
+ <tr>
41
+ <td>/test</td>
42
+ <th>Basic unit test and test helper support</th>
43
+ </tr>
44
+ <tr>
45
+ <td>/views</td>
46
+ <th>Your app's views (not present if --tiny option was used)</th>
47
+ </tr>
48
+ </table>
49
+
50
+ <h3>Rake Tasks</h3>
51
+ <p>The following Rake tasks are available:</p>
52
+ <table>
53
+ <tr>
54
+ <td>rake server</td>
55
+ <th>Start the development server</th>
56
+ </tr>
57
+ <tr>
58
+ <td>rake test:all</td>
59
+ <th>Run all tests</th>
60
+ </tr>
61
+ <tr>
62
+ <td>rake test:unit</td>
63
+ <th>Run unit tests</th>
64
+ </tr>
65
+ </table>
66
+
67
+ <h3>Add Ons</h3>
68
+ <p>Several add-ons are available that adjust the project structure to add support for things like i18n, code metrics, Heroku, etc. Run <code>hoboken help</code> from the command line for a complete list.</p>
69
+ </div>
70
+
71
+ <h3>Links</h3>
72
+ <ul>
73
+ <li><a href="https://github.com/bnadlerjr/hoboken">Documentation</a></li>
74
+ <li><a href="https://github.com/bnadlerjr/hoboken">Source Code</a></li>
75
+ </ul>
76
+
77
+ <footer>
78
+ <small>
79
+ <a href="https://github.com/bnadlerjr/hoboken">Hoboken<a/>, a project generator for the Ruby <a href="http://www.sinatrarb.com/">Sinatra</a> library, written by <a href="http://bobnadler.com">Bob Nadler</a>.
80
+ </small>
81
+ </footer>
82
+ </div>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= titleized_name %></title>
5
+ <link rel="icon" type="image/png" href="img/favicon.png" />
6
+ <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/normalize/2.1.3/normalize.min.css">
7
+ <link rel="stylesheet" type="text/css" href="css/styles.css">
8
+ <script type="text/javascript" src="js/app.js"></script>
9
+ </head>
10
+ <body>
11
+ <%%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1,3 @@
1
+ module Hoboken
2
+ VERSION = "0.0.1.beta"
3
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hoboken
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.beta
5
+ platform: ruby
6
+ authors:
7
+ - Bob Nadler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-23 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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.1.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.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.18.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.18.1
55
+ description: Sinatra project generator.
56
+ email:
57
+ - bnadlerjr@gmail.com
58
+ executables:
59
+ - hoboken
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/hoboken
69
+ - hoboken.gemspec
70
+ - lib/hoboken.rb
71
+ - lib/hoboken/generate.rb
72
+ - lib/hoboken/templates/Gemfile.erb.tt
73
+ - lib/hoboken/templates/README.md.tt
74
+ - lib/hoboken/templates/Rakefile.tt
75
+ - lib/hoboken/templates/classic.rb.tt
76
+ - lib/hoboken/templates/config.ru.tt
77
+ - lib/hoboken/templates/en.yml.tt
78
+ - lib/hoboken/templates/favicon.png
79
+ - lib/hoboken/templates/gitignore
80
+ - lib/hoboken/templates/hoboken.png
81
+ - lib/hoboken/templates/metrics.rake.tt
82
+ - lib/hoboken/templates/modular.rb.tt
83
+ - lib/hoboken/templates/sinatra.png
84
+ - lib/hoboken/templates/sprockets.rake
85
+ - lib/hoboken/templates/sprockets_chain.rb
86
+ - lib/hoboken/templates/sprockets_helper.rb
87
+ - lib/hoboken/templates/styles.css.tt
88
+ - lib/hoboken/templates/test/support/rack_test_assertions.rb.tt
89
+ - lib/hoboken/templates/test/unit/app_test.rb.tt
90
+ - lib/hoboken/templates/test/unit/test_helper.rb.tt
91
+ - lib/hoboken/templates/views/index.erb.tt
92
+ - lib/hoboken/templates/views/layout.erb.tt
93
+ - lib/hoboken/version.rb
94
+ homepage: https://github.com/bnadlerjr/hoboken
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>'
110
+ - !ruby/object:Gem::Version
111
+ version: 1.3.1
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.0.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Sinatra project generator.
118
+ test_files: []