Skip to content

Commit

Permalink
Merge d3ec79a into e7d7286
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiru Njuguna committed Oct 29, 2018
2 parents e7d7286 + d3ec79a commit cd5cd11
Show file tree
Hide file tree
Showing 24 changed files with 132 additions and 321 deletions.
10 changes: 4 additions & 6 deletions Gemfile
@@ -1,14 +1,12 @@
source 'https://rubygems.org/'

gemspec

gem 'active_model_serializers', '~> 0.10.0.rc1'
gem 'coveralls', '~> 0'
gem 'coveralls'
group :development do
gem "rake", '~> 0'
gem "pry"
gem 'rake'
gem 'pry'
gem 'guard'
gem 'rspec'
gem 'guard-rubocop'
gem 'guard-rspec', require: false
end
end
10 changes: 5 additions & 5 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
natra (0.0.3)
natra (0.0.4)
activesupport (~> 5.0)
thor (~> 0.18)

Expand Down Expand Up @@ -91,7 +91,7 @@ GEM
nenv (~> 0.1)
shellany (~> 0.0)
parallel (1.12.1)
parser (2.5.1.2)
parser (2.5.3.0)
ast (~> 2.4.0)
powerpack (0.1.2)
pry (0.11.3)
Expand All @@ -106,7 +106,7 @@ GEM
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
rainbow (3.0.0)
rake (0.9.6)
rake (12.3.1)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
Expand Down Expand Up @@ -154,13 +154,13 @@ PLATFORMS
DEPENDENCIES
active_model_serializers (~> 0.10.0.rc1)
bundler (~> 1.16)
coveralls (~> 0)
coveralls
guard
guard-rspec
guard-rubocop
natra!
pry
rake (~> 0)
rake
rspec

BUNDLED WITH
Expand Down
26 changes: 0 additions & 26 deletions Guardfile
@@ -1,29 +1,3 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}

## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"

# Note: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec'
# * bundler binstubs: 'bin/rspec'
# * spring: 'bin/rspec' (This will use spring if running and you have
# installed the spring binstubs per the docs)
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'

guard :rspec, cmd: "bundle exec rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
Expand Down
3 changes: 1 addition & 2 deletions Rakefile
Expand Up @@ -2,5 +2,4 @@ require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
7 changes: 3 additions & 4 deletions bin/console
@@ -1,6 +1,5 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "natra"
require "pry"
require 'bundler/setup'
require 'natra'
require 'pry'
Pry.start
3 changes: 0 additions & 3 deletions bin/natra
@@ -1,7 +1,4 @@
#!/usr/bin/env bash

$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))

require "natra"

Natra::CLI.start
1 change: 0 additions & 1 deletion bin/setup
Expand Up @@ -2,5 +2,4 @@
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install
5 changes: 1 addition & 4 deletions lib/extensions/string.rb
Expand Up @@ -4,10 +4,7 @@ module String
def camel_case
return self.gsub(/^./) { |l| l.capitalize } if !match(/[_-]/)
altered_self = self.downcase.capitalize
altered_self.scan(/[_-][a-zA-Z]/).each do |match|
altered_self.gsub!(match, match[1].upcase)
end

altered_self.scan(/[_-][a-zA-Z]/).each { |match| altered_self.gsub!(match, match[1].upcase) }
altered_self
end

Expand Down
17 changes: 8 additions & 9 deletions lib/natra.rb
@@ -1,9 +1,8 @@
require "extensions/string"
require "natra/generators/app/app_generator"
require "natra/generators/model/model_generator"
require "natra/generators/scaffold/scaffold_generator"
require "natra/generators/controller/controller_generator"
require "natra/version"
require "natra/cli"

module Natra; end
require 'extensions/string'
require 'natra/generators/app/app_generator'
require 'natra/generators/model/model_generator'
require 'natra/generators/scaffold/scaffold_generator'
require 'natra/generators/controller/controller_generator'
require 'natra/version'
require 'natra/cli'
module Natra; end
4 changes: 2 additions & 2 deletions lib/natra/cli.rb
Expand Up @@ -3,11 +3,11 @@ module Natra
class CLI < Thor
desc '-v', 'Show Natra version number'
map %w[-v --version] => :version
# USAGE: Natra -v

