frankly 0.1.6 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f8bd4c6d54dc267c2c76c3acda425e4d9e43e7278cdacd11e35c379723a0ce2
4
- data.tar.gz: 9a214222eda89b2edd17e1650a1b2213fba965a337cc2fa09e7991250d5afa2b
3
+ metadata.gz: c0be7eb9681ed289f31a435937341c8a0d9cc0fa13f266bef8bd3023d2ad1884
4
+ data.tar.gz: 4f238519f427acf2af89eb5d2ecbd37d36478b3e3fe41b5f151031c67a4a569d
5
5
  SHA512:
6
- metadata.gz: d9a73f8401b3064f1d5be7cbb23f6d006e1691e177aca6af482325beaaacdc9c0802dce722d32ba9a6d8083d448a3c114c8821a23c54703b407be9929f42753d
7
- data.tar.gz: ed096de42c3d010a099dfd636897c313d4d47624a93a0549f9c3296dd6a393ee338b4c8963e4c06b63c4afe824251918fd83326179db9ba48b311c4109119d96
6
+ metadata.gz: 124f81aaecbcdfda40e14346ac06cd986a4c32b4acd3a6068fb79c0e42f75e2c31dfda53934b90b70b39af2e93cb311913da51860449266c883e2c9cd73bb358
7
+ data.tar.gz: 144171fa85fa8daed017d09a7869deaef6f473176ede2b8bc59ea8009410e4a73342a8fabbe064d01f5ae5c8544e602ddc0fe758a68928a9f5639ac996cd98ff
data/README.md CHANGED
@@ -1,35 +1,69 @@
1
1
  # Frankly
2
- ![Build Status](https://travis-ci.org/kenrett/frankly.svg?branch=master)
3
2
 
4
- An opinionated sinatra app skeleton generator with Rake tasks, rspec, postgres, pry and more!
3
+ `frankly` is a Sinatra starter generator.
4
+
5
+ It creates a PostgreSQL + ActiveRecord app scaffold with a modern Sinatra setup.
6
+
7
+ ## Requirements
8
+
9
+ - Ruby 3.1+
10
+ - PostgreSQL
11
+ - Bundler
5
12
 
6
13
  ## Installation
7
14
 
8
- Type this into the command line:
15
+ ```sh
16
+ gem install frankly
17
+ ```
9
18
 
19
+ ## Usage
20
+
21
+ Generate a new app:
22
+
23
+ ```sh
24
+ frankly my_app
10
25
  ```
11
- gem install frankly
26
+
27
+ ### Options
28
+
29
+ ```sh
30
+ frankly my_app --bundle
31
+ frankly my_app --skip-git
12
32
  ```
13
33
 
14
- ## Dependency
34
+ - `--bundle`: runs `bundle install` in the generated app
35
+ - `--skip-git`: skips `git init`
15
36
 
16
- Frankly is dependent on using postgres as your database. If you don't have it installed, please check out this great blogpost for [OSX](https://launchschool.com/blog/how-to-install-postgresql-on-a-mac) or [Linux](https://launchschool.com/blog/how-to-install-postgres-for-linux) from [LaunchSchool](https://launchschool.com/) on how to get set up!
37
+ ## Generated app quickstart
17
38
 
18
- ## Usage
39
+ ```sh
40
+ cd my_app
41
+ bundle install
42
+ bundle exec rackup
43
+ ```
19
44
 
20
- Simple type `frankly APP_NAME` and frankly will create a sinatra scaffold, git init, and bundle your application. Currently frankly does not support special characters or numbers in an `APP_NAME` but please feel free to make a Pull Request if you would like to contribute!
45
+ Open http://localhost:9292.
21
46
 
22
- ## Development
47
+ ## Development (this gem)
23
48
 
24
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+ ```sh
50
+ bin/setup
51
+ bundle exec rspec
52
+ ```
25
53
 
26
- 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).
54
+ ## Release
27
55
 
28
- ## Contributing
56
+ ```sh
57
+ bundle exec rake build
58
+ bundle exec rake install
59
+ bundle exec rake release
60
+ ```
29
61
 
30
- Bug reports and pull requests are welcome on GitHub at https://github.com/kenrett/frankly. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
62
+ ## Contributing
31
63
 
64
+ Issues and pull requests are welcome at:
65
+ https://github.com/kenrett/frankly
32
66
 
33
67
  ## License
34
68
 
35
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
69
+ MIT. See [LICENSE.txt](LICENSE.txt).
data/frankly.gemspec CHANGED
@@ -1,40 +1,33 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'frankly/version'
5
+ require "frankly/version"
4
6
 
5
7
  Gem::Specification.new do |spec|
