frankly 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +31 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/frankly +14 -0
- data/bin/setup +8 -0
- data/frankly.gemspec +40 -0
- data/lib/frankly/cli.rb +66 -0
- data/lib/frankly/version.rb +3 -0
- data/lib/frankly.rb +6 -0
- data/spec/frankly_spec.rb +44 -0
- data/spec/spec_helper.rb +32 -0
- data/templates/Gemfile.tt +28 -0
- data/templates/README.md +30 -0
- data/templates/Rakefile +150 -0
- data/templates/app/.DS_Store +0 -0
- data/templates/app/controllers/.gitkeep +0 -0
- data/templates/app/helpers/.gitkeep +0 -0
- data/templates/app/helpers/README.md +32 -0
- data/templates/app/models/.gitkeep +0 -0
- data/templates/app/models/README.md +5 -0
- data/templates/app/views/.gitkeep +0 -0
- data/templates/app/views/layout.erb +23 -0
- data/templates/config/database.rb +42 -0
- data/templates/config/environment.rb +46 -0
- data/templates/config.ru +6 -0
- data/templates/db/migrate/.gitkeep +0 -0
- data/templates/db/seeds.rb +0 -0
- data/templates/public/.DS_Store +0 -0
- data/templates/public/css/application.css +0 -0
- data/templates/public/css/normalize.css +423 -0
- data/templates/public/favicon.ico +0 -0
- data/templates/public/js/.gitkeep +0 -0
- data/templates/public/js/application.js +7 -0
- metadata +168 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b231b5fb4caff815c59a89ca54058bd865d6010e
|
4
|
+
data.tar.gz: e46c2c09b1ef059297afdc0b5efe83a6d12e099c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e27253887dfa90c6e3928213b36acff87678069934e08b3b1a35a1d62acd9eab8aaaf9a8113e0315ae273bdd8de06bbec9dbf03e364591702042f61d9c2650fc
|
7
|
+
data.tar.gz: 279416178b684615ca74217a0b6082d8f562923163311f4ab414f2799e343ba1cf7158dc52ebbc9eedbb373ed7c55b81ef25a98c4c31a150d782bb104f10facd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at TODO: Write your email address. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ken Rettberg
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Frankly
|
2
|
+
![Build Status](https://travis-ci.org/kenrett/frankly.svg?branch=master)
|
3
|
+
|
4
|
+
An opinionated sinatra skeleton with Rake tasks, rspec, postgres, and more!
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Type this into the command line:
|
9
|
+
|
10
|
+
```
|
11
|
+
gem install frankly
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
Simple type `frankly APP_NAME` and frankly will create a sinatra scaffold, git init, and bundle.
|
17
|
+
|
18
|
+
## Development
|
19
|
+
|
20
|
+
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.
|
21
|
+
|
22
|
+
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).
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
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.
|
27
|
+
|
28
|
+
|
29
|
+
## License
|
30
|
+
|
31
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "frankly"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/frankly
ADDED
data/bin/setup
ADDED
data/frankly.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'frankly/version'
|
4
|
+
|
5
|
+
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"]
|
19
|
+
|
20
|
+
spec.post_install_message = <<-PIC
|
21
|
+
|
22
|
+
.
|
23
|
+
.---------.'---.
|
24
|
+
'. : .'
|
25
|
+
'. .::: .' The Chairman
|
26
|
+
'.'::'.' of the Board
|
27
|
+
'||' has arrived.
|
28
|
+
||
|
29
|
+
||
|
30
|
+
||
|
31
|
+
---====---
|
32
|
+
PIC
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.6"
|
37
|
+
spec.add_development_dependency "pry-byebug", "~> 3.4"
|
38
|
+
|
39
|
+
spec.add_runtime_dependency 'thor', '~> 0.19.1'
|
40
|
+
end
|
data/lib/frankly/cli.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'thor'
|
4
|
+
require 'thor/group'
|
5
|
+
|
6
|
+
module Frankly
|
7
|
+
class CLI < Thor::Group
|
8
|
+
include Thor::Actions
|
9
|
+
|
10
|
+
def self.source_root
|
11
|
+
File.expand_path('../../../templates', __FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Creates a new Sinatra application"
|
15
|
+
argument :name, :type => :string, :desc => "The name of the new application"
|
16
|
+
|
17
|
+
def setup
|
18
|
+
@app_path = name.downcase.gsub(/[^a-z|\-|\_]/, '')
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_app_scaffold
|
22
|
+
empty_directory "#{@app_path}/app"
|
23
|
+
create_file "#{@app_path}/app/models/.gitkeep"
|
24
|
+
create_file "#{@app_path}/app/controllers/.gitkeep"
|
25
|
+
create_file "#{@app_path}/app/views/.gitkeep"
|
26
|
+
create_file "#{@app_path}/app/helpers/.gitkeep"
|
27
|
+
create_file "#{@app_path}/config/.gitkeep"
|
28
|
+
create_file "#{@app_path}/db/migrate/.gitkeep"
|
29
|
+
create_file "#{@app_path}/public/css/.gitkeep"
|
30
|
+
create_file "#{@app_path}/public/js/.gitkeep"
|
31
|
+
end
|
32
|
+
|
33
|
+
def copy_templates
|
34
|
+
copy_file "app/views/layout.erb", "#{@app_path}/app/views/layout.erb"
|
35
|
+
copy_file "config.ru", "#{@app_path}/config.ru"
|
36
|
+
copy_file "Rakefile", "#{@app_path}/Rakefile"
|
37
|
+
copy_file "config/database.rb", "#{@app_path}/config/database.rb"
|
38
|
+
copy_file "config/environment.rb", "#{@app_path}/config/environment.rb"
|
39
|
+
copy_file "db/seeds.rb", "#{@app_path}/db/seeds.rb"
|
40
|
+
copy_file "README.md", "#{@app_path}/README.md"
|
41
|
+
copy_file "Gemfile", "#{@app_path}/Gemfile"
|
42
|
+
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
|
+
copy_file "public/js/application.js", "#{@app_path}/public/js/application.js"
|
45
|
+
copy_file "public/favicon.ico", "#{@app_path}/public/favicon.ico"
|
46
|
+
end
|
47
|
+
|
48
|
+
def initialize_git_repo
|
49
|
+
puts "about to run git init"
|
50
|
+
inside(@app_path) do
|
51
|
+
run('git init .')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def install_dependencies
|
56
|
+
puts "installing dependencies"
|
57
|
+
inside(@app_path) do
|
58
|
+
run('bundle')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
if __FILE__ == $0
|
65
|
+
cli = Frankly::CLI.start
|
66
|
+
end
|
data/lib/frankly.rb
ADDED
@@ -0,0 +1,44 @@
|
|
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
ADDED
@@ -0,0 +1,32 @@
|
|
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
|
@@ -0,0 +1,28 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# PostgreSQL driver
|
4
|
+
gem 'pg'
|
5
|
+
|
6
|
+
# Sinatra driver
|
7
|
+
gem 'sinatra', '~> 1.0'
|
8
|
+
gem 'sinatra-contrib'
|
9
|
+
|
10
|
+
gem 'activesupport', '~>4.2.0'
|
11
|
+
gem 'activerecord', '~>4.2.0'
|
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'
|
22
|
+
end
|
23
|
+
|
24
|
+
group :test, :development do
|
25
|
+
gem 'factory_girl'
|
26
|
+
gem 'faker'
|
27
|
+
gem 'pry-byebug'
|
28
|
+
end
|
data/templates/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
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.
|
2
|
+
|
3
|
+
### Purpose
|
4
|
+
The Sinatra Skeleton:
|
5
|
+
|
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
|
9
|
+
|
10
|
+
### Quickstart
|
11
|
+
|
12
|
+
1. `bundle install`
|
13
|
+
2. `shotgun config.ru`
|
14
|
+
|
15
|
+
As needed, create models & migrations with the `rake` tasks:
|
16
|
+
|
17
|
+
```
|
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
|
20
|
+
```
|
21
|
+
|
22
|
+
### Contributing
|
23
|
+
|
24
|
+
We would love for you to help make the skeleton more awesome, There are three ways to contribute:
|
25
|
+
|
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!
|
29
|
+
|
30
|
+
Be prepared to give and receive specific, actionable, and kind feedback!
|
data/templates/Rakefile
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
require ::File.expand_path('../config/environment', __FILE__)
|
4
|
+
|
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
|
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
|
+
ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil) do |migration|
|
106
|
+
ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
desc "rollback your migration--use STEP=number to step back multiple times"
|
111
|
+
task :rollback do
|
112
|
+
step = (ENV['STEP'] || 1).to_i
|
113
|
+
ActiveRecord::Migrator.rollback('db/migrate', step)
|
114
|
+
Rake::Task['db:version'].invoke if Rake::Task['db:version']
|
115
|
+
end
|
116
|
+
|
117
|
+
desc "Populate the database with dummy data by running db/seeds.rb"
|
118
|
+
task :seed do
|
119
|
+
require APP_ROOT.join('db', 'seeds.rb')
|
120
|
+
end
|
121
|
+
|
122
|
+
desc "Returns the current schema version number"
|
123
|
+
task :version do
|
124
|
+
puts "Current version: #{ActiveRecord::Migrator.current_version}"
|
125
|
+
end
|
126
|
+
|
127
|
+
namespace :test do
|
128
|
+
desc "Migrate test database"
|
129
|
+
task :prepare do
|
130
|
+
system "rake db:migrate RACK_ENV=test"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
desc 'Start IRB with application environment loaded'
|
136
|
+
task "console" do
|
137
|
+
exec "pry -r./config/environment"
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
# In a production environment like Heroku, RSpec might not
|
142
|
+
# be available. To handle this, rescue the LoadError.
|
143
|
+
# https://devcenter.heroku.com/articles/getting-started-with-ruby-o#runtime-dependencies-on-development-test-gems
|
144
|
+
begin
|
145
|
+
require 'rspec/core/rake_task'
|
146
|
+
RSpec::Core::RakeTask.new(:spec)
|
147
|
+
rescue LoadError
|
148
|
+
end
|
149
|
+
|
150
|
+
task :default => :spec
|
Binary file
|
File without changes
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# HELPERS
|
2
|
+
|
3
|
+
## Basics
|
4
|
+
|
5
|
+
Helpers are methods that are defined in a central place but which can be used
|
6
|
+
inside of your view templates. An example of a helper is shown in
|
7
|
+
`app/views/index.erb` inside where we use the `em` helper.
|
8
|
+
|
9
|
+
## Adding helpers
|
10
|
+
|
11
|
+
Add helpers here inside of *.rb files inside this directory e.g.:
|
12
|
+
`app/helpers/formatting.rb`.
|
13
|
+
|
14
|
+
Inside this file define your helpers like:
|
15
|
+
|
16
|
+
```
|
17
|
+
helpers do
|
18
|
+
def em(text)
|
19
|
+
"<em>#{text}</em>"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
## Reloading
|
25
|
+
|
26
|
+
After you create new files containing helpers, you must restart the web server
|
27
|
+
so that your changes are reloaded into the running web server process. This is
|
28
|
+
because helper files are read *only once* at web-server *startup* time. Also,
|
29
|
+
if you add a new helper or alter its implementation, you *also* must restart it
|
30
|
+
so that "sourced" (i.e. read in) anew. Other web frameworks do not require
|
31
|
+
this restart e.g. Rails but in this starter kit you're best not "bubbling out"
|
32
|
+
helpers until your implementation has "gelled."
|
File without changes
|