def version
say "Natra #{Natra::VERSION}"
end
# register(class_name, subcommand_alias, usage_list_string, description_string)

register Natra::Generators::AppGenerator, 'new', 'new APP_PATH', 'Creates a new Sinatra application'
register Natra::Generators::ModelGenerator, 'model', 'model NAME', 'Generate a model'
register Natra::Generators::ControllerGenerator, 'controller', 'controller NAME', 'Generate a controller'
Expand Down
111 changes: 48 additions & 63 deletions lib/natra/generators/app/app_generator.rb
@@ -1,138 +1,127 @@
# encoding: UTF-8
require "thor/group"

require 'thor/group'
module Natra
module Generators
class AppGenerator < Thor::Group
include Thor::Actions
desc 'Creates a new Sinatra application'
argument :name, type: :string, desc: 'The name of the new application'
class_option :capistrano, type: :boolean, desc: 'Include Capistrano configuration'
class_option :redis, type: :boolean, desc: 'Include Redis configuration'
class_option :rvm, type: :boolean, desc: 'Create .ruby-version (ruby-2.1.0) and .ruby-gemset'
class_option :bundle, type: :boolean, desc: 'Run bundle after generating the app'
class_option :git, type: :boolean, desc: 'Initialize a Git repository'

desc "Creates a new Sinatra application"
argument :name, :type => :string, :desc => "The name of the new application"
class_option :capistrano, :type => :boolean, :desc => "Include Capistrano configuration"
class_option :redis, :type => :boolean, :desc => "Include Redis configuration"
class_option :rvm, :type => :boolean, :desc => "Create .ruby-version (ruby-2.1.0) and .ruby-gemset"
class_option :bundle, :type => :boolean, :desc => "Run bundle after generating the app"
class_option :git, :type => :boolean, :desc => "Initialize a Git repository"

# Creates instance variables from options passed to natra.
def setup
@app_path = name.directory_name
@name = name.file_name

options.each do |key, value|
instance_variable_set "@#{key.to_s}".to_sym, value
end
options.each {|key, value| instance_variable_set "@#{key}".to_sym, value}
end

def self.source_root
File.expand_path(File.join(File.dirname(__FILE__), "templates"))
File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
end

# Create empty directories
def create_empty_directories
%w{config/initializers lib spec}.each do |dir|
empty_directory File.join(@app_path, dir)
end

%w[config/initializers lib spec].each {|dir| empty_directory File.join(@app_path, dir)}
empty_directory File.join(@app_path, 'db/migrate')

create_file File.join(@app_path, "lib", ".keep")
template "config/environment.rb", File.join(@app_path, "config/environment.rb")
create_file File.join(@app_path, 'lib', '.keep')
template 'config/environment.rb', File.join(@app_path, 'config/environment.rb')
end

def create_seeds_file
create_file File.join(@app_path, "db", "seeds.rb")
create_file File.join(@app_path, 'db', 'seeds.rb')
end

def initialize_db
copy_file('bin/setup', File.join(@app_path, "bin/setup"))
copy_file('bin/setup', File.join(@app_path, 'bin/setup'))
end

def uuid_setup
template 'db/migrate/add_extensions.rb', File.join(@app_path,"db/migrate/#{Time.now.strftime('%Y%m%d')}0000_add_extensions.rb")
template 'db/migrate/add_extensions.rb', File.join(@app_path, "db/migrate/#{Time.now.strftime('%Y%m%d')}0000_add_extensions.rb")
end

def create_public_directory
template "public/favicon.ico", File.join(@app_path, "public/favicon.ico")
template 'public/favicon.ico', File.join(@app_path, 'public/favicon.ico')
end