6
- spec.name = "frankly"
7
- spec.version = Frankly::VERSION
8
- spec.authors = ["Ken Rettberg"]
9
- spec.email = %q{kenrettberg@gmail.com}
10
- spec.description = %q{Setup a sinatra skeleton like a boss!}
11
- spec.summary = %q{An opinionated sinatra skeleton with Rake tasks, rspec, postgres, and more!}
12
- spec.files = `git ls-files`.split($/)
13
- spec.homepage = %q{https://github.com/kenrett/frankly}
14
- spec.rubygems_version = %q{1.6.2}
15
- spec.license = "MIT"
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- spec.test_files = spec.files.grep(%r{^(spec)/})
18
- spec.require_paths = ["lib"]
8
+ spec.name = "frankly"
9
+ spec.version = Frankly::VERSION
10
+ spec.authors = ["Ken Rettberg"]
11
+ spec.email = ["kenrettberg@gmail.com"]
12
+
13
+ spec.summary = "Opinionated Sinatra app skeleton generator"
14
+ spec.description = "Generate a modern Sinatra + ActiveRecord starter app with sensible defaults."
15
+ spec.homepage = "https://github.com/kenrett/frankly"
16
+ spec.license = "MIT"
17
+ spec.required_ruby_version = ">= 3.1"
19
18
 
20
- spec.post_install_message = <<-PIC
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
21
 
22
- .
23
- .---------.'---.
24
- '. : .'
25
- '. .::: .' The Chairman
26
- '.'::'.' of the Board
27
- '||' has arrived.
28
- ||
29
- ||
30
- ||
31
- ---====---
32
- PIC
22
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.start_with?("spec/") }
23
+ spec.bindir = "bin"
24
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
33
26
 
34
- spec.add_development_dependency "bundler", "~> 1.3"
35
- spec.add_development_dependency "rake", "~> 10.0"
36
- spec.add_development_dependency "rspec"
37
- spec.add_development_dependency "pry-byebug", "~> 3.4"
27
+ spec.add_dependency "thor", "~> 1.3"
38
28
 
39
- spec.add_runtime_dependency 'thor', '~> 0.19.1'
29
+ spec.add_development_dependency "bundler", ">= 2.4"
30
+ spec.add_development_dependency "rake", "~> 13.0"
31
+ spec.add_development_dependency "rspec", "~> 3.13"
32
+ spec.add_development_dependency "pry-byebug", "~> 3.10"
40
33
  end
data/lib/frankly/cli.rb CHANGED
@@ -1,66 +1,84 @@
1
- require 'pathname'
2
- require 'fileutils'
3
- require 'thor'
4
- require 'thor/group'
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "pathname"
5
+ require "thor"
6
+ require "thor/group"
5
7
 
6
8
  module Frankly
7
9
  class CLI < Thor::Group
8
10
  include Thor::Actions
9
11
 
12
+ class_option :bundle, type: :boolean, default: false, desc: "Run bundle install after generation"
13
+ class_option :skip_git, type: :boolean, default: false, desc: "Skip git init"
14
+
15
+ desc "Creates a new Sinatra application"
16
+ argument :name, type: :string, desc: "The name of the new application"
17
+
10
18
  def self.source_root
11
- File.expand_path('../../../templates', __FILE__)
19
+ File.expand_path("../../templates", __dir__)
12
20
  end
13
21
 
14
- desc "Creates a new Sinatra application"
15
- argument :name, :type => :string, :desc => "The name of the new application"
22
+ def self.exit_on_failure?
23
+ true
24
+ end
16
25
 
17
26
  def setup
18
- @app_path = name.downcase.gsub(/[^a-z|\-|\_]/, '')
27
+ @app_path = sanitized_app_path
19
28
  end
20
29
 
21
30
  def create_app_scaffold
22
- empty_directory "#{@app_path}/app"
23
- create_file "#{@app_path}/app/models/.gitkeep"
31
+ raise Thor::Error, "Directory '#{@app_path}' already exists" if File.exist?(@app_path)
32
+
33
+ empty_directory @app_path
34
+ empty_directory "#{@app_path}/app/controllers"
35
+ empty_directory "#{@app_path}/app/helpers"
36
+ empty_directory "#{@app_path}/app/models"
37
+ empty_directory "#{@app_path}/db/migrate"
24
38
  create_file "#{@app_path}/app/controllers/.gitkeep"
25
- create_file "#{@app_path}/app/views/.gitkeep"
26
39
  create_file "#{@app_path}/app/helpers/.gitkeep"
27
- create_file "#{@app_path}/config/.gitkeep"
40
+ create_file "#{@app_path}/app/models/.gitkeep"
28
41
  create_file "#{@app_path}/db/migrate/.gitkeep"
29
- create_file "#{@app_path}/public/css/.gitkeep"
30
- create_file "#{@app_path}/public/js/.gitkeep"
31
42
  end
32
43
 
33
44
  def copy_templates
34
45
  copy_file "app/views/layout.erb", "#{@app_path}/app/views/layout.erb"
