sinatra-cl 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
- # Sinatra::Cl
2
-
3
- TODO: Write a gem description
1
+ # Sinatra-cl
4
2
 
5
3
  This is a sinatra app generator based on [Ashley Williams'](http://heyashleyashley.com/) [Ratpack](https://github.com/ashleygwilliams/ratpack)
6
4
 
@@ -19,7 +17,9 @@ Generate a Sinatra App:
19
17
  $ bundle install
20
18
  $ shotgun
21
19
 
22
- TODO: Write usage instructions here
20
+ By default, Sinatra-cl generates a template with twitter bootstrap, to create a sinatra app without twitter bootstrap run:
21
+
22
+ $ sinatra-cl new app --no-bootstrap
23
23
 
24
24
  ## Contributing
25
25
 
data/assets/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_STORE
2
+ *ds_store
3
+ *.db
data/assets/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+
4
+ gem "sinatra"
5
+ gem "sqlite3"
6
+ gem "activerecord"
7
+ gem "sinatra-activerecord"
8
+ gem "rake"
9
+
10
+ group :development do
11
+ gem "shotgun"
12
+ gem "tux"
13
+ end
data/assets/README.md ADDED
@@ -0,0 +1,23 @@
1
+ #ratpack
2
+
3
+ a simple boilerplate for creating production-ready sinatra apps that use activerecord and sqlite
4
+
5
+ twitterbootstrap using html and css are included.
6
+
7
+ if ya want haml and sass, be on the look for classy.
8
+
9
+ ## Up and running
10
+ 1. `bundle install`
11
+ 2. `shotgun`
12
+ 3. visit `localhost:9393`
13
+
14
+ ## Gemfile
15
+ - [sinatra](http://www.sinatrarb.com/): web framework
16
+ - [sqlite3](https://github.com/luislavena/sqlite3-ruby): Database
17
+ - [activerecord](http://guides.rubyonrails.org/active_record_querying.html): ORM
18
+ - [sinatra-activerecord](https://github.com/bmizerany/sinatra-activerecord)
19
+ - [rake](http://rake.rubyforge.org/)
20
+
21
+ ### Development
22
+ * [shotgun](https://github.com/rtomayko/shotgun)
23
+ * [tux](http://tagaholic.me/2011/04/10/tux-a-sinatra-console.html)
data/assets/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "./app"
2
+ require "sinatra/activerecord/rake"
data/assets/app.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ Dir.glob('./lib/*.rb') do |model|
5
+ require model
6
+ end
7
+
8
+ module Name
9
+ class App < Sinatra::Application
10
+
11
+ #configure
12
+ configure do
13
+ set :root, File.dirname(__FILE__)
14
+ set :public_folder, 'public'
15
+ end
16
+
17
+ #database
18
+ set :database, "sqlite3:///#{argument}.db"
19
+
20
+ #filters
21
+
22
+ #routes
23
+ get '/' do
24
+ erb :index
25
+ end
26
+
27
+ #helpers
28
+ helpers do
29
+ def partial(file_name)
30
+ erb file_name, :layout => false
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ class Model < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,2 @@
1
+ <h1>classy</h1>
2
+ <h2>as fuck</h2>
@@ -0,0 +1,8 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ </head>
5
+ <body>
6
+ <%= yield %>
7
+ </body>
8
+ </html>
data/lib/directory.rb ADDED
@@ -0,0 +1,28 @@
1
+ module Sinatra
2
+ module Cl
3
+ class Directory
4
+
5
+ attr_reader :app_name, :flags
6
+
7
+ def initialize(app_name, flags)
8
+ @app_name = app_name
9
+ @flags = flags
10
+ end
11
+
12
+ def build
13
+ parent
14
+ end
15
+
16
+ def parent
17
+ Dir.mkdir(app_name)
18
+ Dir.mkdir("#{app_name}/lib")
19
+ Dir.mkdir("#{app_name}/public")
20
+ Dir.mkdir("#{app_name}/views")
21
+ Dir.mkdir("#{app_name}/public/css")
22
+ Dir.mkdir("#{app_name}/public/img")
23
+ Dir.mkdir("#{app_name}/public/js")
24
+ end
25
+
26
+ end
27
+ end
28
+ end
data/lib/files.rb ADDED
@@ -0,0 +1,69 @@
1
+ module Sinatra
2
+ module Cl
3
+ class Files
4
+
5
+ attr_reader :app_name, :flags
6
+
7
+ def initialize(app_name, flags)
8
+ @app_name = app_name
9
+ @flags = flags
10
+ end
11
+
12
+ def build
13
+ top_level
14
+ lib_files
15
+ public_files unless no_bootstrap?
16
+ no_bootstrap? ? view_files_no_bootstrap : view_files
17
+ end
18
+
19
+ def config
20
+ File.open("#{app_name}/config.ru", "w+") { |io|
21
+ io << "require File.join(File.dirname(__FILE__), 'app.rb')\nrun Name::#{app_name.capitalize}"
22
+ }
23
+ end
24
+
25
+ def no_bootstrap?
26
+ flags.include?(:no_bootstrap)
27
+ end
28
+
29
+
30
+ def top_level
31
+
32
+ FileList.new('./assets/*', './assets/.gitignore').each do |path|
33
+ FileUtils.cp(path,"#{app_name}/#{path.pathmap("%f")}") unless File.directory?(path)
34
+ end
35
+
36
+ config
37
+ end
38
+
39
+ def public_files
40
+ FileList.new('./assets/public/**/*.*').each do |path|
41
+ new_path = path.pathmap("%p").split("/").pop(3).unshift("#{app_name}").join("/")
42
+ FileUtils.cp(path, new_path)
43
+ end
44
+ end
45
+
46
+ def view_files_no_bootstrap
47
+ FileList.new('./assets/views_no_bootstrap/**/*.*').each do |path|
48
+ new_path = path.pathmap("%p").split("/").pop(1).unshift("#{app_name}","views").join("/")
49
+ FileUtils.cp(path, new_path)
50
+ end
51
+ end
52
+
53
+ def lib_files
54
+ FileList.new('./assets/lib/**/*.*').each do |path|
55
+ new_path = path.pathmap("%p").split("/").pop(2).unshift("#{app_name}").join("/")
56
+ FileUtils.cp(path, new_path)
57
+ end
58
+ end
59
+
60
+ def view_files
61
+ FileList.new('./assets/views/**/*.*').each do |path|
62
+ new_path = path.pathmap("%p").split("/").pop(2).unshift("#{app_name}").join("/")
63
+ FileUtils.cp(path, new_path)
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+ end
data/lib/flag.rb ADDED
@@ -0,0 +1,26 @@
1
+ class Flag
2
+ attr_reader :flag_name
3
+
4
+ def initialize(flag_name)
5
+ @flag_name = flag_name
6
+ end
7
+
8
+ def check_flag
9
+ self.send(flag_name.match(/\A(--)(\S*)/).to_a.last.gsub("-","_").to_sym)
10
+ end
11
+
12
+ def method_missing
13
+ raise "There is no flag, #{flag_name}\nOur supported flags are currently:#{supported_flags}"
14
+ end
15
+
16
+ def supported_flags
17
+ ["--no-bootstrap"].each do |flag|
18
+ puts "#{flag}"
19
+ end
20
+ end
21
+
22
+ def no_bootstrap
23
+ :no_bootstrap
24
+ end
25
+
26
+ end
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Cl
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  end
data/lib/sinatra-cl.rb CHANGED
@@ -1,36 +1,36 @@
1
1
  require_relative "sinatra-cl/version"
2
+ require_relative "files"
3
+ require_relative "directory"
4
+ require_relative "flag"
2
5
  require 'rake'
3
6
  require 'fileutils'
4
7
 
5
8
  module Sinatra
6
9
  module Cl
7
- class Generate
8
- attr_reader :command, :argument
10
+ class Build
11
+ attr_accessor :app_name
12
+ attr_reader :command, :flags
9
13
 
10
14
  def initialize(user_input)
11
- @command, @argument = user_input
15
+ @command = user_input[0]
16
+ @app_name = user_input[1]
17
+ @flags = parse_flags(user_input[2..-1])
12
18
  end
13
19
 
14
- def execute_new(argument)
15
- argument = "sinatra-app" if argument.nil?
16
- build_parent
17
- build_gem_file
18
- build_gitignore
19
- build_readme
20
- build_rakefile
21
- build_apprb
22
- build_config
23
- build_model
24
- build_css
25
- build_img
26
- build_js
27
- build_erb
20
+ def parse_flags(flags)
21
+ flags.map{|flag_name| Flag.new(flag_name).check_flag}
28
22
  end
29
23
 
30
- def build_app
24
+ def execute_new(app_name)
25
+ app_name = "sinatra-app" if app_name.nil?
26
+ parent
27
+ files
28
+ end
29
+
30
+ def app
31
31
  case command
32
32
  when "new"
33
- execute_new(argument)
33
+ execute_new(app_name)
34
34
  when "help"
35
35
  "Usage:\nnew: sinatra-cl new [APPNAME]"
36
36
  else
@@ -38,174 +38,18 @@ module Sinatra
38
38
  end
39
39
  end
40
40
 
41
- def build_parent
42
- Dir.mkdir(argument)
43
- Dir.mkdir("#{argument}/lib")
44
- Dir.mkdir("#{argument}/public")
45
- Dir.mkdir("#{argument}/views")
46
- Dir.mkdir("#{argument}/public/css")
47
- Dir.mkdir("#{argument}/public/img")
48
- Dir.mkdir("#{argument}/public/js")
49
- end
50
-
51
- def build_gem_file
52
- File.open("#{argument}/GEMFILE", "w+") { |io|
53
- io << <<-END
54
- source "https://rubygems.org"
55
-
56
-
57
- gem "sinatra"
58
- gem "sqlite3"
59
- gem "activerecord"
60
- gem "sinatra-activerecord"
61
- gem "rake"
62
-
63
- group :development do
64
- gem "shotgun"
65
- gem "tux"
66
- end
67
- END
68
- }
41
+ def parent
42
+ Sinatra::Cl::Directory.new(app_name, flags).build
69
43
  end
70
44
 
71
- def build_gitignore
72
- File.open("#{argument}/.gitignore", "w+") { |io|
73
- io << <<-END
74
- .DS_STORE
75
- *ds_store
76
- *.db
77
- END
78
- }
45
+ def files
46
+ Sinatra::Cl::Files.new(app_name, flags).build
79
47
  end
80
48
 
81
- def build_readme
82
- File.open("#{argument}/README.md", "w+") { |io|
83
- io << <<-END
84
- #ratpack
85
-
86
- a simple boilerplate for creating production-ready sinatra apps that use activerecord and sqlite
87
-
88
- twitterbootstrap using html and css are included.
89
-
90
- if ya want haml and sass, be on the look for classy.
91
-
92
- ## Up and running
93
- 1. `bundle install`
94
- 2. `shotgun`
95
- 3. visit `localhost:9393`
96
-
97
- ## Gemfile
98
- - [sinatra](http://www.sinatrarb.com/): web framework
99
- - [sqlite3](https://github.com/luislavena/sqlite3-ruby): Database
100
- - [activerecord](http://guides.rubyonrails.org/active_record_querying.html): ORM
101
- - [sinatra-activerecord](https://github.com/bmizerany/sinatra-activerecord)
102
- - [rake](http://rake.rubyforge.org/)
103
-
104
- ### Development
105
- * [shotgun](https://github.com/rtomayko/shotgun)
106
- * [tux](http://tagaholic.me/2011/04/10/tux-a-sinatra-console.html)
107
- END
108
- }
109
- end
110
-
111
- def build_rakefile
112
- File.open("#{argument}/Rakefile", "w+") { |io|
113
- io << <<-END
114
- require "./app"
115
- require "sinatra/activerecord/rake"
116
- END
117
- }
118
- end
119
-
120
- def build_apprb
121
- File.open("#{argument}/app.rb", "w+") { |io|
122
- io << <<-END
123
- require 'bundler'
124
- Bundler.require
125
-
126
- Dir.glob('./lib/*.rb') do |model|
127
- require model
128
- end
129
-
130
- module Name
131
- class App < Sinatra::Application
132
-
133
- #configure
134
- configure do
135
- set :root, File.dirname(__FILE__)
136
- set :public_folder, 'public'
137
- end
138
-
139
- #database
140
- set :database, "sqlite3:///#{argument}.db"
141
-
142
- #filters
143
-
144
- #routes
145
- get '/' do
146
- erb :index
147
- end
148
-
149
- #helpers
150
- helpers do
151
- def partial(file_name)
152
- erb file_name, :layout => false
153
- end
154
- end
155
-
156
- end
157
- end
158
- END
159
- }
160
- end
161
-
162
- def build_config
163
- File.open("#{argument}/config.ru", "w+") { |io|
164
- io << <<-END
165
- require File.join(File.dirname(__FILE__), 'app.rb')
166
-
167
- run Name::App
168
- END
169
- }
170
- end
171
-
172
- def build_model
173
- File.open("#{argument}/lib/model.rb", "w+") { |io|
174
- io << <<-END
175
- class Model < ActiveRecord::Base
176
-
177
- end
178
- END
179
- }
180
- end
181
-
182
- def build_css
183
- FileList.new('./assets/*.css').each do |path|
184
- FileUtils.cp(path,"#{argument}/public/css/#{path.pathmap("%f")}")
185
- end
186
- end
187
-
188
- def build_img
189
- FileList.new('./assets/*.png','./assets/*.jpg').each do |path|
190
- FileUtils.cp(path,"#{argument}/public/img/#{path.pathmap("%f")}")
191
- end
192
- end
193
-
194
- def build_js
195
- FileList.new('./assets/*.js').each do |path|
196
- FileUtils.cp(path,"#{argument}/public/js/#{path.pathmap("%f")}")
197
- end
198
- end
199
-
200
- def build_erb
201
- FileList.new('./assets/*.erb').each do |path|
202
- FileUtils.cp(path,"#{argument}/views/#{path.pathmap("%f")}")
203
- end
204
- end
205
49
 
206
50
  end
207
51
  end
208
52
  end
209
53
 
210
- s = Sinatra::Cl::Generate.new(@input)
211
- s.build_app
54
+ s = Sinatra::Cl::Build.new(@input)
55
+ s.app
data/sinatra-cl.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
7
7
  gem.name = "sinatra-cl"
8
8
  gem.version = Sinatra::Cl::VERSION
9
9
  gem.authors = ["jeffreybaird"]
10
- gem.email = ["jlbaird87@gmail.com"]
10
+ gem.email = ["jeff@jeffreyleebaird.com"]
11
11
  gem.description = "This uses Ashley William's ratpack setup to scaffold a sinatra app"
12
12
  gem.summary = "This is a test"
13
13
  gem.homepage = ""
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-cl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-07 00:00:00.000000000 Z
12
+ date: 2013-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 1.0.0
30
30
  description: This uses Ashley William's ratpack setup to scaffold a sinatra app
31
31
  email:
32
- - jlbaird87@gmail.com
32
+ - jeff@jeffreyleebaird.com
33
33
  executables:
34
34
  - sinatra-cl
35
35
  extensions: []
@@ -40,16 +40,27 @@ files:
40
40
  - LICENSE.txt
41
41
  - README.md
42
42
  - Rakefile
43
- - assets/bootstrap-responsive.min.css
44
- - assets/bootstrap.min.css
45
- - assets/bootstrap.min.js
46
- - assets/custom.css
47
- - assets/glyphicons-halflings-white.png
48
- - assets/glyphicons-halflings.png
49
- - assets/index.erb
50
- - assets/layout.erb
51
- - assets/rapack.jpg
43
+ - assets/.gitignore
44
+ - assets/Gemfile
45
+ - assets/README.md
46
+ - assets/Rakefile
47
+ - assets/app.rb
48
+ - assets/lib/model.rb
49
+ - assets/public/css/bootstrap-responsive.min.css
50
+ - assets/public/css/bootstrap.min.css
51
+ - assets/public/css/custom.css
52
+ - assets/public/img/glyphicons-halflings-white.png
53
+ - assets/public/img/glyphicons-halflings.png
54
+ - assets/public/img/rapack.jpg
55
+ - assets/public/js/bootstrap.min.js
56
+ - assets/views/index.erb
57
+ - assets/views/layout.erb
58
+ - assets/views_no_bootstrap/index.erb
59
+ - assets/views_no_bootstrap/layout.erb
52
60
  - bin/sinatra-cl
61
+ - lib/directory.rb
62
+ - lib/files.rb
63
+ - lib/flag.rb
53
64
  - lib/sinatra-cl.rb
54
65
  - lib/sinatra-cl/version.rb
55
66
  - sinatra-cl.gemspec
File without changes
File without changes
File without changes
File without changes