sinatras 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: de1c29ea24d11dc38e4eeb0d1b46571591dc91e5
4
+ data.tar.gz: 00eee0e2afc3d4048fdbce687ea4b7761ea779b2
5
+ SHA512:
6
+ metadata.gz: 0eff990fb293a406a9018099da2acaf094b4dfc3d13b796365b5da04fe5dc55a08cc12b342223a94efae922b5677a12202f33af2bd19afe788d074807cbdfa2d
7
+ data.tar.gz: 47f4a220c787e717c41e3444f0abbf2a2b6323b0c68d1eece7618294303d0fc6f386c218ecd4e74f5222ac67f861ddb040484cc326a19dce54a44649a12f1061
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sinatras.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 tomcha
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tomcha
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
+ # Sinatras
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sinatras'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sinatras
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/sinatras/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/sinatras ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sinatras'
4
+ Sinatras::Command.run(ARGV)
@@ -0,0 +1,79 @@
1
+ # encoding: utf-8
2
+
3
+ require 'optparse'
4
+
5
+ module Sinatras
6
+ class Command
7
+ module Options
8
+ def self.parse!(argv)
9
+ options = {}
10
+
11
+ sub_command_parsers = create_sub_command_parsers(options)
12
+ command_parser = create_command_parser
13
+
14
+
15
+ begin
16
+ command_parser.order!(argv)
17
+
18
+ options[:command] = argv.shift
19
+
20
+ sub_command_parsers[options[:command]].parse!(argv)
21
+
22
+ if options[:command] == 'new'
23
+ raise ArgumentError, "#{options[:command]} Appname not found." if argv.empty?
24
+ options[:appname] = String(argv.first)
25
+ end
26
+
27
+ rescue OptionParser::MissingArgument, OptionParser::InvalidOption, ArgumentError => e
28
+ abort e.message
29
+ end
30
+
31
+ options
32
+ end
33
+
34
+ def self.create_sub_command_parsers(options)
35
+ sub_command_parsers = Hash.new do |k, v|
36
+ raise ArgumentError, "'#{v}' is not sinatras sub command"
37
+ end
38
+
39
+ sub_command_parsers['new'] = OptionParser.new do |opt|
40
+ opt.banner = 'Usage: new <args>'
41
+ opt.on_tail('-h', '--help', 'Show this message'){|v| help_sub_command(opt)}
42
+ end
43
+
44
+ sub_command_parsers
45
+ end
46
+
47
+ def self.help_sub_command(parser)
48
+ puts parser.help
49
+ exit
50
+ end
51
+
52
+ def self.create_command_parser
53
+ command_parser = OptionParser.new do |opt|
54
+ sub_command_help = [
55
+ {name: 'new Appname', summary: 'create new project scalton'},
56
+ ]
57
+ opt.banner = "Usage: #{opt.program_name} [-h|--help][-v|--version] <command>[<args>]"
58
+ opt.separator ''
59
+ opt.separator "#{opt.program_name} Available Commands:"
60
+ sub_command_help.each do |command|
61
+ opt.separator [opt.summary_indent, command[:name].ljust(40), command[:summary]].join (' ')
62
+ end
63
+
64
+ opt.on_head('-h', '--help', ) do |v|
65
+ puts opt.help
66
+ exit
67
+ end
68
+
69
+ opt.on_head('-v', '--version', 'show program version') do |v|
70
+ opt.version = Sinatras::VERSION
71
+ puts opt.ver
72
+ exit
73
+ end
74
+ end
75
+ end
76
+ private_class_method :create_sub_command_parsers, :create_command_parser, :help_sub_command
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,148 @@
1
+ # encoding: utf-8
2
+
3
+ module Sinatras
4
+ #コマンドライン処理を行うクラス
5
+ # @auther tomcha_
6
+ class Command
7
+
8
+ def execute
9
+ options = Options.parse!(@argv)
10
+ sub_command = options.delete(:command)
11
+
12
+ tasks = case sub_command
13
+ when 'new'
14
+ new(options)
15
+ end
16
+ end
17
+
18
+ def self.run(argv)
19
+ new(argv).execute
20
+ end
21
+
22
+ def initialize(argv)
23
+ @argv = argv
24
+ end
25
+
26
+ private def make_dir(appname)
27
+ Dir.mkdir(appname, 0755)
28
+ puts "make directory ./" + appname + "/"
29
+ Dir.mkdir(appname + "/app", 0755)
30
+ puts "make directory ./" + appname + "/app/"
31
+ Dir.mkdir(appname + "/app/views", 0755)
32
+ puts "make directory ./" + appname + "/app/views/"
33
+ Dir.mkdir(appname + "/spec", 0755)
34
+ puts "make directory ./" + appname + "/spec/"
35
+ Dir.mkdir(appname + "/public", 0755)
36
+ puts "make directory ./" + appname + "/public/"
37
+ Dir.mkdir(appname + "/config", 0755)
38
+ puts "make directory ./" + appname + "/config/"
39
+ 1
40
+ end
41
+
42
+ private def make_file(appname)
43
+ File.open("./" + appname + "/Gemfile","w") do |file|
44
+ file.print <<__EOS__
45
+ source "https://rubygems.org"
46
+ gem 'sinatra' ~> '1.4.5'
47
+ gem 'haml' ~> '4.0.6'
48
+ gem 'rspec' ~> '3.2.0'
49
+ __EOS__
50
+ end
51
+ puts "make file ./" + appname + "/Gemfile"
52
+
53
+ File.open("./" + appname + "/config.ru","w") do |file|
54
+ classname = appname.split("",2)
55
+ file.puts "require './app/" + appname + "'"
56
+ file.puts "run " + classname[0].upcase + classname[1]
57
+ end
58
+ puts "make file ./" + appname + "/config.ru"
59
+
60
+ File.open("./" + appname + "/app/" + appname + ".rb","w") do |file|
61
+ classname = appname.split("",2)
62
+ file.print <<__EOS__
63
+ require 'sinatra/base'
64
+ require 'haml'
65
+
66
+ __EOS__
67
+ file.puts "class " + classname[0].upcase + classname[1] + "< Sinatra::Base"
68
+ file.print <<__EOS__
69
+ get '/' do
70
+ haml :index
71
+ end
72
+ end
73
+ __EOS__
74
+ end
75
+ puts "make file ./" + appname + "/app/" + appname + ".rb"
76
+
77
+ File.open("./" + appname + "/app/views/layout.haml","w") do |file|
78
+ file.print <<__EOS__
79
+ !!!
80
+ %html{lang: 'ja'}
81
+ %head
82
+ %meta{charset: 'utf-8'}
83
+ %title
84
+ hello,sinatras
85
+ %body
86
+ %div
87
+ =yield
88
+ __EOS__
89
+ end
90
+ puts "make file ./" + appname + "/app/views/layout.haml"
91
+
92
+ File.open("./" + appname + "/app/views/index.haml","w") do |file|
93
+ file.print <<__EOS__
94
+ %h1
95
+ Hello,Sinatras
96
+ %p
97
+ powerd by Sinatra
98
+ __EOS__
99
+ end
100
+ puts "make file ./" + appname + "/app/views/index.haml"
101
+ 1
102
+ end
103
+
104
+ private def change_permission(appname)
105
+ File.chmod(0644, "./" + appname + "/Gemfile")
106
+ puts "change permission file ./" + appname + "/Gemfile"
107
+ File.chmod(0644, "./" + appname + "/config.ru")
108
+ puts "change permission file ./" + appname + "/config.ru"
109
+ File.chmod(0644, "./" + appname + "/app/" + appname+ ".rb")
110
+ puts "change permission file ./" + appname + "/app/" + appname + ".rb"
111
+ File.chmod(0644, "./" + appname + "/app/views/layout.haml")
112
+ puts "change permission file ./" + appname + "/app/views/layout.haml"
113
+ File.chmod(0644, "./" + appname + "/app/views/index.haml")
114
+ puts "change permission file ./" + appname + "/app/views/index.haml"
115
+ 1
116
+ end
117
+
118
+ private def do_gitcommand(appname)
119
+ Dir.chdir("./#{appname}") do
120
+ init = `git init`
121
+ puts "git init is success." if init
122
+ add = `git add -A`
123
+ puts "git add -A is success." if add
124
+ comm = `git commit -m 'first commit'`
125
+ puts "git commit -m 'first commit' is success." if comm
126
+ end
127
+ 1
128
+ end
129
+
130
+ def new(options)
131
+ appname = options[:appname]
132
+ if options[:appname] !~ /^[a-z_]+[a-zA-Z0-9_]*$/
133
+ puts 'appname format is (a-z or _ ) + (alphabet,0-9, and _)'
134
+ exit
135
+ end
136
+ if (File.directory?(appname))
137
+ puts 'appname same name of the directory exist'
138
+ exit
139
+ end
140
+
141
+ make_dir(appname)
142
+ make_file(appname)
143
+ change_permission(appname)
144
+ do_gitcommand(appname)
145
+ 1
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,3 @@
1
+ module Sinatras
2
+ VERSION = "0.0.1"
3
+ end
data/lib/sinatras.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'sinatras/command'
2
+ require 'sinatras/command/options'
3
+ require "sinatras/version"
data/sinatras.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sinatras/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sinatras"
8
+ spec.version = Sinatras::VERSION
9
+ spec.authors = ["tomcha"]
10
+ spec.email = ["tomcha@tomcha.net"]
11
+ spec.summary = %q{It is a tool to create a template of web application to use the 'Sinatra'.}
12
+ spec.description = %q{sinatra's app make tool}
13
+ spec.homepage = "https://github.com/tomcha/sinatras"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 3.1.0"
24
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+
4
+ describe Sinatras do
5
+ it 'should have a version number' do
6
+ expect(Sinatras::VERSION).not_to be nil
7
+ end
8
+
9
+ describe Sinatras::Command do
10
+
11
+ describe '.run' do
12
+ before do
13
+ FileUtils.rm_rf("foo") if File.exists?("foo")
14
+ end
15
+
16
+ after(:all) do
17
+ FileUtils.rm_rf("foo") if File.exists?("foo")
18
+ end
19
+
20
+ let(:command){ Sinatras::Command.run(params) }
21
+ subject{ command }
22
+
23
+ context 'If new is passed as the first argument' do #第1引数にnewが渡された場合
24
+ context 'If passed only the first argument' do #第1引数のみ渡された場合
25
+ let(:params){ ['new'] }
26
+ it '' do
27
+ expect{command}.to raise_error SystemExit
28
+ end
29
+ end
30
+ context 'If the first argument and the second argument is passed' do #第1引数と第2引数が渡された場合
31
+ let(:params){ ['new', 'foo'] }
32
+ it { is_expected.to eq 1}
33
+ end
34
+ end
35
+
36
+ context 'If the new has not been passed to the first argument' do #第1引数にnewが渡されなかった場合
37
+ context 'If passed only the first argument' do #第1引数のみ渡された場合
38
+ let(:params){ ['mew'] }
39
+ # it { is_expected.not_to eq 1}
40
+ it '' do
41
+ expect{command}.to raise_error SystemExit
42
+ end
43
+ end
44
+ context 'If the first argument and the second argument is passed' do #第1引数と第2引数が渡された場合
45
+ let(:params){ ['mew', 'hoge'] }
46
+ # it { is_expected.not_to eq 1}
47
+ it '' do
48
+ expect{command}.to raise_error SystemExit
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ __END__
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'sinatras'
3
+
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatras
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - tomcha
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ description: sinatra's app make tool
56
+ email:
57
+ - tomcha@tomcha.net
58
+ executables:
59
+ - sinatras
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/sinatras
70
+ - lib/sinatras.rb
71
+ - lib/sinatras/command.rb
72
+ - lib/sinatras/command/options.rb
73
+ - lib/sinatras/version.rb
74
+ - sinatras.gemspec
75
+ - spec/sinatras_spec.rb
76
+ - spec/spec_helper.rb
77
+ homepage: https://github.com/tomcha/sinatras
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.4.5
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: It is a tool to create a template of web application to use the 'Sinatra'.
101
+ test_files:
102
+ - spec/sinatras_spec.rb
103
+ - spec/spec_helper.rb