46
+ copy_file "app/views/index.erb", "#{@app_path}/app/views/index.erb"
47
+ copy_file "app.rb", "#{@app_path}/app.rb"
35
48
  copy_file "config.ru", "#{@app_path}/config.ru"
36
49
  copy_file "Rakefile", "#{@app_path}/Rakefile"
37
50
  copy_file "config/database.rb", "#{@app_path}/config/database.rb"
38
51
  copy_file "config/environment.rb", "#{@app_path}/config/environment.rb"
39
52
  copy_file "db/seeds.rb", "#{@app_path}/db/seeds.rb"
40
53
  copy_file "README.md", "#{@app_path}/README.md"
41
- copy_file "Gemfile", "#{@app_path}/Gemfile"
54
+ template "Gemfile.tt", "#{@app_path}/Gemfile"
55
+ template "gitignore.tt", "#{@app_path}/.gitignore"
42
56
  copy_file "public/css/application.css", "#{@app_path}/public/css/application.css"
43
- copy_file "public/css/normalize.css", "#{@app_path}/public/css/normalize.css"
44
57
  copy_file "public/js/application.js", "#{@app_path}/public/js/application.js"
45
58
  copy_file "public/favicon.ico", "#{@app_path}/public/favicon.ico"
46
59
  end
47
60
 
48
61
  def initialize_git_repo
49
- puts "about to run git init"
50
- inside(@app_path) do
51
- run('git init .')
52
- end
62
+ return if options[:skip_git]
63
+
64
+ inside(@app_path) { run("git init .") }
53
65
  end
54
66
 
55
67
  def install_dependencies
56
- puts "installing dependencies"
57
- inside(@app_path) do
58
- run('bundle')
59
- end
68
+ return unless options[:bundle]
69
+
70
+ inside(@app_path) { run("bundle install") }
71
+ end
72
+
73
+ private
74
+
75
+ def sanitized_app_path
76
+ cleaned = name.to_s.strip.downcase.gsub(/[^a-z0-9_-]/, "")
77
+ raise Thor::Error, "APP_NAME must include at least one letter or number" if cleaned.empty?
78
+
79
+ cleaned
60
80
  end
61
81
  end
62
82
  end
63
83
 
64
- if __FILE__ == $0
65
- cli = Frankly::CLI.start
66
- end
84
+ Frankly::CLI.start if $PROGRAM_NAME == __FILE__
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Frankly
2
- VERSION = "0.1.6"
4
+ VERSION = "0.2.0"
3
5
  end
data/templates/Gemfile.tt CHANGED
@@ -1,28 +1,22 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- # PostgreSQL driver
4
- gem 'pg'
3
+ ruby ">= 3.1"
5
4
 
6
- # Sinatra driver
7
- gem 'sinatra', '~> 1.0'
8
- gem 'sinatra-contrib'
5
+ gem "sinatra", "~> 3.1"
6
+ gem "sinatra-activerecord", "~> 2.0"
7
+ gem "sinatra-contrib", "~> 3.1"
8
+ gem "pg", "~> 1.5"
9
+ gem "puma", "~> 6.0"
10
+ gem "rake", "~> 13.0"
9
11
 
10
- gem 'activesupport', '~>5.2'
11
- gem 'activerecord', '~>5.2'
12
-
13
- gem 'rake'
14
-
15
- gem 'shotgun', '~>0.9.1'
16
-
17
- group :test do
18
- gem 'shoulda-matchers'
19
- gem 'rack-test'
20
- gem 'rspec', '~>3.0'
21
- gem 'capybara'
12
+ group :development do
13
+ gem "pry-byebug", "~> 3.10"
14
+ gem "rerun", "~> 0.14"
22
15
  end
23
16
 
24
- group :test, :development do
25
- gem 'factory_girl'
26
- gem 'faker'
27
- gem 'pry-byebug'
17
+ group :test do
18
+ gem "capybara", "~> 3.40"
19
+ gem "rack-test", "~> 2.1"
20
+ gem "rspec", "~> 3.13"
21
+ gem "shoulda-matchers", "~> 6.4"
28
22
  end
data/templates/README.md CHANGED
@@ -1,30 +1,48 @@
1
- > **Note**: This branch (master) contains a skeleton without any app code, perfect for creating a _new_ application or challenge. If you're looking for an example app built with this skeleton, take a look at the [example](/../..//tree/example) branch which includes basic CRUD and RSpec tests.
1
+ # Sinatra App
2
2
 
3
- ### Purpose
4
- The Sinatra Skeleton:
3
+ Generated by `frankly`.
5
4
 
6
- 1. Provides a foundation for building challenges or creating a new Sinatra application.
7
- 2. Demonstrates a reasonable set of practices around building Sinatra applications.
8
- 3. Eases the transition to Rails for Dev Bootcamp students
5
+ ## Requirements
9
6
 
