kelredd-sinatra-helpers 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,12 +4,20 @@
4
4
 
5
5
  This is a ruby gem with a bunch of helpers to make Sinatra more useful.
6
6
 
7
+ == Installation
8
+
9
+ gem install kelredd-sinatra-helpers
10
+
11
+ == Usage
12
+
13
+ require 'sinatra_helpers'
14
+
7
15
  === A Generator
8
16
 
9
17
  I've written a generator for new Sinatra apps. Please note: I've written this generator suited for my needs and paradigms in writing Sinatra apps. It is written for me and comes AS IS. Use if you wish, but know that it conforms to what I like using in Sinatra apps, including:
10
18
 
11
19
  * Most, if not all, of the helpers in this gem
12
- * Gem configuration (via gemsconfig: http://github.com/kelredd/gemsconfig)
20
+ * Bundler for gem configurations
13
21
  * Capistrano deployment scheme
14
22
  * Source control with Git
15
23
  * Erb (with generators from useful: http://github.com/kelredd/useful/tree/master/lib/useful/erb_helpers/)
@@ -20,7 +28,8 @@ I've written a generator for new Sinatra apps. Please note: I've written this g
20
28
  * Rack::Less (http://github.com/kelredd/rack-less)
21
29
  * Rack::Sprockets (http://github.com/kelredd/rack-sprockets)
22
30
  * Unit testing with Test::Unit
23
-
31
+ * Test suite using leftright, rack-test, webrat, etc...
32
+
24
33
  If you don't like/want to use something that this generates, don't use the generator, or back out some generated code manually. Ok, enough about that. On to usage:
25
34
 
26
35
  $ sinatra path/to/app
@@ -37,15 +46,21 @@ http://github.com/kelredd/useful/tree/master/lib/useful/erb_helpers/ for more in
37
46
 
38
47
  === ActiveRecord
39
48
 
40
- Coming.
49
+ Provides a Rails like way for configuring an activerecord database. Here's the steps to set it up:
41
50
 
42
- == Installation
51
+ 1. Configure this gem in your bundle
43
52
 
44
- gem install kelredd-sinatra-helpers
53
+ gem 'kelredd-sinatra-helpers', :require => "sinatra_helpers"
45
54
 
46
- == Usage
55
+ 2. Configure active record in your bundle
47
56
 
48
- require 'sinatra_helpers'
57
+ gem 'activerecord'
58
+
59
+ 3. Create your db config yaml file at 'config/database.yml'
60
+
61
+ 4. Somewhere in your app initialization script, do
62
+
63
+ require 'sinatra_helpers/active_record'
49
64
 
50
65
  == License
51
66
 
@@ -0,0 +1,21 @@
1
+ require 'sinatra/base'
2
+ require 'active_record'
3
+
4
+ module SinatraHelpers; end
5
+ module SinatraHelpers::ActiveRecord
6
+
7
+ class << self
8
+
9
+ def registered(app)
10
+ db_config_file = File.join(Sinatra::Application.root,'config',"database.yml")
11
+ db_config = YAML.load(ERB.new(IO.read(db_config_file)).result)
12
+ db = (db_config[Sinatra::Application.environment.to_s]).symbolize_keys
13
+ ::ActiveRecord::Base.establish_connection(db)
14
+ ::ActiveRecord::Base.logger = Logger.new(STDOUT)
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+
21
+ Sinatra::Application.register SinatraHelpers::ActiveRecord
@@ -0,0 +1,18 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'sinatra'
4
+
5
+ gem 'rack-flash'
6
+ gem 'rack-cache', :require => "rack/cache"
7
+ gem 'rack-less', :require => "rack/less"
8
+ gem 'rack-sprockets', :require => "rack/sprockets"
9
+
10
+ gem 'kelredd-useful', :require => "useful/ruby_extensions"
11
+ gem 'kelredd-sinatra-helpers', :require => "sinatra_helpers"
12
+
13
+ group :test do
14
+ gem 'rack-test', "~>0.5", :require => "rack/test"
15
+ gem 'shoulda', "~>2.11"
16
+ gem 'leftright'
17
+ gem 'webrat', "~>0.7"
18
+ end
@@ -1,5 +1,10 @@
1
1
  require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+
2
5
  require 'sinatra'
6
+ Bundler.require(:default)
7
+
3
8
  require 'app/base'
4
9
 
5
10
  # define routes here or load in route definitions
@@ -1,10 +1,10 @@
1
1
  RACK_ENV = ENV["RACK_ENV"] ||= "development"
2
2
  ROOT_DIR = File.expand_path("#{File.dirname(__FILE__)}/..") unless defined? ROOT_DIR
3
-
3
+
4
4
  def root_path(*args)
5
5
  File.join(ROOT_DIR, *args)
6
6
  end
7
-
7
+
8
8
  def public_path(*args)
9
9
  root_path('public', *args)
10
10
  end
@@ -30,7 +30,7 @@ def load_lib(files_dir=[])
30
30
  end
31
31
 
32
32
  def load_libs
33
- load_lib
33
+ load_lib
34
34
  end
35
35
 
36
36
  require 'config/env'
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ENV['RACK_ENV'] ||= (ARGV.first || 'development')
3
+ RACK_ENV = ENV['RACK_ENV'] = (ARGV.first || 'development')
4
4
  platform_irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
5
5
 
6
6
  require 'rubygems'
7
- require 'sinatra/base'
8
7
  libs = " -r app"
9
8
 
10
- puts "Loading default environment (Sinatra #{Sinatra::VERSION})"
11
- exec "#{platform_irb} #{libs} --simple-prompt"
9
+ puts "Loading #{RACK_ENV} environment (Sinatra)"
10
+ exec "#{platform_irb} #{libs} --simple-prompt"
@@ -1,7 +1,9 @@
1
1
  require 'capistrano/ext/multistage'
2
2
  require 'useful/cap_tasks'
3
+ require 'bundler/capistrano'
3
4
 
4
5
  set :stages, %w(live staging)
6
+ set :application, "<%= @name %>"
5
7
 
6
8
  require 'useful/cap_tasks/git_query_revision_remote'
7
9
  require 'useful/cap_tasks/passenger_deploy'
@@ -9,7 +11,7 @@ require 'useful/cap_tasks/disable_with_down_html'
9
11
  require 'useful/cap_tasks/rack_cache'
10
12
 
11
13
  namespace :deploy do
12
-
14
+
13
15
  after 'deploy:update_code', 'deploy:setup_stage_environment'
14
16
 
15
17
  desc "_: (#{application}) Setup production environment (files, symlinks, etc...)."
@@ -17,5 +19,5 @@ namespace :deploy do
17
19
  config = "#{release_path}/admin/#{rack_env}.ru"
18
20
  run "cp #{config} #{release_path}/config.ru"
19
21
  end
20
-
22
+
21
23
  end
@@ -1,8 +1,5 @@
1
1
  require 'logger'
2
2
  LOGGER = Logger.new(root_path('log', "#{RACK_ENV}.log"))
3
-
4
- require 'config/gems'
5
- Gemsconfig::load if defined?(Gemsconfig)
6
3
 
7
4
  # basic app configurations
8
5
  set :root, root_path
@@ -10,43 +7,4 @@ set :views, root_path("app", "views")
10
7
  set :images_path, public_path("images")
11
8
  set :environment, RACK_ENV.to_sym if defined?(RACK_ENV)
12
9
 
13
- # Load environment
14
- begin
15
- require "config/envs/#{RACK_ENV.downcase}"
16
- rescue LoadError => err
17
- puts "no environment config set up for '#{RACK_ENV.downcase}', ignoring..."
18
- end
19
-
20
- # load app files
21
- load_app 'helpers'
22
- load_app 'models'
23
-
24
- # Load initializers
25
- Dir[root_path('config', 'initializers', '*.rb')].each do |file|
26
- require file
27
- end
28
-
29
- # load middlewares
30
- # TODO: set your session cookie name here
31
- use Rack::Session::Cookie, :key => '_sess'
32
- use Rack::Flash
33
-
34
- use Rack::Less
35
- Rack::Less.configure do |config|
36
- config.combinations = {
37
- 'web' => ['reset', 'app']
38
- }
39
- config.combination_timestamp = if !development?
40
- File.mtime(Sinatra::Application.root).to_i
41
- else
42
- true
43
- end
44
- if config.cache = !development?
45
- config.compress = :whitespace
46
- end
47
- end
48
-
49
- use Rack::Sprockets
50
- Rack::Sprockets.configure do |config|
51
- config.cache = production?
52
- end
10
+ require 'config/init'
@@ -5,4 +5,3 @@ task :environment do
5
5
  set :app_file, File.join(root_path, 'app.rb')
6
6
  disable :run
7
7
  end
8
-
@@ -0,0 +1,28 @@
1
+ # load app files
2
+ load_app 'helpers'
3
+ load_app 'models'
4
+
5
+ # load middlewares
6
+ # TODO: set your session cookie name here
7
+ use Rack::Session::Cookie, :key => '_sess'
8
+ use Rack::Flash
9
+
10
+ use Rack::Less
11
+ Rack::Less.configure do |config|
12
+ config.combinations = {
13
+ 'web' => ['reset', 'app']
14
+ }
15
+ if config.cache = production?
16
+ # only cache if in production
17
+ # compress by removing whitespace if in production
18
+ config.compress = :whitespace
19
+ else
20
+ # always cache_bust if not in production
21
+ config.cache_bust = true
22
+ end
23
+ end
24
+
25
+ use Rack::Sprockets
26
+ Rack::Sprockets.configure do |config|
27
+ config.cache = production?
28
+ end
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require 'test/helper'
2
2
 
3
3
  class LayoutTest < Test::Unit::TestCase
4
4
 
@@ -7,19 +7,19 @@ class LayoutTest < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  context "The app's layout" do
10
-
11
- before do
10
+
11
+ setup do
12
12
  visit '/'
13
13
  end
14
14
 
15
15
 
16
16
  # TODO: write better tests...
17
17
  # => this is just for show :)
18
-
18
+
19
19
  should "say hello" do
20
20
  assert_contain "Hello from <%= @class_name %>!"
21
21
  end
22
-
22
+
23
23
  end
24
24
 
25
25
  end
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require 'test/helper'
2
2
 
3
3
  class UnitTest < Test::Unit::TestCase
4
4
 
@@ -7,7 +7,7 @@ class UnitTest < Test::Unit::TestCase
7
7
  should "flunk" do
8
8
  flunk "This is just an example from a template. Please provide some tests"
9
9
  end
10
-
10
+
11
11
  end
12
12
 
13
13
  end
@@ -1,10 +1,3 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda/test_unit'
4
- require 'useful/shoulda_macros/test_unit'
5
- require 'rack/test'
6
- require 'webrat'
7
-
8
1
  ENV["RACK_ENV"] = "test"
9
2
  ROOT_DIR = File.expand_path("#{File.dirname(__FILE__)}/..")
10
3
 
@@ -13,13 +6,17 @@ $LOAD_PATH.unshift(File.join(ROOT_DIR, 'test'))
13
6
 
14
7
  require 'app'
15
8
 
9
+ require 'test/unit'
10
+ require 'useful/shoulda_macros/test_unit'
11
+ Bundler.require(:test)
12
+
16
13
  class Test::Unit::TestCase
17
14
  include Rack::Test::Methods
18
15
  include Webrat::Methods
19
16
  include Webrat::Matchers
20
-
17
+
21
18
  Webrat.configure do |config|
22
19
  config.mode = :rack
23
20
  end
24
-
21
+
25
22
  end
@@ -8,12 +8,12 @@ module SinatraHelpers::Generator
8
8
  'Capfile.erb' => 'Capfile',
9
9
  'Rakefile.erb' => 'Rakefile',
10
10
  'gitignore.erb' => '.gitignore',
11
-
11
+
12
12
  :admin => {
13
13
  'production.ru.erb' => 'production.ru',
14
14
  'staging.ru.erb' => 'staging.ru'
15
15
  },
16
-
16
+
17
17
  :app => {
18
18
  'base.rb.erb' => 'base.rb',
19
19
  :helpers => {},
@@ -31,7 +31,7 @@ module SinatraHelpers::Generator
31
31
  'app.less.erb' => 'app.less'
32
32
  }
33
33
  },
34
-
34
+
35
35
  :config => {
36
36
  'deploy.rb.erb' => 'deploy.rb',
37
37
  :deploy => {
@@ -39,36 +39,29 @@ module SinatraHelpers::Generator
39
39
  'deploy_staging.rb.erb' => 'staging.rb'
40
40
  },
41
41
  'env.rb.erb' => 'env.rb',
42
- :envs => {
43
- 'env_development.rb.erb' => 'development.rb',
44
- 'env_production.rb.erb' => 'production.rb',
45
- 'env_staging.rb.erb' => 'staging.rb',
46
- 'env_test.rb.erb' => 'test.rb'
47
- },
48
- 'gems.rb.erb' => 'gems.rb',
49
- :initializers => {
50
- 'init.rb.erb' => 'init.rb'
51
- }
42
+ 'init.rb.erb' => 'init.rb'
52
43
  },
53
-
44
+
45
+ 'Gemfile.erb' => 'Gemfile',
46
+
54
47
  :lib => {
55
48
  :tasks => {
56
49
  'environment.rake.erb' => 'environment.rake'
57
50
  }
58
51
  },
59
-
52
+
60
53
  :log => {},
61
-
54
+
62
55
  :public => {
63
56
  :images => {},
64
57
  },
65
-
58
+
66
59
  :script => {
67
60
  'console.erb' => 'console'
68
61
  },
69
-
62
+
70
63
  :test => {
71
- 'test_helper.rb.erb' => 'test_helper.rb',
64
+ 'test_helper.rb.erb' => 'helper.rb',
72
65
  :functional => {
73
66
  'layout_test.rb.erb' => 'layout_test.rb'
74
67
  },
@@ -76,7 +69,7 @@ module SinatraHelpers::Generator
76
69
  'model_test.rb.erb' => 'model_test.rb'
77
70
  }
78
71
  }
79
-
72
+
80
73
  }
81
74
 
82
75
  end
@@ -1,13 +1,13 @@
1
1
  module SinatraHelpers
2
2
  module Version
3
-
3
+
4
4
  MAJOR = 0
5
- MINOR = 2
6
- TINY = 8
7
-
5
+ MINOR = 3
6
+ TINY = 0
7
+
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
10
10
  end
11
-
11
+
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelredd-sinatra-helpers
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 8
10
- version: 0.2.8
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-20 00:00:00 -05:00
18
+ date: 2010-09-16 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -126,6 +126,7 @@ files:
126
126
  - README.rdoc
127
127
  - Rakefile
128
128
  - bin/sinatra
129
+ - lib/sinatra_helpers/active_record.rb
129
130
  - lib/sinatra_helpers/cache.rb
130
131
  - lib/sinatra_helpers/environment_tests.rb
131
132
  - lib/sinatra_helpers/erb/analytics.rb
@@ -147,11 +148,8 @@ files:
147
148
  - lib/sinatra_helpers/generator/file_templates/deploy_production.rb.erb
148
149
  - lib/sinatra_helpers/generator/file_templates/deploy_staging.rb.erb
149
150
  - lib/sinatra_helpers/generator/file_templates/env.rb.erb
150
- - lib/sinatra_helpers/generator/file_templates/env_development.rb.erb
151
- - lib/sinatra_helpers/generator/file_templates/env_production.rb.erb
152
- - lib/sinatra_helpers/generator/file_templates/env_staging.rb.erb
153
- - lib/sinatra_helpers/generator/file_templates/env_test.rb.erb
154
151
  - lib/sinatra_helpers/generator/file_templates/environment.rake.erb
152
+ - lib/sinatra_helpers/generator/file_templates/Gemfile.erb
155
153
  - lib/sinatra_helpers/generator/file_templates/gems.rb.erb
156
154
  - lib/sinatra_helpers/generator/file_templates/gitignore.erb
157
155
  - lib/sinatra_helpers/generator/file_templates/index.html.erb.erb