sinatra-chassis 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
data/README.md CHANGED
@@ -1,14 +1,473 @@
1
- ## Chassis
1
+ # Chassis
2
2
 
3
- Chassis is a mutable framework extension for Sinatra that's designed not just to help you write less code, but to help you focus on less code.
3
+ Chassis is a mutable framework extension for Sinatra that's designed to help you focus on less code by writing less code.
4
4
 
5
- gem install sinatra-chassis
5
+ It starts by generating a basic Sinatra application, bootstrapped to run on Rack. As your application grows, Chassis will adapt itself to your changes. You choose the gems, design patterns, scope, and size of your application.
6
6
 
7
- ### Instructions
7
+ Focus only on what you use, and forget the rest.
8
8
 
9
- http://jarrodtaylor.github.com/sinatra-chassis/
10
9
 
11
- ### License
10
+ [jarrodtaylor.github.io/sinatra-chassis](http://jarrodtaylor.github.io/sinatra-chassis/)
11
+
12
+ ## Getting Started
13
+
14
+ ### Prerequisites
15
+
16
+ - A working Ruby installation: [ruby-lang.org](http://www.ruby-lang.org/)
17
+ - Experience with Sinatra: [sinatrarb.com](http://www.sinatrarb.com)
18
+
19
+ ### Installation
20
+
21
+ Install Chassis as a RubyGem:
22
+
23
+ ```bash
24
+ ~: gem install sinatra-chassis
25
+ ```
26
+
27
+ ### Generating an Application
28
+
29
+ The Chassis gem comes with a cli for generating ready-to-run applications:
30
+
31
+ ```
32
+ ~: chassis
33
+ The chassis command creates a new chassis app.
34
+
35
+ Usage:
36
+ chassis [options] app_path
37
+
38
+ Example:
39
+ chassis -g -h ~/Projects/my_app
40
+
41
+ Options:
42
+ -g, --git Init a git repo, add the first commit
43
+ -h, --heroku Create a Heroku app
44
+ --skip-bundle Don't run bundle install
45
+ -e, --extension Create a Chassis extension
46
+ ```
47
+
48
+ The ```chassis``` command will generate a boilerplate application and bundle it's gems. Adding ```-g``` will initialize a git repo and add the first commit. Adding ```-h``` will create and link to an app on Heroku. Adding ```--skip-bundle``` will skip over the gem bundling step. And ```-e``` will generate a Chassis extension template.
49
+
50
+ > The -g and -h switches assume git and the heroku toolbelt to already be installed.
51
+
52
+ Create a new application and take a look around:
53
+
54
+ ```bash
55
+ ~: chassis SampleApp
56
+ ~: cd SampleApp
57
+ ```
58
+
59
+ --
60
+
61
+ ### What's Included
62
+
63
+ ##### app.rb
64
+ > Hooks together all the pieces of the application:
65
+ > - Requires the gems in Gemfile.lock
66
+ > - Requires the Chassis helpers
67
+ > - Requires sinatra/reloader in development
68
+ > - Enables sessions and sets a session_secret
69
+ > - Requires the default load path
70
+ > - Adds a sample route
71
+
72
+ ##### config.ru
73
+ > Loads app.rb on a Rack server.
74
+
75
+ ##### /tmp/restart.txt
76
+ > Used to restart the application on a Rack server.
77
+
78
+ ##### /public
79
+ > For storing publicly accessible files, such as JavaScripts and Stylesheets, as well as:
80
+ > - /public/robots.txt for handling web crawlers
81
+ > - /public/favicon.ico for adding a favicon to browser bookmarks and address bars
82
+
83
+ ##### Gemfile and Gemfile.lock
84
+ > For managing gems.
85
+
86
+ ##### /views/layout.erb
87
+ > A stock HTML5 template with alert and yield methods already in the body.
88
+
89
+ ##### Rakefile
90
+ > Loads app.rb, the Chassis rake tasks, rake tasks from the loaded extensions, and all your own .rake scripts from /tasks.
91
+
92
+ ##### .gitignore
93
+ > For keeping unnecessary files out of your git repository.
94
+
95
+ ##### README.md
96
+ > A place to put instructions for using your application.
97
+
98
+ ### Running on Localhost
99
+
100
+ Chassis is based on a standard Sinatra application, and runs the same way:
101
+
102
+ ```bash
103
+ ~/SampleApp: ruby app.rb
104
+ ```
105
+
106
+ Your application is now running at [localhost:4567](http://localhost:4567/).
107
+
108
+ > Use ```Ctrl-C``` to stop the local server.
109
+
110
+ ## The Basics
111
+
112
+ ### Loading Your Application
113
+
114
+ Your application structure is defined in app.rb with the ```require_directory``` method, allowing you to organize your application code into multiple files and load them in the proper order.
115
+
116
+ ```ruby
117
+ require_directory([
118
+ 'config',
119
+ 'settings',
120
+ 'modules',
121
+ 'helpers',
122
+ 'libraries',
123
+ 'models',
124
+ 'controllers',
125
+ 'routes'
126
+ ])
127
+ ```
128
+
129
+ ```require_directory``` will require all the Ruby scripts from each directory it's passed, and you can add your own directory structure to the Array.
130
+
131
+ ### Adding Route Handlers
132
+
133
+ Namespaced routes and tests can be generated with the rake task ```sinatra:add:routes[namespace]```. The ```[namespace]``` argument is required.
134
+
135
+ ```bash
136
+ ~/SampleApp: rake sinatra:add:routes[users]
137
+ # => add ./routes/users.rb
138
+ # => add ./tests/routes/users_tests.rb
139
+ ```
140
+
141
+ ### CoffeeScript and Sass
142
+
143
+ CoffeeScript and Sass files in the /public directory will be automatically compiled when requested. Just link to them as if linking to a .js or .css file:
144
+
145
+ ```html
146
+ <head>
147
+ <!-- Compile and load /public/js/global.coffee -->
148
+ <script type="text/javascript" src="/js/global.js"></script>
149
+
150
+ <!-- Compile and load /public/css/theme.scss -->
151
+ <link rel="stylesheet" type="text/css" href="/css/theme.css">
152
+ </head>
153
+ ```
154
+
155
+ > Notice the .js and .css extensions. If a .js or .css file exists in the same directory and with the same name as a .coffee or .scss file, the .js or .css file will be loaded. This allows assets to be precompiled without changing the script and link tags.
156
+
157
+ #### Precompiling
158
+
159
+ Compiling CoffeeScript and Sass is generally too slow to be good practice on a production server. The solution is to work with .coffee and .scss during development, then precompile them into .js and .css for deployment.
160
+
161
+ The task ```rake assets:precompile``` will compile all .coffee and .scss files in /public into .js and .css files of the same name.
162
+
163
+ ```bash
164
+ ~/SampleApp: rake assets:precompile
165
+ ```
166
+
167
+ Web servers will see the .js and .css files first, bypassing the .coffee and .scss files completely.
168
+
169
+ > Precompiled assets are automatically minified.
170
+
171
+ If you need to use "bare" CoffeeScript, just set ```Tilt::CoffeeScriptTemplate.default_bare``` to true. On-the-fly and precompiled .coffee files will the compiled as bare JavaScript.
172
+
173
+ Adding assets:precompile to your deploy scripts will automate this process, as well as keep compiled files out of source control.
174
+
175
+ > Heroku already does this by default, it works with their read-only filesystem.
176
+
177
+ The task ```rake assets:decompile``` will remove the compiled .js and .css files.
178
+
179
+ ```bash
180
+ ~/SampleApp: rake assets:decompile
181
+ ```
182
+
183
+ #### Assets Path
184
+
185
+ By default, Chassis uses /public for .coffee and .scss files. To use other directories, add them to the ```assets_path``` setting:
186
+
187
+ ```ruby
188
+ set :assets_path, ['public', 'scripts']
189
+ ```
190
+
191
+ ```html
192
+ <head>
193
+ <!-- Compile and load /scripts/global.coffee -->
194
+ <script type="text/javascript" src="/scripts/global.js"></script>
195
+ </head>
196
+ ```
197
+
198
+ > All .coffee and .scss files will be moved to /public when precompiled.
199
+
200
+ ### Mobile Templates
201
+
202
+ In cases where responsive design just won't work, Chassis can find mobile view templates and layouts. Prefix your view template extension with ```.mobile``` and it will be sent to mobile devices only.
203
+
204
+ For example: ```hello_world.erb``` would have the mobile counterpart ```hello_world.mobile.erb```, and ```layout.haml``` would have the mobile counterpart ```layout.mobile.haml```.
205
+
206
+ To enable mobile templates, use the ```mobile_views``` setting:
207
+
208
+ ```ruby
209
+ enable :mobile_views
210
+ ```
211
+
212
+ Mobile devices are determined by their user agents, which are listed as an Array of regular expressions in the ```mobile_user_agents``` setting. The default setting applies to iPhone and Android devices, but you're free to override it:
213
+
214
+ ```ruby
215
+ set :mobile_user_agents, [/iPhone/, /Android.*AppleWebKit/]
216
+ ```
217
+
218
+ ### Catch-all Route Handling
219
+
220
+ Sinatra evaluates all the routes in your application and returns a 404 Not Found error if it doesn't find a match. Chassis intercepts this error and looks in the /views directory for a directory/template combination that matches the request path before passing the request to an error page.
221
+
222
+ For example: A request for ```/hello/world``` will first look for the route handler ```get('/hello/world')```. If the route handler doesn't exist, it will then look for the template ```/views/hello/world.erb```. If the template doesn't exits, it will raise a 404 Not Found error.
223
+
224
+ The template extension/rendering engine doesn't matter: ```/views/hello/world.erb``` will work just as well as ```/views/hello/world.haml```.
225
+
226
+ To disable catch-all route handling:
227
+
228
+ ```ruby
229
+ disable :catch_all_route
230
+ ```
231
+
232
+ ### Production Error Pages
233
+
234
+ No production application should be without well styled error pages. Chassis adds a basic error page, only shown when running in production.
235
+
236
+ To use a your own custom error page, create the view template ```/views/error.erb```. Chassis makes the error available to the template with the variables code and message:
237
+
238
+ ```erb
239
+ <h1>Error <%= code %></h1>
240
+ <hr />
241
+ <h2><%= message %></h2>
242
+ ```
243
+
244
+ > Note that when your application is running in development mode, you'll still see the usual Sinatra error pages.
245
+
246
+ ### Running Tests
247
+
248
+ Any test scripts in /tests can be run with the rake task ```chassis:test[file]```:
249
+
250
+ ```bash
251
+ ~/SampleApp: rake chassis:test[routes/users_tests]
252
+ ```
253
+
254
+ Leaving out the ```[file]``` argument will run everything in /tests:
255
+
256
+ ```bash
257
+ ~/SampleApp: rake chassis:test
258
+ ```
259
+
260
+ ### Adding Rake Tasks
261
+
262
+ In addition to the Chassis rake tasks, any ```.rake``` files you add to the /tasks directory will automatically be available.
263
+
264
+ ### Interactive Ruby Shell
265
+
266
+ To load your application in an IRB session:
267
+
268
+ ```bash
269
+ ~/SampleApp: rake chassis:irb
270
+ irb(main):001:0> settings.catch_all_route
271
+ => true
272
+ irb(main):002:0> exit
273
+ ```
274
+
275
+ ## Helpers
276
+
277
+ Chassis comes with a few Sinatra helpers to speed up coding of commonly reused elements.
278
+
279
+ ### Active Links
280
+
281
+ To compare links with the current URL, use the active helper:
282
+
283
+ ```erb
284
+ <a href="/hello/world" class="<%= active('hello') %>">Hi</a>
285
+ # => <a href="/hello/world" class="active">Hi</a>
286
+ <a href="/goodbye/world" class="<%= active('goodbye') %>">Bye</a>
287
+ # => <a href="/goodbye/world" class="">Bye</a>
288
+ ```
289
+
290
+ > Style a.active links in your CSS for "sticky" links.
291
+
292
+ ### Alerting Users
293
+
294
+ The alert helper uses rack-flash to send one-time messages to users:
295
+
296
+ ```ruby
297
+ get '/send/message/?'
298
+ flash[:alert] = 'This is a public service announcement.'
299
+ redirect '/hello/world'
300
+ end
301
+ ```
302
+
303
+ ```erb
304
+ <%= alert %>
305
+ # => <div id='alert'>This is a public service announcement.</div>
306
+ ```
307
+
308
+ > Flash empties itself after each request, so your message will only display once.
309
+
310
+ ### Date Selects
311
+
312
+ The ```date_select``` helper, when combined with the Sinatra ```time_for``` helper, makes converting dates to and from DateTime objects for a database simple:
313
+
314
+ ```erb
315
+ <form>
316
+ <%= date_select(DateTime.now,
317
+ select_class: 'updated_at',
318
+ select_id: 'updated_at',
319
+ select_name: 'updated_at',
320
+ start_year: 1999,
321
+ end_year: 2021,
322
+ day_first: true,
323
+ month_name: false) %>
324
+ </form>
325
+ ```
326
+
327
+ A valid DateTime object is the only required argument. The others are recommended:
328
+
329
+ **select_name**: name attribute for fields, appended with _day, _month, or _year
330
+
331
+ **select_id**: id attribute for fields, appended with _day, _month, or _year
332
+
333
+ **select_class**: class attribute for fields
334
+
335
+ **start_year**: first year to use in year select (default: 3 years ago)
336
+
337
+ **end_year**: last year to use in year select (default: 3 years from now)
338
+
339
+ **day_first**: true/false to show the day before the month (default: false)
340
+
341
+ **month_name**: true/false to display month names (default: false)
342
+
343
+ > For easy site-wide styling, generated select fields always have the classes ```month_select```, ```day_select```, and ```year_select```.
344
+
345
+ To convert back to a DateTime object, use the ```time_for``` Sinatra helper on the submitted form fields:
346
+
347
+ ```ruby
348
+ time_for("#{params[:dob_month]}-#{params[:dob_day]}-#{params[:dob_year]}")
349
+ ```
350
+
351
+ ### Hiding Elements
352
+
353
+ When it's necessary to hide elements based on Ruby conditionals:
354
+
355
+ ```erb
356
+ <div style="<%= hidden unless @user.recent? %>">Hello, world!</div>
357
+ # => <div style="display: none;">Hello, world!</div>
358
+ ```
359
+
360
+ ### Numerability
361
+
362
+ Ruby uses duck typing, but incompatible types are still incompatible. To find out if a String can be used as a Number:
363
+
364
+ ```ruby
365
+ numeric?('1')
366
+ # => true
367
+ numeric?('hello')
368
+ # => false
369
+ ```
370
+
371
+ ### Titles
372
+
373
+ Titleizing a String will uppercase the first letter of each word:
374
+
375
+ ```ruby
376
+ titleize('hello world')
377
+ # => 'Hello World'
378
+ ```
379
+
380
+ ### Truncation
381
+
382
+ The truncate helper will truncate both Strings and Numbers:
383
+
384
+ ```ruby
385
+ truncate('Lorem ipsum dolor sit amet.', word_count: 3, end_string: '...')
386
+ # => 'Lorem ipsum dolor...'
387
+ truncate(1.234000, decimal: 1)
388
+ # => 1.2
389
+ truncate(1.234000, decimal: 5)
390
+ # => 1.234
391
+ truncate(1.234000, decimal: 5, trailing_zeros: true)
392
+ # => '1.23400'
393
+ ```
394
+
395
+ > ```truncate()``` will try to round numbers by default. For simple truncation, pass ```round: false```.
396
+
397
+ ## Extensions
398
+
399
+ Chassis can be easily extended to work with other gems, databases, APIs, design patterns, etc. Extensions are packaged as gems, and included in your Gemfile. Example:
400
+
401
+ ```ruby
402
+ gem 'chassis-datamapper'
403
+ ```
404
+
405
+ Running ```bundle install``` after adding an extension gem will make that it available to your app.
406
+
407
+ > Some gems will include a setup rake task to help get things started. Be sure to check out your newly available tasks for each extension with ```rake -T```.
408
+
409
+ ### Commonly Used Extensions
410
+
411
+ - **DataMapper** for working with databases: [chassis-datamapper](https://github.com/jarrodtaylor/chassis-datamapper)
412
+ - **Pony** for sending emails: [chassis-pony](https://github.com/jarrodtaylor/chassis-pony)
413
+
414
+ ### Writing Your Own
415
+
416
+ If you're familiar with writing RubyGems, you can create your own extensions:
417
+
418
+ ```bash
419
+ chassis -e my_extension
420
+ ```
421
+
422
+ The generated extension includes placeholders to fill in your own code, tasks, and templates.
423
+
424
+ ## Release Notes
425
+
426
+ ##### v1.1.0 (June 17, 2013)
427
+
428
+ - Added support for extensions.
429
+ - Removed DataMapper and Pony (they're now extensions).
430
+ - Updated the Gemfile to use the RubyGems url string.
431
+ - Updated Sinatra version to 1.4.3.
432
+ - Required ./app.rb from Chassis instead of the app.
433
+ - Added an extension template generator.
434
+ - Added a ton of documentation to the readme.
435
+
436
+ ##### v1.0.5 (June 8, 2013)
437
+
438
+ - Added the option to generate "bare" CoffeeScript if Tilt::CoffeeScriptTemplate.default\_bare is set to true.
439
+
440
+ ##### v1.0.4 (June 7, 2013)
441
+
442
+ - Updated the truncate helper to round numbers when truncating.
443
+ - Updated the required gems to newer versions.
444
+ - Cleaned up the default readme, no longer requiring Kramdown.
445
+ - Added asset minifying.
446
+
447
+
448
+ ##### v1.0.3 (May 7, 2013)
449
+
450
+ - Added /modules to the default load path.
451
+ - Fixed the truncate helper to work with the numberic? helper.
452
+
453
+ ##### v1.0.2 (April 6, 2013)
454
+
455
+ - Moved require_directory below session setup in app.rb.
456
+ - Deprecated settings.load_path in favor of a default Array of directories.
457
+ - Disabled settings.mobile\_views by default.
458
+ - Fixed mobile view routing.
459
+
460
+ ##### v1.0.1 (March 25, 2013)
461
+
462
+ - Updated the gem license ownership.
463
+ - Replaced the :rubygems symbol in the Gemfile with the string 'https://rubygems.org'.
464
+ - Locked in Sinatra v.1.3.4 (until sinatra-contrib supports Sinatra v1.4).
465
+
466
+ ##### v1.0.0 (February 5, 2013)
467
+
468
+ - First!
469
+
470
+ ## License
12
471
 
13
472
  Copyright (C) 2013 Jarrod Taylor.
14
473
 
data/bin/chassis CHANGED
@@ -5,9 +5,10 @@ require 'sinatra/chassis/file_manager'
5
5
 
6
6
  # Sets the default switches
7
7
  switches = {
8
- git: false,
9
- heroku: false,
10
- bundler: true
8
+ extension: false,
9
+ git: false,
10
+ heroku: false,
11
+ bundler: true
11
12
  }
12
13
 
13
14
  # Internal: Parses command options and runs associated methods.
@@ -25,10 +26,12 @@ options = OptionParser.new do |opt|
25
26
 
26
27
  opt.on('--skip-bundle', 'Don\'t run bundle install') { switches[:bundler] = false }
27
28
 
29
+ opt.on('-e', '--extension', 'Create a Chassis extension') { switches[:extension] = true }
30
+
28
31
  opt.parse!
29
32
  end
30
33
 
31
- # If app name is given, create application.
34
+ # If app name is given, create application or extension.
32
35
  if ARGV[0]
33
36
  app = ARGV[0]
34
37
 
@@ -41,17 +44,33 @@ if ARGV[0]
41
44
  exit
42
45
  end
43
46
 
44
- copy_directory "#{TEMPLATES}/chassis", app
45
-
46
- if switches[:bundler]
47
- puts LABELS[:run] + 'bundle'
48
- system "cd #{app} && bundle install"
47
+ if switches[:extension]
48
+ copy_directory "#{TEMPLATES}/extension", app
49
+
50
+ File.delete "#{app}/chassis-extension.gemspec"
51
+ File.delete "#{app}/lib/chassis-extension.rb"
52
+ File.delete "#{app}/lib/chassis/tasks/chassis-extension.rake"
53
+
54
+ copy_template "#{TEMPLATES}/extension/chassis-extension.gemspec",
55
+ "#{app}/#{app}.gemspec",
56
+ locals = { name: app }
57
+ copy_template "#{TEMPLATES}/extension/lib/chassis-extension.rb",
58
+ "#{app}/lib/#{app}.rb"
59
+ copy_template "#{TEMPLATES}/extension/lib/chassis/tasks/chassis-extension.rake",
60
+ "#{app}/lib/chassis/tasks/#{app}.rake"
61
+ else
62
+ copy_directory "#{TEMPLATES}/chassis", app
63
+
64
+ if switches[:bundler]
65
+ puts LABELS[:run] + 'bundle'
66
+ system "cd #{app} && bundle install"
67
+ end
49
68
  end
50
-
69
+
51
70
  puts LABELS[:run] + 'chmod -r 0755'
52
71
  FileUtils.chmod_R 0755, app
53
72
 
54
- if switches[:git]
73
+ if switches[:git] || switches[:extension]
55
74
  puts LABELS[:run] + 'git'
56
75
  system "cd #{app} && git init && git add . && git commit -m 'First!'"
57
76
  end
@@ -61,7 +80,7 @@ if ARGV[0]
61
80
  system "cd #{app} && heroku create && git push heroku master"
62
81
  end
63
82
 
64
- puts "\n Next steps:\n cd #{app}\n ruby app.rb\n\n"
83
+ puts "\n Next steps:\n cd #{app}\n ruby app.rb\n\n" unless switches[:extension]
65
84
  exit
66
85
  end
67
86
 
@@ -1,11 +1,21 @@
1
- # Require this script in app Rakefiles to import the Chassis file_manager,
2
- # the Chassis app rake tasks, and the tasks in the app /tasks directory.
1
+ # Require the application
2
+ require './app'
3
3
 
4
+ # Make the file manager library available to Rake tasks
4
5
  require "#{File.dirname(__FILE__)}/file_manager"
5
6
 
7
+ # Fix for Rake v10+ not using the top level DSL
6
8
  class Sinatra::Application
7
9
  extend Rake::DSL if defined? Rake::DSL
8
10
  end
9
11
 
12
+ # Import the Chassis tasks
10
13
  Dir[File.join(File.dirname(__FILE__) + "/../tasks/**/*.rake")].each { |file| import file }
14
+
15
+ # Import Chassis extension gem tasks
16
+ Gem.loaded_specs.values.each do |v|
17
+ Dir["#{v.full_gem_path}/lib/chassis/tasks/**/*.rake"].each { |file| import file }
18
+ end
19
+
20
+ # Import tasks from the app
11
21
  Dir["./tasks/**/*.rake"].each { |file| import file }
@@ -7,17 +7,13 @@ namespace :chassis do
7
7
  IRB.start
8
8
  end
9
9
 
10
- namespace :run do
11
-
12
- desc 'Run one or all /tests scripts'
13
- task :test, :file do |t, args|
14
- if args.file == nil
15
- Dir["./tests/**/*.rb"].each { |file| require file }
16
- else
17
- require "./tests/#{args.file}"
18
- end
10
+ desc 'Run one or all /tests scripts'
11
+ task :test, :file do |t, args|
12
+ if args.file == nil
13
+ Dir["./tests/**/*.rb"].each { |file| require file }
14
+ else
15
+ require "./tests/#{args.file}"
19
16
  end
20
-
21
17
  end
22
-
18
+
23
19
  end
@@ -3,6 +3,9 @@ source 'https://rubygems.org'
3
3
  gem 'coffee-script', '>= 2.2.0'
4
4
  gem 'jsmin', '>= 1.0.1'
5
5
  gem 'sass', '>= 3.2.9'
6
- gem 'sinatra', '>= 1.4.2'
7
- gem 'sinatra-chassis', '>= 1.0.5', require: 'sinatra/chassis'
6
+ gem 'sinatra', '>= 1.4.3'
7
+ gem 'sinatra-chassis', '>= 1.1.0', require: 'sinatra/chassis'
8
8
  gem 'sinatra-contrib', '>= 1.4.0', require: 'sinatra/contrib'
9
+
10
+ # gem 'chassis-datamapper'
11
+ # gem 'chassis-pony'
@@ -1,2 +1 @@
1
- require './app'
2
1
  require 'sinatra/chassis/tasks'
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1 @@
1
+ Instructions for using your extension go here...
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+
6
+ s.name = '<%= locals[:name] %>'
7
+ s.version = '0.0.1'
8
+ s.author = ''
9
+ s.email = ''
10
+ s.homepage = ''
11
+ s.summary = ''
12
+ s.description = ''
13
+ s.license = ''
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.required_ruby_version = ">= 1.9.2"
20
+
21
+ s.add_dependency 'sinatra-chassis', '>= 1.1.0'
22
+
23
+ end
@@ -0,0 +1 @@
1
+ # Code here will be available to apps using your extension.
@@ -0,0 +1 @@
1
+ # Rake tasks in this directory will be available to apps using your extension.
@@ -0,0 +1 @@
1
+ # Templates like this one can be copied from your extension to the app.
@@ -4,12 +4,12 @@ $:.push File.expand_path('../lib', __FILE__)
4
4
  Gem::Specification.new do |s|
5
5
 
6
6
  s.name = 'sinatra-chassis'
7
- s.version = '1.0.5'
7
+ s.version = '1.1.0'
8
8
  s.author = 'Jarrod Taylor'
9
9
  s.email = 'jarrodtaylor@icloud.com'
10
10
  s.homepage = 'http://jarrodtaylor.github.io/sinatra-chassis'
11
11
  s.summary = 'Chassis is a mutable framework extension for Sinatra.'
12
- s.description = "Chassis is a mutable framework extension for Sinatra that's designed not just to help you write less code, but to help you focus on less code."
12
+ s.description = "Chassis is a mutable framework extension for Sinatra that's designed to help you focus on less code by writing less code."
13
13
  s.license = 'MIT'
14
14
 
15
15
  s.files = `git ls-files`.split("\n")
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency 'rack-flash3', '>= 1.0.3'
24
24
  s.add_dependency 'rack-test', '>= 0.6.2'
25
25
  s.add_dependency 'sass', '>= 3.2.9'
26
- s.add_dependency 'sinatra', '>= 1.4.2'
26
+ s.add_dependency 'sinatra', '>= 1.4.3'
27
27
 
28
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-chassis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
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-06-08 00:00:00.000000000 Z
12
+ date: 2013-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: coffee-script
@@ -98,7 +98,7 @@ dependencies:
98
98
  requirements:
99
99
  - - ! '>='
100
100
  - !ruby/object:Gem::Version
101
- version: 1.4.2
101
+ version: 1.4.3
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,9 +106,9 @@ dependencies:
106
106
  requirements:
107
107
  - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
- version: 1.4.2
109
+ version: 1.4.3
110
110
  description: Chassis is a mutable framework extension for Sinatra that's designed
111
- not just to help you write less code, but to help you focus on less code.
111
+ to help you focus on less code by writing less code.
112
112
  email: jarrodtaylor@icloud.com
113
113
  executables:
114
114
  - chassis
@@ -127,8 +127,6 @@ files:
127
127
  - lib/sinatra/chassis/tasks.rb
128
128
  - lib/sinatra/tasks/assets.rake
129
129
  - lib/sinatra/tasks/chassis.rake
130
- - lib/sinatra/tasks/datamapper.rake
131
- - lib/sinatra/tasks/pony.rake
132
130
  - lib/sinatra/tasks/sinatra.rake
133
131
  - lib/sinatra/templates/chassis/.gitignore
134
132
  - lib/sinatra/templates/chassis/Gemfile
@@ -140,12 +138,14 @@ files:
140
138
  - lib/sinatra/templates/chassis/public/robots.txt
141
139
  - lib/sinatra/templates/chassis/tmp/restart.txt
142
140
  - lib/sinatra/templates/chassis/views/layout.erb
143
- - lib/sinatra/templates/datamapper/data/migrations/datamapper_migration.rb
144
- - lib/sinatra/templates/datamapper/data/seeds/seed.rb
145
- - lib/sinatra/templates/datamapper/models/datamapper.rb
146
- - lib/sinatra/templates/datamapper/settings/datamapper.rb
147
- - lib/sinatra/templates/datamapper/tests/models/datamapper_tests.rb
148
- - lib/sinatra/templates/pony/settings/pony.rb
141
+ - lib/sinatra/templates/extension/.gitignore
142
+ - lib/sinatra/templates/extension/Gemfile
143
+ - lib/sinatra/templates/extension/README.md
144
+ - lib/sinatra/templates/extension/Rakefile
145
+ - lib/sinatra/templates/extension/chassis-extension.gemspec
146
+ - lib/sinatra/templates/extension/lib/chassis-extension.rb
147
+ - lib/sinatra/templates/extension/lib/chassis/tasks/chassis-extension.rake
148
+ - lib/sinatra/templates/extension/lib/chassis/templates/template.rb
149
149
  - lib/sinatra/templates/sinatra/routes/routes.rb
150
150
  - lib/sinatra/templates/sinatra/tests/routes/routes_tests.rb
151
151
  - lib/sinatra/views/error.erb
@@ -1,117 +0,0 @@
1
- namespace :setup do
2
-
3
- desc 'Set up DataMapper'
4
- task :datamapper do
5
- create_directory './settings'
6
- append_to_file './Gemfile', "\ngem 'data_mapper', '~> 1.2.0'"
7
- append_to_file './Gemfile', "\ngem 'dm-sqlite-adapter', '~> 1.2.0'"
8
- append_to_file './Gemfile', "\n# gem 'dm-mysql-adapter', '~> 1.2.0'"
9
- append_to_file './Gemfile', "\n# gem 'dm-postgres-adapter', '~> 1.2.0'\n"
10
- append_to_file './app.rb', "\nDataMapper.finalize\n"
11
- copy_file "#{TEMPLATES}/datamapper/settings/datamapper.rb",
12
- "./settings/datamapper.rb"
13
- end
14
-
15
- end
16
-
17
- namespace :dm do
18
-
19
- def create_dm_path
20
- if DataMapper.repository.adapter.options[:path].include? 'sqlite'
21
- db = DataMapper.repository.adapter.options[:path].split('/').last
22
- create_directory DataMapper.repository.adapter.options[:path].gsub(db, '')
23
- end
24
- end
25
-
26
- namespace :add do
27
-
28
- desc 'Add a data migration' if defined? DataMapper
29
- task :migration, :name do |t, args|
30
- if args.name == nil
31
- puts 'You must define a migration name.'
32
- puts 'Example: rake add:migration[my_migration]'
33
- exit
34
- end
35
- create_directory './data', './data/migrations'
36
- t = Time.now.strftime("%Y%m%d%H%M%S")
37
- copy_template "#{TEMPLATES}/datamapper/data/migrations/datamapper_migration.rb",
38
- "./data/migrations/#{t}_#{args.name}.rb",
39
- { t: t, migration: args.name }
40
- end
41
-
42
- desc 'Add a model' if defined? DataMapper
43
- task :model, :name do |t, args|
44
- if args.name == nil
45
- puts 'You must define a model name.'
46
- puts 'Example: rake add:model[my_model]'
47
- exit
48
- end
49
- create_directory './models', './tests', './tests/models'
50
- copy_template "#{TEMPLATES}/datamapper/models/datamapper.rb",
51
- "./models/#{args.name}.rb",
52
- { model: args.name }
53
- copy_template "#{TEMPLATES}/datamapper/tests/models/datamapper_tests.rb",
54
- "./tests/models/#{args.name}_tests.rb",
55
- { model: args.name }
56
- end
57
-
58
- desc 'Add a seed data script' if defined? DataMapper
59
- task :seed, :name do |t, args|
60
- if args.name == nil
61
- puts 'You must define a seed file name.'
62
- puts 'Example: rake add:seed[my_seed_script]'
63
- exit
64
- end
65
- create_directory './data', './data/seeds'
66
- copy_template "#{TEMPLATES}/datamapper/data/seeds/seed.rb",
67
- "./data/seeds/#{args.name}.rb"
68
- end
69
-
70
- end
71
-
72
- desc 'Auto upgrade one or all models' if defined? DataMapper
73
- task :upgrade, :model do |t, args|
74
- create_dm_path
75
- args.model == nil ? DataMapper.auto_upgrade! : args.model.constantize.auto_upgrade!
76
- end
77
-
78
- desc 'Auto migrate one or all models' if defined? DataMapper
79
- task :migrate, :model do |t, args|
80
- create_dm_path
81
- args.model == nil ? DataMapper.auto_migrate! : args.model.constantize.auto_migrate!
82
- end
83
-
84
- namespace :migrate do
85
-
86
- desc 'Migrate up to a specific migration number' if defined? DataMapper
87
- task :up, :number do |t, args|
88
- create_dm_path
89
- require 'dm-migrations/migration_runner'
90
- Dir['./data/migrations/*.rb'].each { |m| require m }
91
- args.number == nil ? migrate_up! : migrate_up!(args.number)
92
- end
93
-
94
- desc 'Migrate down to a specific migration number' if defined? DataMapper
95
- task :down, :number do |t, args|
96
- create_dm_path
97
- require 'dm-migrations/migration_runner'
98
- Dir['./data/migrations/*.rb'].each { |m| require m }
99
- args.number == nil ? migrate_down! : migrate_down!(args.number)
100
- end
101
-
102
- end
103
-
104
- namespace :run do
105
-
106
- desc 'Run one or all /data/seeds scripts' if defined? DataMapper
107
- task :seed, :file do |t, args|
108
- if args.file == nil
109
- Dir["./data/seeds/**/*.rb"].each { |file| require file }
110
- else
111
- require "./data/seeds/#{args.file}"
112
- end
113
- end
114
-
115
- end
116
-
117
- end
@@ -1,11 +0,0 @@
1
- namespace :setup do
2
-
3
- desc 'Set up Pony'
4
- task :pony do
5
- create_directory './settings'
6
- append_to_file './Gemfile', "\ngem 'pony', '~> 1.4'\n"
7
- copy_file "#{TEMPLATES}/pony/settings/pony.rb",
8
- "./settings/pony.rb"
9
- end
10
-
11
- end
@@ -1,13 +0,0 @@
1
- migration <%= locals[:t] %>, :<%= locals[:migration] %> do
2
-
3
- up do
4
- # create_table :widgets do
5
- # column :id, Integer, serial: true
6
- # end
7
- end
8
-
9
- down do
10
- # drop_table :widgets
11
- end
12
-
13
- end
@@ -1 +0,0 @@
1
- # User.first_or_create(email: 'johndoe@example.com')
@@ -1,8 +0,0 @@
1
- class <%= locals[:model].capitalize %>
2
- include DataMapper::Resource
3
-
4
- timestamps :at, :on
5
- property :deleted_at, ParanoidDateTime
6
- property :id, Serial
7
-
8
- end
@@ -1,16 +0,0 @@
1
- configure :development do
2
- DataMapper::Logger.new $stdout, :debug
3
- # DataMapper.setup :default, 'sqlite::memory:'
4
- DataMapper.setup :default, "sqlite://#{Dir.pwd}/data/development.sqlite3"
5
- # DataMapper.setup :default, 'mysql://username:password@host_url:3306/database_name'
6
- # DataMapper.setup :default, 'postgres://username:password@host_url:5432/database_name'
7
- end
8
-
9
- configure :production do
10
- # DataMapper::Logger.new $stdout, :debug
11
- # DataMapper.setup :default, 'sqlite::memory:'
12
- # DataMapper.setup :default, "sqlite://#{Dir.pwd}/data/production.sqlite3"
13
- # DataMapper.setup :default, 'mysql://username:password@host_url:3306/database_name'
14
- # DataMapper.setup :default, 'postgres://username:password@host_url:5432/database_name'
15
- # DataMapper.setup(:default, ENV['DATABASE_URL'] || 'postgres://localhost/mydb')
16
- end
@@ -1,16 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'rack/test'
3
- require './app'
4
-
5
- class <%= locals[:model].capitalize %>Tests < MiniTest::Unit::TestCase
6
- include Rack::Test::Methods
7
-
8
- def app
9
- Sinatra::Application
10
- end
11
-
12
- # def test_made_by
13
- # <%= locals[:model] %> = <%= locals[:model].capitalize %>.new
14
- # assert_equal <%= locals[:model] %>.made_by, 'Acme Corp.'
15
- # end
16
- end
@@ -1,27 +0,0 @@
1
- Pony.options = {
2
- via: :smtp,
3
- via_options: {
4
- address: '',
5
- port: '',
6
- domain: '',
7
- user_name: '',
8
- password: '',
9
- authentication: :plain,
10
- enable_starttls_auto: true
11
- }
12
- }
13
-
14
- # Heroku example:
15
-
16
- # Pony.options = {
17
- # via: :smtp,
18
- # via_options: {
19
- # address: 'smtp.sendgrid.net',
20
- # port: '587',
21
- # domain: 'heroku.com',
22
- # user_name: ENV['SENDGRID_USERNAME'],
23
- # password: ENV['SENDGRID_PASSWORD'],
24
- # authentication: :plain,
25
- # enable_starttls_auto: true
26
- # }
27
- # }