10
- ### Quickstart
7
+ - Ruby 3.1+
8
+ - PostgreSQL
9
+ - Bundler
11
10
 
12
- 1. `bundle install`
13
- 2. `shotgun config.ru`
14
-
15
- As needed, create models & migrations with the `rake` tasks:
11
+ ## Quickstart
16
12
 
13
+ ```sh
14
+ bundle install
15
+ bundle exec rackup
17
16
  ```
18
- rake generate:migration # Create an empty migration in db/migrate, e.g., rake generate:migration NAME=create_tasks
19
- rake generate:model # Create an empty model in app/models, e.g., rake generate:model NAME=User
17
+
18
+ Open http://localhost:9292.
19
+
20
+ ## Development reload
21
+
22
+ ```sh
23
+ bundle exec rerun -- rackup
20
24
  ```
21
25
 
22
- ### Contributing
26
+ ## Database
27
+
28
+ The template uses PostgreSQL via ActiveRecord.
23
29
 
24
- We would love for you to help make the skeleton more awesome, There are three ways to contribute:
30
+ Environment variables:
25
31
 
26
- 1. Ask for a bug fix or enhancement!
27
- 2. Submit a pull request for a bug fix or enhancement!
28
- 3. Code review an open pull request!
32
+ - `RACK_ENV` (default: `development`)
33
+ - `DATABASE_URL` (default: `postgres://localhost/<app_name>_<rack_env>`)
29
34
 
30
- Be prepared to give and receive specific, actionable, and kind feedback!
35
+ Examples:
36
+
37
+ ```sh
38
+ RACK_ENV=test bundle exec rake spec
39
+ DATABASE_URL=postgres://localhost/my_app_development bundle exec rackup
40
+ ```
41
+
42
+ ## Common tasks
43
+
44
+ ```sh
45
+ bundle exec rake spec
46
+ bundle exec rake db:migrate
47
+ bundle exec rake db:rollback
48
+ ```
data/templates/Rakefile CHANGED
@@ -1,154 +1,12 @@
1
- require 'rake'
1
+ # frozen_string_literal: true
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require "sinatra/activerecord/rake"
4
+ require_relative "app"
4
5
 
5
- # Include all of ActiveSupport's core class extensions, e.g., String#camelize
6
- require 'active_support/core_ext'
7
-
8
- namespace :generate do
9
- desc "Create an empty model in app/models, e.g., rake generate:model NAME=User"
10
- task :model do
11
- unless ENV.has_key?('NAME')
12
- raise "Must specificy model name, e.g., rake generate:model NAME=User"
13
- end
14
-
15
- model_name = ENV['NAME'].camelize
16
- model_filename = ENV['NAME'].underscore + '.rb'
17
- model_path = APP_ROOT.join('app', 'models', model_filename)
18
-
19
- if File.exist?(model_path)
20
- raise "ERROR: Model file '#{model_path}' already exists"
21
- end
22
-
23
- puts "Creating #{model_path}"
24
- File.open(model_path, 'w+') do |f|
25
- f.write(<<-EOF.strip_heredoc)
26
- class #{model_name} < ActiveRecord::Base
27
- # Remember to create a migration!
28
- end
29
- EOF
30
- end
31
- end
32
-
33
- desc "Create an empty migration in db/migrate, e.g., rake generate:migration NAME=create_tasks"
34
- task :migration do
35
- unless ENV.has_key?('NAME')
36
- raise "Must specificy migration name, e.g., rake generate:migration NAME=create_tasks"
37
- end
38
-
39
- name = ENV['NAME'].camelize
40
- filename = "%s_%s.rb" % [Time.now.strftime('%Y%m%d%H%M%S'), ENV['NAME'].underscore]
41
- path = APP_ROOT.join('db', 'migrate', filename)
42
-
43
- if File.exist?(path)
44
- raise "ERROR: File '#{path}' already exists"
45
- end
46
-
47
- puts "Creating #{path}"
48
- File.open(path, 'w+') do |f|
49
- f.write(<<-EOF.strip_heredoc)
50
- class #{name} < ActiveRecord::Migration[5.2]
51
- def change
52
- end
53
- end
54
- EOF
55
- end
56
- end
57
-
58
- desc "Create an empty model spec in spec, e.g., rake generate:spec NAME=user"
59
- task :spec do
60
- unless ENV.has_key?('NAME')
61
- raise "Must specificy migration name, e.g., rake generate:spec NAME=user"
62
- end
63
-
64
- name = ENV['NAME'].camelize
65
- filename = "%s_spec.rb" % ENV['NAME'].underscore
66
- path = APP_ROOT.join('spec', filename)
67
-
68
- if File.exist?(path)
69
- raise "ERROR: File '#{path}' already exists"
70
- end
71
-
72
- puts "Creating #{path}"
73
- File.open(path, 'w+') do |f|
74
- f.write(<<-EOF.strip_heredoc)
75
- require 'spec_helper'
76
- describe #{name} do
77
- pending "add some examples to (or delete) #{__FILE__}"
78
- end
79
- EOF
80
- end
81
- end
82
-
83
- end
84
-
85
- namespace :db do
86
- desc "Drop, create, and migrate the database"
87
- task :reset => [:drop, :create, :migrate]
88
-
89
- desc "Create the databases at #{DB_NAME}"
90
- task :create do
91
- puts "Creating development and test databases if they don't exist..."
92
- system("createdb #{APP_NAME}_development && createdb #{APP_NAME}_test")
93
- end
94
-
95
- desc "Drop the database at #{DB_NAME}"
96
- task :drop do
97
- puts "Dropping development and test databases..."
98
- system("dropdb #{APP_NAME}_development && dropdb #{APP_NAME}_test")
99
- end
100
-
101
- desc "Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)."
102
- task :migrate do
103
- ActiveRecord::Migrator.migrations_paths << File.dirname(__FILE__) + 'db/migrate'
104
- ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
105
- if ActiveRecord.version.release() < Gem::Version.new('5.2.0')
106
- ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil) do |migration|
107
- ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope)
108
- end
109
- else
110
- ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths).migrate
111
- end
112
- end
113
-
114
- desc "rollback your migration--use STEP=number to step back multiple times"
115
- task :rollback do
116
- step = (ENV['STEP'] || 1).to_i
117
- ActiveRecord::Migrator.rollback('db/migrate', step)
118
- Rake::Task['db:version'].invoke if Rake::Task['db:version']
119
- end
120
-
121
- desc "Populate the database with dummy data by running db/seeds.rb"
122
- task :seed do
123
- require APP_ROOT.join('db', 'seeds.rb')
124
- end
125
-
126
- desc "Returns the current schema version number"
127
- task :version do
128
- puts "Current version: #{ActiveRecord::Migrator.current_version}"
129
- end
130
-
131
- namespace :test do
132
- desc "Migrate test database"
133
- task :prepare do
134
- system "rake db:migrate RACK_ENV=test"
135
- end
136
- end
137
- end
138
-
139
- desc 'Start PRY with application environment loaded'
140
- task "console" do
141
- exec "pry -r./config/environment"
142
- end
143
-
144
-
145
- # In a production environment like Heroku, RSpec might not
146
- # be available. To handle this, rescue the LoadError.
147
- # https://devcenter.heroku.com/articles/getting-started-with-ruby-o#runtime-dependencies-on-development-test-gems
148
6
  begin