def create_app_directory
%w{app/controllers app/views app/models}.each do |dir|
directory dir, File.join(@app_path, dir)
end
%w[app/controllers app/views app/models].each {|dir| directory dir, File.join(@app_path, dir)}
end

def create_app_spec
template "spec/application_controller_spec.rb", File.join(@app_path, "spec/application_controller_spec.rb")
template 'spec/application_controller_spec.rb', File.join(@app_path, 'spec/application_controller_spec.rb')
end

def create_spec_helper
template "spec/spec_helper.rb", File.join(@app_path, "spec/spec_helper.rb")
template 'spec/spec_helper.rb', File.join(@app_path, 'spec/spec_helper.rb')
end

def create_config
template "config.ru", File.join(@app_path, "config.ru")
template 'config.ru', File.join(@app_path, 'config.ru')
end

def create_gemfile
template "Gemfile", File.join(@app_path, "Gemfile")
template 'Gemfile', File.join(@app_path, 'Gemfile')
end

def create_rakefile
template "Rakefile", File.join(@app_path, "Rakefile")
template 'Rakefile', File.join(@app_path, 'Rakefile')
end

def create_readme
template("README.md", File.join(@app_path, "README.md"))
template('README.md', File.join(@app_path, 'README.md'))
end

def create_db_config
template("config/db.yml", File.join(@app_path, "config/db.yml"))
template('config/db.yml', File.join(@app_path, 'config/db.yml'))
end

def create_database_initializer
template("config/initializers/database.rb", File.join(@app_path, "config/initializers/database.rb"))
template('config/initializers/database.rb', File.join(@app_path, 'config/initializers/database.rb'))
end

def create_redis_config
copy_file("config/redis.yml", File.join(@app_path, "config/redis.yml")) if @redis
copy_file('config/redis.yml', File.join(@app_path, 'config/redis.yml')) if @redis
end

def create_redis_initializer
template("config/initializers/redis.rb", File.join(@app_path, "config/initializers/redis.rb")) if @redis
template('config/initializers/redis.rb', File.join(@app_path, 'config/initializers/redis.rb')) if @redis
end

def create_gitignore
copy_file "gitignore", File.join(@app_path, '.gitignore')
copy_file 'gitignore', File.join(@app_path, '.gitignore')
end

def create_rspec
copy_file 'rspec', File.join(@app_path, '.rspec')
end

def create_rubocop
copy_file 'rubocop.yml', File.join(@app_path, '.rubocop.yml')
copy_file 'rubocop.yml', File.join(@app_path, '.rubocop.yml')
end

def create_docker
copy_file 'Dockerfile', File.join(@app_path, 'Dockerfile')
end

def create_docker_compose
template('docker-compose.yml', File.join(@app_path, "docker-compose.yml"))
template('docker-compose.yml', File.join(@app_path, 'docker-compose.yml'))
end

def create_guardfile
copy_file 'Guardfile',File.join(@app_path, 'Guardfile')
copy_file 'Guardfile', File.join(@app_path, 'Guardfile')
end

def create_spec_support
create_file File.join(@app_path, "spec/support/", ".keep")
create_file File.join(@app_path, 'spec/support/', '.keep')
end

def create_secrets
template('secrets.env',File.join(@app_path, "secrets.env"))
template('secrets.env', File.join(@app_path, 'secrets.env'))
end

def create_capistrano_config
if @capistrano
inside(@app_path) do
run('cap install')
end
end
inside(@app_path) {run('cap install')} if @capistrano
end

def create_rvm_gemset
Expand All @@ -146,15 +135,11 @@ def create_rvm_gemset
end

def initialize_git_repo
inside(@app_path) do
run('git init .') if @git
end
inside(@app_path) {run('git init .') if @git}
end

def install_dependencies
inside(@app_path) do
run('bundle') if @bundle
end
inside(@app_path) {run('bundle') if @bundle}
end
end
end
Expand Down
Empty file.
Binary file not shown.
Empty file.

0 comments on commit cd5cd11

Please sign in to comment.