Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wess committed Jan 20, 2016
0 parents commit 9eda07e
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in centerstage.gemspec
gemspec
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Wess Cope

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Centerstage

Centerstage is a commandline helper for creating Sinatra/Datamapper apps, including Rakefile and templates for creating routes and models.

## Installation

To install, just run:

$ gem install centerstage

## Usage

Once Centerstage is installed, you can get started using it by running:
$ centerstage setup

This will download the project template from the repo and install it to private directory (~/.center-stage). You can also, optionally, pass a fork url of your Centerstage
project setup. When you pass your fork (fork of http://github.com/wess/center-stage), Centerstage will attempt to download your fork and setup the project template for create.
Example:
$ centerstage setup "http://github.com/<yourname>/center-stage"


Once setup, you create your new Centerstage project using:
$ centerstage create /path/to/project
$ cd /path/to/project
$ bundle install

This will create a folder and a stubbed out Sinatra/Datamapper project that includes a Rakefile with prewritten commands for generating routes and models. In the project's directory
there is a `.templates` folder, this folder contains the templates used to generate routes (views) and models. You can change or update these as you see fit. When you use the
`generate` command, Rake will look to the template when generating the file.

## Development
Pull requests are always welcome, either to the main center-stage project setup or to the centerstage gem.

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/wess/center-stage.


## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "bundler/gem_tasks"
task :default => :spec
4 changes: 4 additions & 0 deletions bin/centerstage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby

require "centerstage"
Centerstage::App.start(ARGV)
34 changes: 34 additions & 0 deletions centerstage.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'centerstage/version'

Gem::Specification.new do |spec|
spec.name = "centerstage"
spec.version = Centerstage::VERSION
spec.authors = ["Wess Cope"]
spec.email = ["wcope@me.com"]

spec.summary = %q{Sinatra setup and generator.}
spec.description = %q{Centerstage is a command line script to generate Sinatra based applications with data mapper, including an extendable Rakefile for generating new routes and models.}
spec.homepage = "https://github.com/wess/center-stage"
spec.license = "MIT"

# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
# delete this section to allow pushing this gem to any host.
if spec.respond_to?(:metadata)
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
else
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
end

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "bin"
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.11"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "thor", "~> 0.19.1"
spec.add_development_dependency "rubyzip", "~> 1.1.7"
end
88 changes: 88 additions & 0 deletions lib/centerstage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
require 'thor'
require 'uri'
require 'open-uri'
require 'fileutils'
require 'etc'
require 'zip'
require 'erb'
require "centerstage/version"


URL = "https://github.com/wess/center-stage/archive/master.zip"
HOME_DIR = Etc.getpwuid.dir
CENTER_STAGE_DIR = "#{HOME_DIR}/.center-stage"
CONFIG_TEMPLATE = <<-BLOCK
app_name: <%= name %>
development:
db:
user: username
name: database
production:
db:
user: username
name: database
BLOCK

module Centerstage
class App < Thor
desc "setup", "Sets up CenterStage for use"
def setup(fork=URL)
if not valid_url?(fork)
puts "URL provided for fork of Centerstage, is invalid."
return
end

if File.directory?(CENTER_STAGE_DIR)
FileUtils.rm_rf CENTER_STAGE_DIR
end

FileUtils.mkdir_p(CENTER_STAGE_DIR)

zip_path = "#{CENTER_STAGE_DIR}/center-stage.zip"
open zip_path, 'wb' do |file|
file << open(fork).read
end

Zip::File.open zip_path do |zip_file|
zip_file.each do |entry|
path_array = entry.name.split("/").drop(1)
path = "#{CENTER_STAGE_DIR}/#{path_array.join("/")}"

entry.extract path
end
end

File.delete zip_path

puts "Setup complete"
end

desc "create NAME", "Creates a new Sinatra/Datamapper app"
def create(name)
app_dir = "#{Dir.pwd}/#{name}"
app_name = name.slice(0, 1).capitalize + name.slice(1..-1)

FileUtils.cp_r CENTER_STAGE_DIR, app_dir

Dir.glob("#{app_dir}/**/*.*") do |file|
template = ERB.new File.read(file)
File.open(file, 'w') do |f|
f.write template.result(binding)
end
end
end

no_commands do
def valid_url?(url)
uri = URI.parse(url)
uri.kind_of?(URI::HTTP)
rescue URI::InvalidURIError
false
end
end
end
end

3 changes: 3 additions & 0 deletions lib/centerstage/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Centerstage
VERSION = "0.0.1"
end

0 comments on commit 9eda07e

Please sign in to comment.