149
- require 'rspec/core/rake_task'
7
+ require "rspec/core/rake_task"
150
8
  RSpec::Core::RakeTask.new(:spec)
151
9
  rescue LoadError
152
10
  end
153
11
 
154
- task :default => :spec
12
+ task default: :spec
@@ -0,0 +1,2 @@
1
+ <h1>Frankly, it works.</h1>
2
+ <p>Your Sinatra app "<strong><%= @app_name %></strong>" is up and running.</p>
@@ -1,23 +1,15 @@
1
- <!DOCTYPE html>
1
+ <!doctype html>
2
2
  <html lang="en">
3
- <head>
4
- <!--
5
- normalize.css removes cross-browser differences in defaults, e.g.,
6
- differences in how form elements appear between Firefox and IE
7
- See: http://necolas.github.com/normalize.css/
8
- -->
9
- <link rel="stylesheet" href="/css/normalize.css">
10
- <!--
11
- application.css is where you put your styles
12
- -->
13
- <link rel="stylesheet" href="/css/application.css">
14
-
15
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
16
- <script src="/js/application.js"></script>
17
-
18
- <title></title>
19
- </head>
20
- <body>
21
- <%= yield %>
22
- </body>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title><%= @app_name || "Sinatra App" %></title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <link rel="stylesheet" href="/css/application.css">
8
+ </head>
9
+ <body>
10
+ <main class="container">
11
+ <%= yield %>
12
+ </main>
13
+ <script src="/js/application.js"></script>
14
+ </body>
23
15
  </html>
data/templates/app.rb ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sinatra/base"
4
+ require_relative "config/environment"
5
+
6
+ class App < Sinatra::Base
7
+ configure do
8
+ set :root, APP_ROOT.to_s
9
+ set :public_folder, APP_ROOT.join("public").to_s
10
+ set :views, APP_ROOT.join("app", "views").to_s
11
+ end
12
+
13
+ configure :development do
14
+ register Sinatra::Reloader
15
+ end
16
+
17
+ get "/" do
18
+ @app_name = APP_NAME
19
+ erb :index
20
+ end
21
+
22
+ run! if app_file == $PROGRAM_NAME
23
+ end
@@ -1,42 +1,23 @@
1
- # Log queries to STDOUT in development
2
- if Sinatra::Application.development?
3
- ActiveRecord::Base.logger = Logger.new(STDOUT)
4
- end
1
+ # frozen_string_literal: true
5
2
 
