francis 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/francis +6 -0
  2. data/lib/francis.rb +75 -0
  3. metadata +47 -0
data/bin/francis ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'francis'
3
+ args = ARGV.dup
4
+ ARGV.clear
5
+ command = args.shift.strip
6
+ Francis.dispatch(command, args)
data/lib/francis.rb ADDED
@@ -0,0 +1,75 @@
1
+ # A simple gem & CLI for setting up a working directory
2
+ # structure for Sinatra apps.
3
+ #
4
+ # Author:: Ian Kent (mailto:ian@iankent.me)
5
+ # License:: Distributed under the same terms as Ruby
6
+
7
+ # This is the only and main class for the gem.
8
+
9
+ class Francis
10
+ @@folders = ["app","tmp","db","public","views","public/css","public/js","public/img"]
11
+ @@files = ["app/app.rb", "db/db.rb", "tmp/restart.txt", "Gemfile","config.ru"]
12
+
13
+ # Determines which method to call.
14
+ def self.dispatch(command, args)
15
+ case command
16
+ when 'new'
17
+ Francis.new(args[0],args[1..-1])
18
+ when 'folders'
19
+ Francis.folders
20
+ when 'files'
21
+ Francis.files
22
+ else
23
+ Francis.help
24
+ end
25
+ end
26
+
27
+ # Creates a new working directory for Sinatra apps,
28
+ # it takes two variables: a name to call the directory
29
+ # and an option array.
30
+ def self.new(name, options)
31
+ dir = Dir.getwd
32
+ if Dir.exists?("#{dir}/#{name}")
33
+ abort("There is already a folder with that name, please choose another.")
34
+ else
35
+ Dir.mkdir("#{dir}/#{name}")
36
+ end
37
+ Dir.chdir("#{dir}/#{name}")
38
+ @@folders.each do |f|
39
+ Dir.mkdir(f)
40
+ end
41
+ @@files.each do |f|
42
+ File.new(f,"w")
43
+ end
44
+ File.open("Gemfile","a") do |f|
45
+ f.write("source 'https://rubygems.org'\ngem 'sinatra'")
46
+ end
47
+ File.open("app/app.rb","a") do |f|
48
+ f.write("get '/' do\n 'Hello world!'\nend")
49
+ end
50
+ File.open("config.ru","a") do |f|
51
+ f.write("require 'bundler'\nBundler.require\nrequire './app/app'\nrequire './db/db'\nrun Sinatra::Application")
52
+ end
53
+ if options.include?("--git")
54
+ system("git init")
55
+ end
56
+ puts "Sinatra app '#{name}' created!"
57
+ end
58
+
59
+ # Prints the folders that are included in the directory
60
+ # set up.
61
+ def self.folders
62
+ puts @@folders
63
+ end
64
+
65
+ # Prints the files that are included in the directory
66
+ # set up.
67
+ def self.files
68
+ puts @@files
69
+ end
70
+
71
+ # Prints the help file.
72
+ def self.help
73
+ puts "Usage:\n\nfrancis new <appname> [--git]\n\nCreates a new Sinatra app.\n\n<appname> => Name of the new directory\n\n--git => If present, will set the new directory up as a git repository\n\nfrancis folders\n\nPrints a list of folders that are created when francis new is run.\n\nfrancis files\n\nPrints a list of files that are created when francis new is run."
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: francis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ian Kent
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-01 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A quick start for Sinatra apps
15
+ email: ian@iankent.me
16
+ executables:
17
+ - francis
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/francis.rb
22
+ - bin/francis
23
+ homepage: http://code.iankent.me/francis
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.23
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: Francis
47
+ test_files: []