darkhelmet-sinatra_more 0.3.33
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +23 -0
- data/IDEAS.md +54 -0
- data/LICENSE +20 -0
- data/README.rdoc +756 -0
- data/ROADMAP +88 -0
- data/Rakefile +63 -0
- data/TODO +60 -0
- data/VERSION +1 -0
- data/bin/sinatra_gen +6 -0
- data/generators/base_app/.gitignore +7 -0
- data/generators/base_app/Gemfile +13 -0
- data/generators/base_app/app/.empty_directory +0 -0
- data/generators/base_app/app/helpers/.empty_directory +0 -0
- data/generators/base_app/app/helpers/view_helpers.rb +3 -0
- data/generators/base_app/app/mailers/.empty_directory +0 -0
- data/generators/base_app/app/models/.empty_directory +0 -0
- data/generators/base_app/app/routes/.empty_directory +0 -0
- data/generators/base_app/app/views/.empty_directory +0 -0
- data/generators/base_app/config.ru.tt +10 -0
- data/generators/base_app/config/boot.rb.tt +42 -0
- data/generators/base_app/config/dependencies.rb.tt +41 -0
- data/generators/base_app/lib/.empty_directory +0 -0
- data/generators/base_app/public/images/.empty_directory +0 -0
- data/generators/base_app/public/images/.gitignore +0 -0
- data/generators/base_app/public/javascripts/.empty_directory +0 -0
- data/generators/base_app/public/stylesheets/.empty_directory +0 -0
- data/generators/base_app/test/models/.empty_directory +0 -0
- data/generators/base_app/test/routes/.empty_directory +0 -0
- data/generators/base_app/test/test_config.rb.tt +5 -0
- data/generators/base_app/vendor/gems/.empty_directory +0 -0
- data/generators/components/component_actions.rb +48 -0
- data/generators/components/mocks/mocha_mock_gen.rb +8 -0
- data/generators/components/mocks/rr_mock_gen.rb +8 -0
- data/generators/components/orms/activerecord_orm_gen.rb +99 -0
- data/generators/components/orms/couchrest_orm_gen.rb +64 -0
- data/generators/components/orms/datamapper_orm_gen.rb +52 -0
- data/generators/components/orms/mongomapper_orm_gen.rb +101 -0
- data/generators/components/orms/sequel_orm_gen.rb +61 -0
- data/generators/components/renderers/erb_renderer_gen.rb +7 -0
- data/generators/components/renderers/haml_renderer_gen.rb +22 -0
- data/generators/components/scripts/jquery_script_gen.rb +9 -0
- data/generators/components/scripts/prototype_script_gen.rb +10 -0
- data/generators/components/scripts/rightjs_script_gen.rb +10 -0
- data/generators/components/tests/bacon_test_gen.rb +21 -0
- data/generators/components/tests/riot_test_gen.rb +19 -0
- data/generators/components/tests/rspec_test_gen.rb +19 -0
- data/generators/components/tests/shoulda_test_gen.rb +19 -0
- data/generators/components/tests/testspec_test_gen.rb +19 -0
- data/generators/generator_actions.rb +79 -0
- data/generators/skeleton_generator.rb +53 -0
- data/lib/sinatra/mailer_plugin.rb +14 -0
- data/lib/sinatra/mailer_plugin/mail_object.rb +39 -0
- data/lib/sinatra/mailer_plugin/mailer_base.rb +75 -0
- data/lib/sinatra/markup_plugin.rb +19 -0
- data/lib/sinatra/markup_plugin/asset_tag_helpers.rb +109 -0
- data/lib/sinatra/markup_plugin/form_builder/abstract_form_builder.rb +133 -0
- data/lib/sinatra/markup_plugin/form_builder/standard_form_builder.rb +31 -0
- data/lib/sinatra/markup_plugin/form_helpers.rb +194 -0
- data/lib/sinatra/markup_plugin/format_helpers.rb +74 -0
- data/lib/sinatra/markup_plugin/output_helpers.rb +98 -0
- data/lib/sinatra/markup_plugin/tag_helpers.rb +42 -0
- data/lib/sinatra/render_plugin.rb +12 -0
- data/lib/sinatra/render_plugin/render_helpers.rb +63 -0
- data/lib/sinatra/routing_plugin.rb +50 -0
- data/lib/sinatra/routing_plugin/named_route.rb +27 -0
- data/lib/sinatra/routing_plugin/routing_helpers.rb +22 -0
- data/lib/sinatra/support_lite.rb +19 -0
- data/lib/sinatra/warden_plugin.rb +51 -0
- data/lib/sinatra/warden_plugin/warden_helpers.rb +60 -0
- data/lib/sinatra_more.rb +7 -0
- data/sinatra_more.gemspec +215 -0
- data/test/active_support_helpers.rb +7 -0
- data/test/fixtures/mailer_app/app.rb +51 -0
- data/test/fixtures/mailer_app/views/demo_mailer/sample_mail.erb +1 -0
- data/test/fixtures/mailer_app/views/sample_mailer/anniversary_message.erb +2 -0
- data/test/fixtures/mailer_app/views/sample_mailer/birthday_message.erb +2 -0
- data/test/fixtures/markup_app/app.rb +66 -0
- data/test/fixtures/markup_app/views/capture_concat.erb +14 -0
- data/test/fixtures/markup_app/views/capture_concat.haml +13 -0
- data/test/fixtures/markup_app/views/content_for.erb +11 -0
- data/test/fixtures/markup_app/views/content_for.haml +9 -0
- data/test/fixtures/markup_app/views/content_tag.erb +11 -0
- data/test/fixtures/markup_app/views/content_tag.haml +9 -0
- data/test/fixtures/markup_app/views/fields_for.erb +8 -0
- data/test/fixtures/markup_app/views/fields_for.haml +6 -0
- data/test/fixtures/markup_app/views/form_for.erb +56 -0
- data/test/fixtures/markup_app/views/form_for.haml +47 -0
- data/test/fixtures/markup_app/views/form_tag.erb +57 -0
- data/test/fixtures/markup_app/views/form_tag.haml +45 -0
- data/test/fixtures/markup_app/views/link_to.erb +5 -0
- data/test/fixtures/markup_app/views/link_to.haml +4 -0
- data/test/fixtures/markup_app/views/mail_to.erb +3 -0
- data/test/fixtures/markup_app/views/mail_to.haml +3 -0
- data/test/fixtures/markup_app/views/meta_tag.erb +3 -0
- data/test/fixtures/markup_app/views/meta_tag.haml +3 -0
- data/test/fixtures/render_app/app.rb +54 -0
- data/test/fixtures/render_app/views/erb/test.erb +1 -0
- data/test/fixtures/render_app/views/haml/test.haml +1 -0
- data/test/fixtures/render_app/views/template/_user.haml +7 -0
- data/test/fixtures/render_app/views/template/haml_template.haml +1 -0
- data/test/fixtures/render_app/views/template/some_template.haml +2 -0
- data/test/fixtures/routing_app/app.rb +48 -0
- data/test/fixtures/routing_app/views/index.haml +7 -0
- data/test/fixtures/warden_app/app.rb +75 -0
- data/test/fixtures/warden_app/views/dashboard.haml +6 -0
- data/test/generators/test_skeleton_generator.rb +190 -0
- data/test/helper.rb +73 -0
- data/test/mailer_plugin/test_mail_object.rb +24 -0
- data/test/mailer_plugin/test_mailer_base.rb +81 -0
- data/test/markup_plugin/test_asset_tag_helpers.rb +171 -0
- data/test/markup_plugin/test_form_builder.rb +627 -0
- data/test/markup_plugin/test_form_helpers.rb +417 -0
- data/test/markup_plugin/test_format_helpers.rb +96 -0
- data/test/markup_plugin/test_output_helpers.rb +63 -0
- data/test/markup_plugin/test_tag_helpers.rb +73 -0
- data/test/test_mailer_plugin.rb +33 -0
- data/test/test_render_plugin.rb +78 -0
- data/test/test_routing_plugin.rb +94 -0
- data/test/test_warden_plugin.rb +105 -0
- metadata +307 -0
data/ROADMAP
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
Working with lipsiadmin:
|
2
|
+
|
3
|
+
1) Proof of concept for the Sinatra Framework
|
4
|
+
2) Adding in additional features to the current sinatra_more (more generators, helpers, etc)
|
5
|
+
3) Split plugin up into individual gems for better organization
|
6
|
+
4) Porting of lipsiadmin over to sinatra
|
7
|
+
5) First produciton application
|
8
|
+
6) Build Sinatra Framework Website
|
9
|
+
|
10
|
+
Use Bundler for managing dependencies:
|
11
|
+
* http://github.com/wycats/bundler
|
12
|
+
* http://www.engineyard.com/blog/2009/using-the-rubygems-bundler-for-your-app/
|
13
|
+
|
14
|
+
Framework structure:
|
15
|
+
|
16
|
+
* sinatra-core (the existing sinatra framework) <= from Sinatra
|
17
|
+
* sinatra-gen (easy generation of and for sinatra apps) <= from Generator
|
18
|
+
* sinatra-helpers (adds the markup and renderer helpers) <= from MarkupPlugin, RenderPlugin
|
19
|
+
* sinatra-mailer (mail handling for sinatra applications) <= from MailerPlugin
|
20
|
+
* sinatra-routing (sinatra route mapping system) <= from RoutingPlugin
|
21
|
+
* sinatra-cache (page and fragment caching support)
|
22
|
+
* sinatra-admin (admin management dashboard for content) <= from Lipsiadmin (ported)
|
23
|
+
|
24
|
+
Additional wish-list features (integrate existing plugin) (?)
|
25
|
+
|
26
|
+
* Reloading Support - http://github.com/alexch/rerun
|
27
|
+
* Internationalization - http://r18n.rubyforge.org/#sinatra
|
28
|
+
* Asynchronous Commands - http://github.com/deadprogrammer/spork
|
29
|
+
* Capistrano Deployment - http://github.com/nakajima/capinatra (?)
|
30
|
+
* Job Queue - http://github.com/adamcooke/resque (or http://github.com/bmizerany/sinatra-dj)
|
31
|
+
|
32
|
+
'sinatra-cache' Caching concept:
|
33
|
+
|
34
|
+
# in models
|
35
|
+
class Person
|
36
|
+
def something_expensive
|
37
|
+
Sinatra::Cache.get('key')
|
38
|
+
Sinatra::Cache.set('key', value)
|
39
|
+
Sinatra::Cache.fetch('key') { 'value' }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# fragment in route
|
44
|
+
get '/cache2' do
|
45
|
+
cache 'cache2', :expiry => 10 do
|
46
|
+
'Hello Cache2'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# fragment in view
|
51
|
+
# /views/test.haml
|
52
|
+
- cache 'test', :expiry => 10 do
|
53
|
+
= partial 'item', :collection => @items
|
54
|
+
|
55
|
+
# page
|
56
|
+
get '/example', :cache => true do
|
57
|
+
haml_template 'accounts/index'
|
58
|
+
end
|
59
|
+
|
60
|
+
'sinatra-routing' Routing Concept:
|
61
|
+
|
62
|
+
namespace :admin do
|
63
|
+
get :show do
|
64
|
+
...
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
get :accounts do
|
69
|
+
...
|
70
|
+
end
|
71
|
+
|
72
|
+
map(:admin, :show).to("/my-admin/:id/show")
|
73
|
+
map(:accounts).to("/show-me-my/accounts")
|
74
|
+
|
75
|
+
# or
|
76
|
+
|
77
|
+
map :admin do |namespace|
|
78
|
+
namespace.map(:show).to("/my-admin/:id/show")
|
79
|
+
end
|
80
|
+
|
81
|
+
# and to use
|
82
|
+
link_to "Show Admin", url_for(:admin, :show, :id => 5)
|
83
|
+
link_to "Accounts", url_for(:accounts)
|
84
|
+
|
85
|
+
'commands' Concept: (console (?) http://github.com/sickill/racksh)
|
86
|
+
|
87
|
+
$ sinatra_more console # loads console for sinatra
|
88
|
+
$ sinatra_more test # runs all test using specified testing framework
|
data/Rakefile
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# $ rake version:bump:patch release
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |gem|
|
9
|
+
gem.name = "sinatra_more"
|
10
|
+
gem.summary = "Expands sinatra to allow for complex applications"
|
11
|
+
gem.description = "Expands sinatra with standard helpers and tools to allow for complex applications"
|
12
|
+
gem.email = "nesquena@gmail.com"
|
13
|
+
gem.homepage = "http://github.com/nesquena/sinatra_more"
|
14
|
+
gem.authors = ["Nathan Esquenazi"]
|
15
|
+
gem.add_runtime_dependency "sinatra", ">= 0.9.2"
|
16
|
+
gem.add_runtime_dependency "tilt", ">= 0.2"
|
17
|
+
gem.add_runtime_dependency "thor", ">= 0.11.8"
|
18
|
+
gem.add_runtime_dependency "activesupport", ">= 2.2.2"
|
19
|
+
gem.add_runtime_dependency "bundler"
|
20
|
+
gem.add_development_dependency "haml", ">= 2.2.14"
|
21
|
+
gem.add_development_dependency "shoulda", ">= 2.10.2"
|
22
|
+
gem.add_development_dependency "mocha", ">= 0.9.7"
|
23
|
+
gem.add_development_dependency "rack-test", ">= 0.5.0"
|
24
|
+
gem.add_development_dependency "webrat", ">= 0.5.1"
|
25
|
+
end
|
26
|
+
Jeweler::GemcutterTasks.new
|
27
|
+
rescue LoadError
|
28
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'rake/testtask'
|
32
|
+
Rake::TestTask.new(:test) do |test|
|
33
|
+
test.libs << 'lib' << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
|
38
|
+
begin
|
39
|
+
require 'rcov/rcovtask'
|
40
|
+
Rcov::RcovTask.new do |test|
|
41
|
+
test.libs << 'test'
|
42
|
+
test.pattern = 'test/**/test_*.rb'
|
43
|
+
test.verbose = true
|
44
|
+
end
|
45
|
+
rescue LoadError
|
46
|
+
task :rcov do
|
47
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
task :test => :check_dependencies
|
52
|
+
|
53
|
+
task :default => :test
|
54
|
+
|
55
|
+
require 'rake/rdoctask'
|
56
|
+
Rake::RDocTask.new do |rdoc|
|
57
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
58
|
+
|
59
|
+
rdoc.rdoc_dir = 'rdoc'
|
60
|
+
rdoc.title = "sinatra_more #{version}"
|
61
|
+
rdoc.rdoc_files.include('README*')
|
62
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
63
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
= RESOURCES
|
2
|
+
|
3
|
+
- Check out the following sinatra extensions:
|
4
|
+
* http://github.com/wbzyl/sinatra-static-assets
|
5
|
+
* http://github.com/giraffesoft/classy_resources
|
6
|
+
* http://github.com/nakajima/capinatra
|
7
|
+
* http://github.com/deadprogrammer/spork
|
8
|
+
* http://github.com/gioext/sinatra-memcache
|
9
|
+
* http://github.com/kematzy/sinatra-cache
|
10
|
+
* http://r18n.rubyforge.org/#sinatra
|
11
|
+
* http://github.com/alexch/rerun (reloading)
|
12
|
+
* http://github.com/monkrb/glue/blob/master/lib/monk/glue/reloader.rb
|
13
|
+
|
14
|
+
= UNFINISHED
|
15
|
+
|
16
|
+
== Generator
|
17
|
+
|
18
|
+
* Add support for model, routes, migration generator types based on components
|
19
|
+
|
20
|
+
== MarkupPlugin
|
21
|
+
|
22
|
+
* Add support for mustache classes / views for forms, markup
|
23
|
+
* Add support for form.fields_for (one-to-one, nested and many associations like in rails)
|
24
|
+
* Add support for check_box_group, radio_button_group which create a set of checkboxes or radio buttons
|
25
|
+
|
26
|
+
== RenderPlugin
|
27
|
+
|
28
|
+
* Add support for mustache template rendering
|
29
|
+
|
30
|
+
== WardenPlugin
|
31
|
+
|
32
|
+
* Become total warden solution (basically just require warden gem installed, do everything) (?)
|
33
|
+
* Look into removing overlapping methods and simply leveraging sinatra_warden
|
34
|
+
* Take advantage of shared strategies: http://github.com/hassox/warden_strategies/tree/master/lib/
|
35
|
+
|
36
|
+
== RoutingPlugin
|
37
|
+
|
38
|
+
= COMPLETED
|
39
|
+
|
40
|
+
* Add support for multiple applications being mounted into routing system
|
41
|
+
* Add support for RoutingPlugin for easy to use named alias routes for urls
|
42
|
+
* Add support for bundler (http://github.com/wycats/bundler) to make setting up a generated app easy
|
43
|
+
* Add support for button tag method, mail_to helper
|
44
|
+
* Add support for simple fields_for tag helper
|
45
|
+
* Add content_for / yield tags similar to rails
|
46
|
+
* Created application generator using thor
|
47
|
+
* Add support for a MailerPlugin which will make sending emails a breeze (http://github.com/hiroshi/pony)
|
48
|
+
* Add support for missing formbuilder fields (select, and standard_form_builder methods i.e check_box_group)
|
49
|
+
* Add support for missing formhelpers/fields (radio_button_tag, select_tag)
|
50
|
+
* Add support for select_tag :multiple => true
|
51
|
+
* Add support for forms with method => put, delete using hidden field
|
52
|
+
* Remove dependency on activesupport! and enumerate dependencies in rakefile (as much as possible, need inflectors)
|
53
|
+
* Pull from sinatra-helpers and make erb templates work (and credit keldredd)
|
54
|
+
* http://github.com/kelredd/sinatra-helpers/tree/master/lib/sinatra_helpers/erb/
|
55
|
+
* fix content_block_tag to eliminate need for concat option
|
56
|
+
* image_tag should start in images_path (or /images)
|
57
|
+
* I have got to add tests, basically create dummy sinatra applications and use Webrat
|
58
|
+
* Partials with counter (and add to tests)
|
59
|
+
* http://github.com/sbfaulkner/sinatra-helpers/blob/master/lib/sinatra-helpers/haml/partials.rb
|
60
|
+
* http://github.com/kelredd/sinatra-helpers/blob/master/lib/sinatra_helpers/erb/partials.rb
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.33
|
data/bin/sinatra_gen
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
clear_sources
|
2
|
+
source 'http://gemcutter.org'
|
3
|
+
# Base requirements
|
4
|
+
gem 'sinatra'
|
5
|
+
gem 'sinatra_more'
|
6
|
+
gem 'rack-flash'
|
7
|
+
gem 'warden'
|
8
|
+
gem 'bcrypt-ruby', :require_as => 'bcrypt'
|
9
|
+
|
10
|
+
# Component requirements
|
11
|
+
|
12
|
+
# Testing requirements
|
13
|
+
gem 'rack-test', :require_as => 'rack/test', :only => :testing
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
RACK_ENV = ENV["RACK_ENV"] ||= "development" unless defined? RACK_ENV
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/config/boot.rb'
|
4
|
+
|
5
|
+
FileUtils.mkdir_p 'log' unless File.exists?('log')
|
6
|
+
log = File.new("log/sinatra.log", "a")
|
7
|
+
$stdout.reopen(log)
|
8
|
+
$stderr.reopen(log)
|
9
|
+
|
10
|
+
run <%= @class_name %>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# This file is merely for beginning the boot process, check dependencies.rb for more information
|
2
|
+
require 'rubygems'
|
3
|
+
require 'sinatra/base'
|
4
|
+
|
5
|
+
RACK_ENV = ENV["RACK_ENV"] ||= "development" unless defined? RACK_ENV
|
6
|
+
ROOT_DIR = File.dirname(__FILE__) + '/../' unless defined? ROOT_DIR
|
7
|
+
|
8
|
+
# Helper method for file references.
|
9
|
+
# root_path("config", "settings.yml")
|
10
|
+
def root_path(*args)
|
11
|
+
File.join(ROOT_DIR, *args)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns the full path to the public folder along with any given additions
|
15
|
+
# public_path("images")
|
16
|
+
def public_path(*args)
|
17
|
+
root_path('public', *args)
|
18
|
+
end
|
19
|
+
|
20
|
+
class <%= @class_name %> < Sinatra::Application
|
21
|
+
# Defines basic application settings
|
22
|
+
set :root, root_path
|
23
|
+
set :views, root_path("app", "views")
|
24
|
+
set :images_path, public_path("images")
|
25
|
+
set :default_builder, 'StandardFormBuilder'
|
26
|
+
set :environment, RACK_ENV.to_sym if defined?(RACK_ENV)
|
27
|
+
|
28
|
+
# Attempts to require all dependencies with bundler, if this fails, bundle and then try again
|
29
|
+
def self.bundler_require_dependencies(environment=nil)
|
30
|
+
require 'bundler'
|
31
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '/../vendor', 'gems', 'environment'))
|
32
|
+
Bundler.require_env(environment)
|
33
|
+
rescue LoadError => e
|
34
|
+
puts "Bundler must be run to resolve dependencies!"
|
35
|
+
system("cd #{ROOT_DIR}; gem bundle")
|
36
|
+
puts "Retrying with dependencies resolved..."
|
37
|
+
retry
|
38
|
+
end
|
39
|
+
|
40
|
+
# Dependencies contains all required gems and core configuration
|
41
|
+
require File.dirname(__FILE__) + '/dependencies.rb'
|
42
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Dependencies contains all required gems, helpers and core configuration
|
2
|
+
|
3
|
+
def app(&block)
|
4
|
+
<%= @class_name %>.class_eval(&block)
|
5
|
+
end
|
6
|
+
|
7
|
+
class <%= @class_name %> < Sinatra::Application
|
8
|
+
bundler_require_dependencies
|
9
|
+
|
10
|
+
# Required middleware
|
11
|
+
use Rack::Session::Cookie
|
12
|
+
use Rack::Flash
|
13
|
+
|
14
|
+
# Includes all necessary sinatra_more helpers
|
15
|
+
register Sinatra::MarkupPlugin
|
16
|
+
register Sinatra::RenderPlugin
|
17
|
+
register Sinatra::MailerPlugin
|
18
|
+
register Sinatra::RoutingPlugin
|
19
|
+
|
20
|
+
# Requires the initializer modules which configure specific components
|
21
|
+
Dir[File.dirname(__FILE__) + '/initializers/*.rb'].each do |file|
|
22
|
+
# Each initializer file contains a module called 'XxxxInitializer' (i.e HassleInitializer)
|
23
|
+
require file
|
24
|
+
file_class = File.basename(file, '.rb').camelize
|
25
|
+
register "#{file_class}Initializer".constantize
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns the list of load paths for this sinatra application
|
29
|
+
def self.file_loading_paths
|
30
|
+
["lib/**/*.rb", "app/helpers/**/*.rb", "app/routes/**/*.rb", "app/models/*.rb", "app/mailers/*.rb"]
|
31
|
+
end
|
32
|
+
|
33
|
+
# Require all the folders and files necessary to run the application
|
34
|
+
file_loading_paths.each { |load_path| Dir[root_path(load_path)].each { |file| require file } }
|
35
|
+
|
36
|
+
# Require Warden plugin below to allow User to be loaded
|
37
|
+
register Sinatra::WardenPlugin
|
38
|
+
|
39
|
+
# Required helpers
|
40
|
+
helpers ViewHelpers
|
41
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Sinatra
|
2
|
+
module ComponentActions
|
3
|
+
# Adds all the specified gems into the Gemfile for bundler
|
4
|
+
# require_dependencies 'activerecord'
|
5
|
+
# require_dependencies 'mocha', 'bacon', :env => :testing
|
6
|
+
def require_dependencies(*gem_names)
|
7
|
+
options = gem_names.extract_options!
|
8
|
+
gem_names.reverse.each { |lib| insert_into_gemfile(lib, options) }
|
9
|
+
end
|
10
|
+
|
11
|
+
# Inserts a required gem into the Gemfile to add the bundler dependency
|
12
|
+
# insert_into_gemfile(name)
|
13
|
+
# insert_into_gemfile(name, :env => :testing)
|
14
|
+
def insert_into_gemfile(name, options={})
|
15
|
+
after_pattern = "# Component requirements\n"
|
16
|
+
after_pattern = "# #{options[:env].to_s.capitalize} requirements\n" if environment = options[:env]
|
17
|
+
include_text = "gem '#{name}'"
|
18
|
+
include_text << ", :require_as => #{options[:require_as].inspect}" if options[:require_as]
|
19
|
+
include_text << ", :only => #{environment.inspect}" if environment
|
20
|
+
include_text << "\n"
|
21
|
+
options.merge!(:content => include_text, :after => after_pattern)
|
22
|
+
inject_into_file('Gemfile', options[:content], :after => options[:after])
|
23
|
+
end
|
24
|
+
|
25
|
+
# Injects the test class text into the test_config file for setting up the test gen
|
26
|
+
# insert_test_suite_setup('...CLASS_NAME...')
|
27
|
+
# => inject_into_file("test/test_config.rb", TEST.gsub(/CLASS_NAME/, @class_name), :after => "set :environment, :test\n")
|
28
|
+
def insert_test_suite_setup(suite_text, options={})
|
29
|
+
options.reverse_merge!(:path => "test/test_config.rb", :after => /Test configuration\n/)
|
30
|
+
inject_into_file(options[:path], suite_text.gsub(/CLASS_NAME/, @class_name), :after => options[:after])
|
31
|
+
end
|
32
|
+
|
33
|
+
# Injects the mock library include into the test class in test_config for setting up mock gen
|
34
|
+
# insert_mock_library_include('Mocha::API')
|
35
|
+
# => inject_into_file("test/test_config.rb", " include Mocha::API\n", :after => /class.*?\n/)
|
36
|
+
def insert_mocking_include(library_name, options={})
|
37
|
+
options.reverse_merge!(:indent => 2, :after => /class.*?\n/, :path => "test/test_config.rb")
|
38
|
+
include_text = indent_spaces(options[:indent]) + "include #{library_name}\n"
|
39
|
+
inject_into_file(options[:path], include_text, :after => options[:after])
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns space characters of given count
|
43
|
+
# indent_spaces(2)
|
44
|
+
def indent_spaces(count)
|
45
|
+
' ' * count
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|