6
- # Automatically load every file in APP_ROOT/app/models/*.rb, e.g.,
7
- # autoload "Person", 'app/models/person.rb'
8
- #
9
- # We have to do this in case we have models that inherit from each other.
10
- # If model Student inherits from model Person and app/models/student.rb is
11
- # required first, it will throw an error saying "Person" is undefined.
12
- #
13
- # With this lazy-loading technique, Ruby will try to load app/models/person.rb
14
- # the first time it sees "Person" and will only throw an exception if
15
- # that file doesn't define the Person class.
16
- #
17
- # See http://www.rubyinside.com/ruby-techniques-revealed-autoload-1652.html
18
- Dir[APP_ROOT.join('app', 'models', '*.rb')].each do |model_file|
19
- filename = File.basename(model_file).gsub('.rb', '')
20
- autoload ActiveSupport::Inflector.camelize(filename), model_file
21
- end
3
+ require "logger"
4
+ require "uri"
22
5
 
23
- # Heroku controls what database we connect to by setting the DATABASE_URL environment variable
24
- # We need to respect that if we want our Sinatra apps to run on Heroku without modification
25
- db = URI.parse(ENV['DATABASE_URL'] || "postgres://localhost/#{APP_NAME}_#{Sinatra::Application.environment}")
6
+ rack_env = ENV.fetch("RACK_ENV", "development")
7
+ ActiveRecord::Base.logger = Logger.new($stdout) if rack_env == "development"
26
8
 
27
- DB_NAME = db.path[1..-1]
9
+ database_url = ENV.fetch("DATABASE_URL", "postgres://localhost/#{APP_NAME}_#{rack_env}")
10
+ uri = URI.parse(database_url)
28
11
 
29
- # Note:
30
- # Sinatra::Application.environment is set to the value of ENV['RACK_ENV']
31
- # if ENV['RACK_ENV'] is set. If ENV['RACK_ENV'] is not set, it defaults
32
- # to :development
12
+ database_name = uri.path.sub(%r{^/}, "")
13
+ adapter = uri.scheme == "postgres" ? "postgresql" : uri.scheme
33
14
 
34
15
  ActiveRecord::Base.establish_connection(
35
- :adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
36
- :host => db.host,
37
- :port => db.port,
38
- :username => db.user,
39
- :password => db.password,
40
- :database => DB_NAME,
41
- :encoding => 'utf8'
16
+ adapter: adapter,
17
+ host: uri.host,
18
+ port: uri.port,
19
+ username: uri.user,
20
+ password: uri.password,
21
+ database: database_name,
22
+ encoding: "utf8"
42
23
  )
@@ -1,46 +1,19 @@
1
- # Set up gems listed in the Gemfile.
2
- # See: http://gembundler.com/bundler_setup.html
3
- # http://stackoverflow.com/questions/7243486/why-do-you-need-require-bundler-setup
4
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
1
+ # frozen_string_literal: true
5
2
 
6
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
3
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
4
+ require "bundler/setup"
7
5
 
8
- # Require gems we care about
9
- require 'rubygems'
6
+ require "pathname"
10
7
 
11
- require 'uri'
12
- require 'pathname'
13
-
14
- require 'pg'
15
- require 'active_record'
16
- require 'logger'
17
-
18
- require 'sinatra'
19
- require "sinatra/reloader" if development?
20
-
21
- require 'erb'
22
- require 'pry-byebug'
23
-
24
- # Some helper constants for path-centric logic
25
- APP_ROOT = Pathname.new(File.expand_path('../../', __FILE__))
8
+ require "active_record"
9
+ require "erb"
10
+ require "sinatra/reloader"
26
11
 
12
+ APP_ROOT = Pathname.new(File.expand_path("..", __dir__))
27
13
  APP_NAME = APP_ROOT.basename.to_s
28
14
 
29
- configure do
30
- # By default, Sinatra assumes that the root is the file that calls the configure block.
31
- # Since this is not the case for us, we set it manually.
32
- set :root, APP_ROOT.to_path
33
- # See: http://www.sinatrarb.com/faq.html#sessions
34
- enable :sessions
35
- set :session_secret, ENV['SESSION_SECRET'] || 'this is a secret shhhhh'
36
-
37
- # Set the views to
38
- set :views, File.join(Sinatra::Application.root, "app", "views")
39
- end
40
-
41
- # Set up the controllers and helpers
42
- Dir[APP_ROOT.join('app', 'controllers', '*.rb')].each { |file| require file }
43
- Dir[APP_ROOT.join('app', 'helpers', '*.rb')].each { |file| require file }
15
+ Dir[APP_ROOT.join("app", "helpers", "*.rb")].sort.each { |file| require file }
16
+ Dir[APP_ROOT.join("app", "controllers", "*.rb")].sort.each { |file| require file }
17
+ Dir[APP_ROOT.join("app", "models", "*.rb")].sort.each { |file| require file }
44
18
 
