modularize_sinatra 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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 modularize_sinatra.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 goyalankit
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,29 @@
1
+ # ModularizeSinatra
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'modularize_sinatra'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install modularize_sinatra
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "bundler/setup"
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'rubigen'
5
+
6
+ if %w(-v --version).include? ARGV.first
7
+ require 'modularize_sinatra'
8
+ puts "#{File.basename($0)} #{ModularizeSinatra::VERSION}"
9
+ exit(0)
10
+ end
11
+
12
+ require 'rubigen/scripts/generate'
13
+ source = RubiGen::PathSource.new(:application,
14
+ File.join(File.dirname(__FILE__), "../lib"))
15
+ RubiGen::Base.reset_sources
16
+ RubiGen::Base.append_sources source
17
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'modularize_sinatra')
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,88 @@
1
+ class ModularizeSinatraGenerator < RubiGen::Base
2
+
3
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
4
+ Config::CONFIG['ruby_install_name'])
5
+
6
+ default_options :shebang => DEFAULT_SHEBANG,
7
+ :version => '0.0.1',
8
+ :controller_name => 'Ping'
9
+
10
+ attr_reader :name, :module_name, :project_name
11
+ attr_reader :controller_name, :controller_module_name
12
+
13
+ # extensions/option
14
+ attr_reader :test_framework
15
+
16
+
17
+ def initialize(runtime_args, runtime_options = {})
18
+ super
19
+ usage if args.empty?
20
+ @destination_root = File.expand_path(args.shift)
21
+ @name = base_name
22
+ @project_name = @name
23
+ @module_name = name.gsub('-','_').camelize
24
+ extract_options
25
+ end
26
+
27
+ def manifest
28
+ record do |m|
29
+ m.directory ''
30
+ BASEDIRS.each { |path| m.directory path }
31
+
32
+ m.template_copy_each %w( Gemfile config.ru Rakefile)
33
+ m.template "module.rb", "#{project_name}.rb"
34
+ m.template "lib/app.rb", "lib/app.rb"
35
+ m.template "config/environment.rb", "config/environment.rb"
36
+ m.template "spec/spec_helper.rb", "spec/spec_helper.rb"
37
+
38
+ #controller for app
39
+ case controller_name
40
+ when 'Ping'
41
+ m.template "lib/controllers/ping.rb", "lib/controllers/ping.rb"
42
+ m.template "spec/controllers/ping_spec.rb", "spec/controllers/ping_spec.rb"
43
+ else
44
+ m.template "lib/controllers/controller.rb", "lib/controllers/#{controller_name}.rb"
45
+ m.template "spec/controllers/controller_spec.rb", "spec/controllers/controller_spec.rb"
46
+ end
47
+
48
+ m.dependency "install_rubigen_scripts", [destination_root, 'modularize_sinatra'], :shebang => options[:shebang], :collision => :force
49
+ end
50
+ end
51
+
52
+ protected
53
+ def banner
54
+ <<-EOS
55
+ Creates a skeltan for modularized Sinatra Applications
56
+
57
+ USAGE: #{spec.name} name
58
+ EOS
59
+ end
60
+
61
+ def add_options!(opts)
62
+ opts.separator ''
63
+ opts.separator 'Options:'
64
+ opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
65
+ opts.on("-T", "--test-with=TEST_FRAMEWORK", String,
66
+ "Select your preferred testing framework.",
67
+ "Options: rspec (default), test_unit.") { |x| options[:test_framework] = x }
68
+ opts.on("-C", "--controller=CONTROLLER_NAME", String,
69
+ "Give name of your initial controller",
70
+ "default name give is Ping.") { |x| options[:controller_name] = x }
71
+ end
72
+
73
+ def extract_options
74
+ @test_framework = "rspec"
75
+ @controller_name = options[:controller_name] || "Ping"
76
+ @controller_module_name = controller_name.gsub('-','_').camelize
77
+ end
78
+
79
+ BASEDIRS = %w(
80
+ config
81
+ lib/controllers
82
+ public
83
+ spec/controllers
84
+ spec/support
85
+ script
86
+ tmp
87
+ )
88
+ end
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'sinatra'
4
+ gem 'sinatra-contrib'
5
+
6
+ gem 'json'
7
+ gem 'rake'
8
+ gem 'activesupport' , '~> 3.2.8'
9
+ gem 'rack-contrib'
10
+
11
+ group :test do
12
+ gem '<%= test_framework %>'
13
+ gem 'rack-test', :require => 'rack/test'
14
+ end
15
+
@@ -0,0 +1,16 @@
1
+ require 'bundler/setup'
2
+
3
+ Dir[File.join(File.dirname(__FILE__), 'lib/tasks/*.rake')].each { |f| load f }
4
+
5
+ task :default => [:spec]
6
+
7
+ desc "Run specs"
8
+ task :spec do
9
+ require 'rspec/core/rake_task'
10
+ require 'rspec/core/version'
11
+
12
+ RSpec::Core::RakeTask.new(:spec) do |t|
13
+ t.pattern = './spec/**/*_spec.rb'
14
+ end
15
+ end
16
+
@@ -0,0 +1,3 @@
1
+ require 'erb'
2
+
3
+ #here you can load yaml files in config folder
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+ require 'active_support/all'
4
+
5
+ $: << File.dirname(__FILE__)
6
+
7
+ ENV['RACK_ENV'] ||= 'development'
8
+
9
+ require '<%= project_name %>'
10
+ run <%= module_name %>::App
11
+
@@ -0,0 +1,9 @@
1
+ module <%= module_name %>
2
+ class App < Sinatra::Base
3
+ set :root, File.join(File.dirname(__FILE__), '..')
4
+ set :vendor, 'FIX add your vendor name'
5
+
6
+ use <%= module_name %>::Controllers::<%= controller_module_name %>
7
+ end
8
+ end
9
+
@@ -0,0 +1,8 @@
1
+ class <%= module_name %>::Controllers::<%= controller_module_name %> < Sinatra::Base
2
+
3
+ # add your own routes TODO
4
+ # get '/' do
5
+ # end
6
+
7
+ end
8
+
@@ -0,0 +1,5 @@
1
+ class <%= module_name %>::Controllers::Ping < Sinatra::Base
2
+ get '/ping' do
3
+ body "Ahoy! from <%= module_name %> #{Time.now}"
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ $: << 'lib'
2
+ require 'config/environment'
3
+
4
+ module <%= module_name %>
5
+ Dir[File.join(File.dirname(__FILE__), 'lib', '*.rb')].each do |f|
6
+ autoload File.basename(f, '.rb').camelize.to_sym, f
7
+ end
8
+
9
+ module Controllers
10
+ Dir[File.join(File.dirname(__FILE__), 'lib', 'controllers/*.rb')].each do |f|
11
+ autoload File.basename(f, '.rb').camelize.to_sym, f
12
+ end
13
+ end
14
+
15
+ module Models
16
+ Dir[File.join(File.dirname(__FILE__), 'lib', 'models/*.rb')].each do |f|
17
+ autoload File.basename(f, '.rb').camelize.to_sym, f
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= module_name %>::Controllers::<%= controller_module_name %> do
4
+ def app
5
+ <%= module_name %>::Controllers::<%= controller_module_name %>
6
+ end
7
+
8
+ it "should do nothing" do
9
+ true.should == true
10
+ end
11
+ end
12
+
13
+
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= module_name %>::Controllers::Ping do
4
+ def app
5
+ <%= module_name %>::Controllers::Ping
6
+ end
7
+
8
+ describe "get /ping" do
9
+ it "should return 200" do
10
+ get :ping
11
+ last_response.body.should == "Ahoy! from <%= module_name %> #{Time.now}"
12
+ last_response.status.should == 200
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,19 @@
1
+ require 'bundler'
2
+ Bundler.require :default, :test
3
+
4
+ ENV['RACK_ENV'] ||= 'test'
5
+ require 'sinatra/contrib'
6
+
7
+ spec_root = File.expand_path(File.dirname(__FILE__))
8
+ $: << spec_root
9
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '..'))
10
+
11
+ Sinatra::Base.set :environment, :test
12
+ require File.join(File.dirname(__FILE__), '..', '<%= project_name %>')
13
+ Dir[File.join(spec_root, "support/**/*.rb")].each { |f| require f }
14
+
15
+ RSpec.configure do |config|
16
+ config.color_enabled = true
17
+ config.include Sinatra::TestHelpers
18
+ end
19
+
@@ -0,0 +1,3 @@
1
+ module ModularizeSinatra
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "modularize_sinatra/version"
2
+
3
+ module ModularizeSinatra
4
+ #nothing fancy here
5
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/modularize_sinatra/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Ankit Goyal"]
6
+ gem.email = ["ankit3goyal@gmail.com"]
7
+ gem.description = %q{Code Generator for Sinatra}
8
+ gem.summary = %q{Creates a modular skeleton for Sinatra application.}
9
+ gem.homepage = "https://github.com/goyalankit/modularize_sinatra"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "modularize_sinatra"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = ModularizeSinatra::VERSION
17
+ gem.add_dependency "rake"
18
+ gem.add_dependency "rubigen"
19
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: modularize_sinatra
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Ankit Goyal
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2013-04-07 00:00:00 +05:30
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :runtime
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 0
28
+ version: "0"
29
+ name: rake
30
+ requirement: *id001
31
+ prerelease: false
32
+ - !ruby/object:Gem::Dependency
33
+ type: :runtime
34
+ version_requirements: &id002 !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ segments:
39
+ - 0
40
+ version: "0"
41
+ name: rubigen
42
+ requirement: *id002
43
+ prerelease: false
44
+ description: Code Generator for Sinatra
45
+ email:
46
+ - ankit3goyal@gmail.com
47
+ executables:
48
+ - modularize_sinatra
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - bin/modularize_sinatra
60
+ - lib/modularize_sinatra.rb
61
+ - lib/modularize_sinatra/USAGE
62
+ - lib/modularize_sinatra/modularize_sinatra_generator.rb
63
+ - lib/modularize_sinatra/templates/Gemfile
64
+ - lib/modularize_sinatra/templates/Rakefile
65
+ - lib/modularize_sinatra/templates/config.ru
66
+ - lib/modularize_sinatra/templates/config/environment.rb
67
+ - lib/modularize_sinatra/templates/lib/app.rb
68
+ - lib/modularize_sinatra/templates/lib/controllers/controller.rb
69
+ - lib/modularize_sinatra/templates/lib/controllers/ping.rb
70
+ - lib/modularize_sinatra/templates/module.rb
71
+ - lib/modularize_sinatra/templates/spec/controllers/controller_spec.rb
72
+ - lib/modularize_sinatra/templates/spec/controllers/ping_spec.rb
73
+ - lib/modularize_sinatra/templates/spec/spec_helper.rb
74
+ - lib/modularize_sinatra/version.rb
75
+ - modularize_sinatra.gemspec
76
+ has_rdoc: true
77
+ homepage: https://github.com/goyalankit/modularize_sinatra
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options: []
82
+
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.3.6
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Creates a modular skeleton for Sinatra application.
106
+ test_files: []
107
+