45
- # Set up the database and models
46
- require APP_ROOT.join('config', 'database')
19
+ require APP_ROOT.join("config", "database")
data/templates/config.ru CHANGED
@@ -1,6 +1,5 @@
1
- # Require config/environment.rb
2
- require ::File.expand_path('../config/environment', __FILE__)
1
+ # frozen_string_literal: true
3
2
 
4
- set :app_file, __FILE__
3
+ require_relative "app"
5
4
 
6
- run Sinatra::Application
5
+ run App
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ .env
3
+ *.log
4
+ db/*.sqlite3
5
+ db/*.sqlite3-journal
6
+ tmp/
7
+ vendor/bundle/
@@ -0,0 +1,26 @@
1
+ :root {
2
+ font-family: "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
3
+ }
4
+
5
+ * {
6
+ box-sizing: border-box;
7
+ }
8
+
9
+ body {
10
+ margin: 0;
11
+ color: #1f2937;
12
+ background: radial-gradient(circle at top, #f8fafc, #eef2ff 50%, #e5e7eb 100%);
13
+ }
14
+
15
+ .container {
16
+ max-width: 44rem;
17
+ margin: 3rem auto;
18
+ padding: 2.25rem;
19
+ border: 1px solid #d1d5db;
20
+ border-radius: 1rem;
21
+ background: rgba(255, 255, 255, 0.92);
22
+ }
23
+
24
+ h1 {
25
+ margin-top: 0;
26
+ }
@@ -1,7 +1 @@
1
- $(document).ready(function() {
2
- // This is called after the document has loaded in its entirety
3
- // This guarantees that any elements we bind to will exist on the page
4
- // when we try to bind to them
5
-
6
- // See: http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
7
- });
1
+ console.log("Frankly generated app loaded.");
metadata CHANGED
@@ -1,23 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frankly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Rettberg
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2019-02-19 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: bundler
13
+ name: thor
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
18
  version: '1.3'
20
- type: :development
19
+ type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
@@ -25,63 +24,64 @@ dependencies:
25
24
  - !ruby/object:Gem::Version
26
25
  version: '1.3'
27
26
  - !ruby/object:Gem::Dependency
28
- name: rake
27
+ name: bundler
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - "~>"
30
+ - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: '10.0'
32
+ version: '2.4'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
- - - "~>"
37
+ - - ">="
39
38
  - !ruby/object:Gem::Version
40
- version: '10.0'
39
+ version: '2.4'
41
40
  - !ruby/object:Gem::Dependency
42
- name: rspec
41
+ name: rake
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
- - - ">="
44
+ - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: '0'
46
+ version: '13.0'
48
47
  type: :development
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
- - - ">="
51
+ - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: '0'
53
+ version: '13.0'
55
54
  - !ruby/object:Gem::Dependency
56
- name: pry-byebug
55
+ name: rspec
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - "~>"
60
59
  - !ruby/object:Gem::Version
61
- version: '3.4'
60
+ version: '3.13'
62
61
  type: :development
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
65
  - - "~>"
67
66
  - !ruby/object:Gem::Version
68
- version: '3.4'
67
+ version: '3.13'
69
68
  - !ruby/object:Gem::Dependency
70
- name: thor
69
+ name: pry-byebug
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - "~>"
74
73
  - !ruby/object:Gem::Version
75
- version: 0.19.1
76
- type: :runtime
74
+ version: '3.10'
75
+ type: :development
77
76
  prerelease: false
78
77
  version_requirements: !ruby/object:Gem::Requirement
79
78
  requirements:
80
79
  - - "~>"
81
80
  - !ruby/object:Gem::Version
82
- version: 0.19.1
83
- description: Setup a sinatra skeleton like a boss!
84
- email: kenrettberg@gmail.com
81
+ version: '3.10'
82
+ description: Generate a modern Sinatra + ActiveRecord starter app with sensible defaults.
83
+ email:
84
+ - kenrettberg@gmail.com
85
85
  executables:
86
86
  - console
87
87
  - frankly
@@ -104,11 +104,10 @@ files:
104
104
  - lib/frankly.rb
105
105
  - lib/frankly/cli.rb
106
106
  - lib/frankly/version.rb
107
- - spec/frankly_spec.rb
108
- - spec/spec_helper.rb
109
107
  - templates/Gemfile.tt
110
108
  - templates/README.md
111
109
  - templates/Rakefile
110
+ - templates/app.rb
112
111
  - templates/app/.DS_Store
113
112
  - templates/app/controllers/.gitkeep
114
113
  - templates/app/helpers/.gitkeep
@@ -116,12 +115,14 @@ files:
116
115
  - templates/app/models/.gitkeep
117
116
  - templates/app/models/README.md
118
117
  - templates/app/views/.gitkeep
118
+ - templates/app/views/index.erb
119
119
  - templates/app/views/layout.erb
120
120
  - templates/config.ru
121
121
  - templates/config/database.rb
122
122
  - templates/config/environment.rb
123
123
  - templates/db/migrate/.gitkeep
124
124
  - templates/db/seeds.rb
125
+ - templates/gitignore.tt
125
126
  - templates/public/.DS_Store
126
127
  - templates/public/css/application.css
127
128
  - templates/public/css/normalize.css
@@ -131,19 +132,9 @@ files:
131
132
  homepage: https://github.com/kenrett/frankly
132
133
  licenses:
133
134
  - MIT
134
- metadata: {}
135
- post_install_message: |2
136
-
137
- .
138
- .---------.'---.
139
- '. : .'
140
- '. .::: .' The Chairman
141
- '.'::'.' of the Board
142
- '||' has arrived.
143
- ||
144
- ||
145
- ||
146
- ---====---
135
+ metadata:
136
+ homepage_uri: https://github.com/kenrett/frankly
137
+ source_code_uri: https://github.com/kenrett/frankly
147
138
  rdoc_options: []
148
139
  require_paths:
149
140
  - lib
@@ -151,18 +142,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
142
  requirements:
152
143
  - - ">="
153
144
  - !ruby/object:Gem::Version
154
- version: '0'
145
+ version: '3.1'
155
146
  required_rubygems_version: !ruby/object:Gem::Requirement
156
147
  requirements:
157
148
  - - ">="
158
149
  - !ruby/object:Gem::Version
159
150
  version: '0'
160
151
  requirements: []
161
- rubyforge_project:
162
- rubygems_version: 2.7.3
163
- signing_key:
152
+ rubygems_version: 4.0.7
164
153
  specification_version: 4
165
- summary: An opinionated sinatra skeleton with Rake tasks, rspec, postgres, and more!
166
- test_files:
167
- - spec/frankly_spec.rb
168
- - spec/spec_helper.rb
154
+ summary: Opinionated Sinatra app skeleton generator
155
+ test_files: []
data/spec/frankly_spec.rb DELETED
@@ -1,44 +0,0 @@
1
- require "spec_helper"
2
- require "tmpdir"
3
- require "logger"
4
-
5
- describe Frankly do
6
- it "has a version number" do
7
- expect(Frankly::VERSION).not_to be nil
8
- end
9
-
10
- context "when generating a new skeleton" do
11
- before(:all) do
12
- @templates_path = "#{File.dirname(__FILE__)}/../lib/sinatra_generator/templates"
13
- @tmp_dir = Dir.mktmpdir
14
- Dir.chdir @tmp_dir
15
- end
16
-
17
- it "creates a temporary directory" do
18
- expect(@tmp_dir).to_not be nil
19
- end
20
-
21
- it "builds a new app" do
22
- Frankly::CLI.start ["test_app"]
23
-
24
- expect(File.directory?('test_app')).to be true
25
-
26
- Dir.chdir 'test_app' do
27
- expect(File.exist?('config.ru')).to be true
28
- expect(File.exist?('Gemfile')).to be true
29
- expect(File.exist?('Rakefile')).to be true
30
- expect(File.exist?('README.md')).to be true
31
- expect(File.directory?('app')).to be true
32
- expect(File.directory?('config')).to be true
33
- expect(File.directory?('db')).to be true
34
- expect(File.directory?('public')).to be true
35
- end
36
- end
37
-
38
- after(:all) do
39
- Dir.chdir('..')
40
- FileUtils.rm_rf @tmp_dir
41
- expect(File.directory?(@tmp_dir)).to be false
42
- end
43
- end
44
- end
data/spec/spec_helper.rb DELETED
@@ -1,32 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
- require "frankly"
3
- require "pry-byebug"
4
-
5
- #### TODO Figure out how to silence the rubygems (Or prevent it from
6
- # bundling at all) The solution below only silence the generating
7
- # files part
8
- #
9
- # Borrowed from https://gist.github.com/adamstegman/926858
10
- #
11
- # RSpec.configure do |config|
12
- # config.before(:all) { silence_output }
13
- # config.after(:all) { enable_output }
14
- # end
15
- #
16
- # # Redirects stderr and stdout to /dev/null.
17
- # def silence_output
18
- # @orig_stderr = $stderr
19
- # @orig_stdout = $stdout
20
- #
21
- # # redirect stderr and stdout to /dev/null
22
- # $stderr = File.new('/dev/null', 'w')
23
- # $stdout = File.new('/dev/null', 'w')
24
- # end
25
- #
26
- # # Replace stdout and stderr so anything else is output correctly.
27
- # def enable_output
28
- # $stderr = @orig_stderr
29
- # $stdout = @orig_stdout
30
- # @orig_stderr = nil
31
- # @orig_stdout = nil
32
- # end