big_band 0.2.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.md +82 -0
- data/Rakefile +50 -170
- data/TODO.md +50 -0
- data/lib/big_band.rb +13 -258
- data/lib/sinatra/big_band.rb +65 -1
- data/spec/sinatra/big_band_spec.rb +32 -0
- data/spec/spec_helper.rb +2 -4
- data/subproject.rb +42 -0
- data/tasks/doc.task +9 -0
- data/tasks/gem.task +10 -0
- data/tasks/git.task +41 -0
- data/tasks/setup.task +34 -0
- data/tasks/spec.task +24 -0
- metadata +200 -140
- data/README.rdoc +0 -346
- data/README.rdoc.erb +0 -39
- data/big_band.gemspec +0 -25
- data/dependencies.rb +0 -12
- data/depgen/README.rdoc +0 -7
- data/depgen/Rakefile +0 -23
- data/depgen/depgen.rb +0 -123
- data/depgen/depgen.task +0 -42
- data/depgen/depgen_spec.rb +0 -127
- data/deps.rip +0 -8
- data/example/example.rb +0 -13
- data/example/views/index.haml +0 -8
- data/example/views/layout.haml +0 -2
- data/example/views/stylesheets/_base.sass +0 -1
- data/example/views/stylesheets/screen.sass +0 -12
- data/lib/big_band/advanced_routes.rb +0 -188
- data/lib/big_band/basic_extensions.rb +0 -176
- data/lib/big_band/compass.rb +0 -94
- data/lib/big_band/compass/big_band.rb +0 -4
- data/lib/big_band/compass/stylesheets/_big_band.sass +0 -1
- data/lib/big_band/compass/stylesheets/big_band/_blueprint.sass +0 -1
- data/lib/big_band/compass/stylesheets/big_band/_utilities.sass +0 -6
- data/lib/big_band/compass/stylesheets/big_band/blueprint/_html5.sass +0 -4
- data/lib/big_band/compass/stylesheets/big_band/layouts/_inspector.sass +0 -103
- data/lib/big_band/compass/stylesheets/big_band/utilities/_border_radius.sass +0 -27
- data/lib/big_band/compass/stylesheets/big_band/utilities/_css3_prefix.sass +0 -14
- data/lib/big_band/compass/stylesheets/big_band/utilities/_fancy_buttons.sass +0 -62
- data/lib/big_band/compass/stylesheets/big_band/utilities/_html5.sass +0 -3
- data/lib/big_band/config_file.rb +0 -48
- data/lib/big_band/files/overlay-button.png +0 -0
- data/lib/big_band/integration.rb +0 -39
- data/lib/big_band/integration/bacon.rb +0 -10
- data/lib/big_band/integration/monk.rb +0 -26
- data/lib/big_band/integration/rake.rb +0 -80
- data/lib/big_band/integration/rspec.rb +0 -11
- data/lib/big_band/integration/test.rb +0 -42
- data/lib/big_band/integration/test/spec.rb +0 -2
- data/lib/big_band/integration/test/unit.rb +0 -2
- data/lib/big_band/integration/test_spec.rb +0 -8
- data/lib/big_band/integration/test_unit.rb +0 -10
- data/lib/big_band/integration/yard.rb +0 -104
- data/lib/big_band/more_helpers.rb +0 -50
- data/lib/big_band/more_server.rb +0 -14
- data/lib/big_band/more_server/rainbows.rb +0 -13
- data/lib/big_band/more_server/unicorn.rb +0 -27
- data/lib/big_band/reloader.rb +0 -113
- data/lib/big_band/sass.rb +0 -28
- data/lib/big_band/version.rb +0 -3
- data/lib/big_band/web_inspector.rb +0 -178
- data/lib/big_bang.rb +0 -6
- data/lib/sinatra/big_band/advanced_routes.rb +0 -2
- data/lib/sinatra/big_band/basic_extensions.rb +0 -2
- data/lib/sinatra/big_band/compass.rb +0 -2
- data/lib/sinatra/big_band/compass/big_band.rb +0 -2
- data/lib/sinatra/big_band/config_file.rb +0 -2
- data/lib/sinatra/big_band/integration.rb +0 -2
- data/lib/sinatra/big_band/integration/bacon.rb +0 -2
- data/lib/sinatra/big_band/integration/monk.rb +0 -2
- data/lib/sinatra/big_band/integration/rake.rb +0 -2
- data/lib/sinatra/big_band/integration/rspec.rb +0 -2
- data/lib/sinatra/big_band/integration/test.rb +0 -2
- data/lib/sinatra/big_band/integration/test/spec.rb +0 -2
- data/lib/sinatra/big_band/integration/test/unit.rb +0 -2
- data/lib/sinatra/big_band/integration/test_spec.rb +0 -2
- data/lib/sinatra/big_band/integration/test_unit.rb +0 -2
- data/lib/sinatra/big_band/integration/yard.rb +0 -2
- data/lib/sinatra/big_band/more_helpers.rb +0 -2
- data/lib/sinatra/big_band/more_server.rb +0 -2
- data/lib/sinatra/big_band/more_server/rainbows.rb +0 -2
- data/lib/sinatra/big_band/more_server/unicorn.rb +0 -2
- data/lib/sinatra/big_band/reloader.rb +0 -2
- data/lib/sinatra/big_band/sass.rb +0 -2
- data/lib/sinatra/big_band/version.rb +0 -2
- data/lib/sinatra/big_band/web_inspector.rb +0 -2
- data/lib/yard-sinatra.rb +0 -2
- data/spec/big_band/advanced_routes_spec.rb +0 -70
- data/spec/big_band/basic_extensions_spec.rb +0 -39
- data/spec/big_band/more_server_spec.rb +0 -7
- data/spec/big_band/sass_spec.rb +0 -21
- data/spec/spec.opts +0 -5
- data/yard-sinatra.gemspec +0 -24
data/LICENSE
CHANGED
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
Sinatra::BigBand
|
2
|
+
================
|
3
|
+
|
4
|
+
BigBand is a stack of [Sinatra](http://sinatrarb.com) extensions, most of them developed as part of BigBand, but usable without,
|
5
|
+
each of available as a separate gem. All BigBand extensions follow the same release cycle.
|
6
|
+
|
7
|
+
Usage
|
8
|
+
-----
|
9
|
+
|
10
|
+
Simply replace `Sinatra::Base` with `Sinatra::BigBand` in your application.
|
11
|
+
|
12
|
+
A simple example would be:
|
13
|
+
|
14
|
+
require 'sinatra/big_band'
|
15
|
+
class MyApp < Sinatra::BigBand
|
16
|
+
# ...
|
17
|
+
end
|
18
|
+
|
19
|
+
Maybe you want all extensions except `Sinatra::Compass`?
|
20
|
+
|
21
|
+
require 'sinatra/big_band'
|
22
|
+
class MyApp < Sinatra::BigBand :except => :Compass
|
23
|
+
# ...
|
24
|
+
end
|
25
|
+
|
26
|
+
The BigBand Stack
|
27
|
+
-----------------
|
28
|
+
|
29
|
+
Sinatra Extensions
|
30
|
+
|
31
|
+
* [Sinatra::AdvancedRoutes](http://github.com/rkh/sinatra-advanced-routes) – Makes routes first class objects
|
32
|
+
* [Sinatra::Compass](http://github.com/rkh/sinatra-compass) – Integrates the Compass stylesheet framework
|
33
|
+
* [Sinatra::ConfigFile](http://github.com/rkh/sinatra-config-file) – Adds YAML config file support
|
34
|
+
* [Sinatra::MoreServer](http://github.com/rkh/sinatra-more-server) – Adds support for more web servers to Sinatra::Base#run!
|
35
|
+
* [Sinatra::Namespace](http://github.com/rkh/sinatra-namespace) – Adds namespaces, allows namespaces to have local helpers.
|
36
|
+
* [Sinatra::Reloader](http://github.com/rkh/sinatra-reloader) – Advanced and fast code reloader
|
37
|
+
* [Sinatra::Sugar](http://github.com/rkh/sinatra-sugar) – Extensions for Sinatra's standard methods, like #set or #register
|
38
|
+
|
39
|
+
Sinatra tool integration:
|
40
|
+
|
41
|
+
* [AsyncRack](http://github.com/rkh/async-rack) – Makes standard rack middleware play nice with `async.callback`
|
42
|
+
* [Haml::More](http://github.com/rkh/haml-more) – Adds more functionality to Haml and Sass
|
43
|
+
* [monkey-lib](http://github.com/rkh/monkey-lib) – Thin layer over ruby extension libraries (like ActiveSupport) to make those pluggable
|
44
|
+
* [Sinatra::TestHelper](http://github.com/rkh/sinatra-test-helper) – Adds helper methods and better integration for various testing frameworks
|
45
|
+
* [Yard::Sinatra](http://github.com/rkh/yard-sinatra) – Displays Sinatra routes (including comments) in YARD output
|
46
|
+
|
47
|
+
Besides those extensions, there are others in the BigBand stack, that are external:
|
48
|
+
|
49
|
+
* [Rack Flash](http://github.com/nakajima/rack-flash) by Pat Nakajima
|
50
|
+
|
51
|
+
Goals for 0.4.0
|
52
|
+
---------------
|
53
|
+
|
54
|
+
* No sub-project relies on BigBand
|
55
|
+
* All sub-projects should work with MRI/REE >= 1.8.6 (including 1.9.x), JRuby >= 1.4.0 and Rubinius >= 1.0
|
56
|
+
* Some sub-projects should work with MagLev and IronRuby (partial MacRuby support planned for later release)
|
57
|
+
* Ease to modify the stack
|
58
|
+
|
59
|
+
Setup via gem
|
60
|
+
-------------
|
61
|
+
|
62
|
+
Try:
|
63
|
+
|
64
|
+
gem install big_band
|
65
|
+
|
66
|
+
Running the specs / Manual setup
|
67
|
+
--------------------------------
|
68
|
+
|
69
|
+
Try something like this:
|
70
|
+
|
71
|
+
# dependencies, rather mainstream. just in case you don't have one of those.
|
72
|
+
gem install sinatra rspec rack-test rake
|
73
|
+
|
74
|
+
# get the source
|
75
|
+
git clone git://github.com/rkh/big_band.git
|
76
|
+
rake setup:read_only
|
77
|
+
|
78
|
+
# run the specs
|
79
|
+
rake spec
|
80
|
+
|
81
|
+
# run with multiple ruby implementations using rvm
|
82
|
+
rvm specs ree,1.9.1,rbx,jruby
|
data/Rakefile
CHANGED
@@ -1,190 +1,70 @@
|
|
1
|
-
|
2
|
-
load "depgen/depgen.task"
|
1
|
+
# see tasks/*.task for rake tasks
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
else
|
8
|
-
task :default => [:dummy_files, "dependencies:generate:rip", :gems] # gems will trigger spec
|
9
|
-
end
|
10
|
-
|
11
|
-
$LOAD_PATH.unshift(*Dir.glob(File.expand_path(__FILE__ + "/../vendor/*/lib")))
|
12
|
-
require "erb"
|
13
|
-
require "spec/rake/spectask"
|
14
|
-
require "rake/clean"
|
15
|
-
require "rake/rdoctask"
|
16
|
-
require "monkey-lib"
|
17
|
-
require "yard"
|
3
|
+
$RELATIVE_LOAD_PATH = Dir.glob '{*,.}/lib'
|
4
|
+
$LOAD_PATH.unshift('.', *$RELATIVE_LOAD_PATH)
|
5
|
+
require 'subproject'
|
18
6
|
|
19
|
-
|
20
|
-
require "big_band/integration/yard"
|
21
|
-
require "big_band/integration/rake"
|
22
|
-
require "big_band/version"
|
23
|
-
|
24
|
-
include BigBand::Integration::Rake
|
25
|
-
RoutesTask.new { |t| t.source = "lib/**/*.rb" }
|
26
|
-
|
27
|
-
task :install => "gems:install"
|
28
|
-
task :test => :spec
|
29
|
-
task :clobber => "doc:clobber_rdoc"
|
7
|
+
task :default => ["setup:check", :spec]
|
30
8
|
|
9
|
+
require "rake/clean"
|
31
10
|
CLEAN.include "**/*.rbc"
|
32
|
-
CLOBBER.include "*.gem", "
|
33
|
-
|
34
|
-
Spec::Rake::SpecTask.new('spec') do |t|
|
35
|
-
t.spec_opts = %w[--options spec/spec.opts]
|
36
|
-
t.spec_files = Dir.glob 'spec/**/*_spec.rb'
|
37
|
-
end
|
38
|
-
|
39
|
-
TOOL_NAMES = { :Rspec => :RSpec, :Yard => :YARD, :TestSpec => :"Test::Spec", :TestUnit => :"Test::Unit" }
|
40
|
-
|
41
|
-
def yard(files)
|
42
|
-
YARD::Registry.load(Dir[files], true)
|
43
|
-
YARD::Registry.resolve(false, "BigBand")
|
44
|
-
end
|
45
|
-
|
46
|
-
def yard_children(ydoc, directory, defaults = {}, &block)
|
47
|
-
children = Dir.glob("#{directory}/*.rb").map { |f| f[(directory.size+1)..-4].to_const_string.to_sym }
|
48
|
-
children.select!(&block) if block
|
49
|
-
children.map! do |name|
|
50
|
-
rewritten_name = defaults[name] || name
|
51
|
-
ydoc.child(rewritten_name) or ydoc.child(name).tap { |c| c.name = rewritten_name unless c.nil? }
|
52
|
-
end
|
53
|
-
children.compact
|
54
|
-
end
|
55
|
-
|
56
|
-
def generate_readme(target = "README.rdoc", template = "README.rdoc.erb")
|
57
|
-
puts "generating #{target} from #{template}"
|
58
|
-
# HACK: loading other libraries later, for some strange heisenbug setting the docstring to an empty string later.
|
59
|
-
docstring = yard("lib/big_band.rb").docstring
|
60
|
-
ydoc = yard("lib/big_band/{**/,}*.rb")
|
61
|
-
extensions = yard_children(ydoc, "lib/big_band") { |n| n != :Integration }
|
62
|
-
integration = yard_children(ydoc.child(:Integration), "lib/big_band/integration", TOOL_NAMES) { |n| n != :Test }
|
63
|
-
version = BigBand::VERSION
|
64
|
-
File.open(target, "w") { |f| f << ERB.new(File.read(template), nil, "<>").result(binding) }
|
65
|
-
end
|
11
|
+
CLOBBER.include "*.gem", "doc"
|
66
12
|
|
67
|
-
|
68
|
-
|
13
|
+
def insert_desc(*values)
|
14
|
+
return unless Rake.application.last_comment
|
15
|
+
Rake.application.last_comment.replace(Rake.application.last_comment % values)
|
69
16
|
end
|
70
17
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
task "readme" do |t|
|
84
|
-
generate_readme
|
85
|
-
end
|
86
|
-
|
87
|
-
Rake::RDocTask.new("rdoc") do |rdoc|
|
88
|
-
rdoc.rdoc_dir = 'doc'
|
89
|
-
rdoc.options += %w[-a -S -N -m README.rdoc -q -w 2 -t BigBand -c UTF-8]
|
90
|
-
rdoc.rdoc_files.add ['*.{rdoc,rb}', '{config,lib,routes}/**/*.rb']
|
91
|
-
end
|
92
|
-
|
93
|
-
YARD::Rake::YardocTask.new("yardoc") do |t|
|
94
|
-
t.options = %w[--main README.rdoc --backtrace]
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
task :gems => "gems:build"
|
100
|
-
|
101
|
-
namespace :gems do
|
102
|
-
|
103
|
-
desc "Build gems (runs specs first)"
|
104
|
-
task :build => [:clobber, :spec, "doc:readme"] do
|
105
|
-
GEMS = []
|
106
|
-
Dir.glob("*.gemspec") do |file|
|
107
|
-
sh "gem build #{file}"
|
108
|
-
GEMS << "#{file[0..-9]}-#{BigBand::VERSION}.gem"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
desc "Install gems"
|
113
|
-
task :install => :build do
|
114
|
-
GEMS.each { |file| sh "gem install #{file}" }
|
115
|
-
end
|
116
|
-
|
117
|
-
desc "Publish gems (gemcutter)"
|
118
|
-
task :push => :build do
|
119
|
-
GEMS.each { |file| sh "gem push #{file}" }
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
desc "generate dummy files"
|
125
|
-
task :dummy_files do |t|
|
126
|
-
chdir "lib" do
|
127
|
-
rm_rf "sinatra/big_band/"
|
128
|
-
mkdir_p "sinatra/big_band/"
|
129
|
-
Dir.glob("big_band/**/*.rb") do |file|
|
130
|
-
target = "sinatra" / file
|
131
|
-
mkdir_p target.dirname
|
132
|
-
File.open(target, "w") do |f|
|
133
|
-
f.puts "# Generated file, run 'rake #{t.name}' to regenerate"
|
134
|
-
f.puts "require #{file[0..-4].inspect}"
|
18
|
+
def project_namespace(parent = nil, all = true, &block)
|
19
|
+
return namespace(parent) { project_namespace(nil, all, &block) } if parent
|
20
|
+
project_was, default_desc_was = @project, @default_desc
|
21
|
+
namespaces = Subproject.inject({}) { |h, p| h.merge p.name => p}
|
22
|
+
namespaces[all == true ? nil : all] = :all if all
|
23
|
+
namespaces.each do |name, project|
|
24
|
+
@project, @default_desc = project, false
|
25
|
+
if name
|
26
|
+
namespace(name, &block)
|
27
|
+
if @default_desc
|
28
|
+
desc @default_desc
|
29
|
+
task name => "#{name}:default"
|
135
30
|
end
|
31
|
+
else
|
32
|
+
yield
|
136
33
|
end
|
137
34
|
end
|
35
|
+
@project, @default_desc = project_was, default_desc_was
|
138
36
|
end
|
139
37
|
|
140
|
-
|
141
|
-
|
142
|
-
|
38
|
+
def subproject
|
39
|
+
@subproject
|
40
|
+
end
|
143
41
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
42
|
+
def subproject_block(project)
|
43
|
+
proc do |raketask|
|
44
|
+
@subproject, subproject_was = project, @subproject
|
45
|
+
yield raketask if block_given?
|
46
|
+
@subproject = subproject_was
|
148
47
|
end
|
48
|
+
end
|
149
49
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
50
|
+
def project_task(name, &block)
|
51
|
+
return project_namespace { project_task(name, &block) } unless @project
|
52
|
+
name, dependencies = name.to_a.first if name.is_a? Hash
|
53
|
+
dependencies = [dependencies].flatten.compact
|
54
|
+
if @project == :all
|
55
|
+
dependencies += Subproject.map { |p| "#{p.name}:#{name}" }
|
56
|
+
block = nil
|
57
|
+
insert_desc "all subprojects"
|
58
|
+
else
|
59
|
+
insert_desc @project.name
|
160
60
|
end
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
task :git => :prepare do
|
165
|
-
message = "-m 'release: #{BigBand::VERSION}'"
|
166
|
-
sh "git ci -a #{message}"
|
167
|
-
sh "git tag -a v#{BigBand::VERSION} #{message}"
|
168
|
-
sh "git push && git push --tags"
|
61
|
+
if name.to_s == "default"
|
62
|
+
@default_desc = Rake.application.last_comment
|
63
|
+
desc nil
|
169
64
|
end
|
170
|
-
|
171
|
-
task :gem => [:git, "gems:push"]
|
172
|
-
|
65
|
+
task({name => dependencies}, &subproject_block(@project, &block))
|
173
66
|
end
|
174
67
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
task :c => [:clobber, "doc:readme"]
|
179
|
-
task :s => :spec
|
180
|
-
task :d
|
181
|
-
namespace :d do
|
182
|
-
task :r => "doc:readme"
|
183
|
-
task :y => "doc:yardoc"
|
184
|
-
end
|
185
|
-
task :g => :gems
|
186
|
-
namespace :g do
|
187
|
-
task :b => "gems:build"
|
188
|
-
task :i => "gems:install"
|
189
|
-
task :p => "gems:push"
|
68
|
+
Dir.glob("tasks/*.task").sort.each do |file|
|
69
|
+
eval File.read(file), binding, file, 1
|
190
70
|
end
|
data/TODO.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
TODO
|
2
|
+
====
|
3
|
+
|
4
|
+
For 0.4.0 release
|
5
|
+
-----------------
|
6
|
+
|
7
|
+
All subprojects:
|
8
|
+
|
9
|
+
* Add licenses, deps.rip, maybe dependencies file for monk
|
10
|
+
|
11
|
+
BigBand:
|
12
|
+
|
13
|
+
* Create some sort of website (GitHub Pages?)
|
14
|
+
* Write example app
|
15
|
+
|
16
|
+
After 0.4.0
|
17
|
+
-----------
|
18
|
+
|
19
|
+
General:
|
20
|
+
|
21
|
+
* Implement more fancy stuff
|
22
|
+
* Padrino integration (maybe an example app, maybe some docs, dunno)
|
23
|
+
* Monk skeleton using big\_band
|
24
|
+
* See if stack\_helper can be extracted and is of any use (stack\_helper branch)
|
25
|
+
* Improve inline documentation (YARD tags)
|
26
|
+
* Maybe switch to [sinatra-flash](http://github.com/SFEley/sinatra-flash)
|
27
|
+
|
28
|
+
sinatra-advanced-routes:
|
29
|
+
|
30
|
+
* Make compatible with [Usher](http://github.com/joshbuddy/usher)
|
31
|
+
* Make compatible with [padrino-core/routing](http://github.com/padrino/padrino-framework/issues/issue/46)
|
32
|
+
|
33
|
+
Subprojects to be published or written:
|
34
|
+
|
35
|
+
* queueba (yet another message queue based on redis, maybe)
|
36
|
+
* sinatra-postpone
|
37
|
+
* "sinatra-queueba" or redis channel for pusher + pusher integration for sinatra
|
38
|
+
|
39
|
+
Before 0.5.0
|
40
|
+
------------
|
41
|
+
|
42
|
+
BigBand:
|
43
|
+
|
44
|
+
* remove `::BigBand`
|
45
|
+
|
46
|
+
monkey-lib:
|
47
|
+
|
48
|
+
* remove `Object#metaclass`
|
49
|
+
* remove `Object#metaclass_eval`
|
50
|
+
|
data/lib/big_band.rb
CHANGED
@@ -1,264 +1,19 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require "set"
|
4
|
-
|
5
|
-
# BigBand is a collection of Sinatra extensions and offers better sinatra integration for common tools.
|
6
|
-
# It is pluggable and each extension can be used in stand alone mode.
|
7
|
-
#
|
8
|
-
# The main features are:
|
9
|
-
# * Routes as first class objects
|
10
|
-
# * Better handling of #set: Merges hashes, more hooks
|
11
|
-
# * Better compass integration
|
12
|
-
# * YAML config files mapping to set (overwriting present values/methods is prevented)
|
13
|
-
# * Rails-like helpers, like content_for
|
14
|
-
# * Unicorn and Rainbows integration
|
15
|
-
# * Smart code reloader only reloading changed files and getting rid of old routes
|
16
|
-
# * Sass extensions
|
17
|
-
# * Routes for inspection in development mode
|
18
|
-
# * Helpers and configuration for Bacon, RSpec, Test::Spec and Test::Unit
|
19
|
-
# * Tasks listing all routes for Monk and Rake.
|
20
|
-
# * YARD: Add Sinatra routes to generated documentation
|
21
|
-
#
|
22
|
-
# Planned features:
|
23
|
-
# * More template helpers
|
24
|
-
# * ORM integration
|
25
|
-
# * MSpec integration
|
26
|
-
#
|
27
|
-
# == Usage
|
28
|
-
#
|
29
|
-
# Using all BigBand features:
|
30
|
-
#
|
31
|
-
# require "sinatra/big_band"
|
32
|
-
# class Example < Sinatra::BigBand
|
33
|
-
# # Yay, BigBand!
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
# Or you may use the extension style:
|
37
|
-
#
|
38
|
-
# class AnotherExample < Sinatra::Base
|
39
|
-
# register Sinatra::BigBand
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
# Or for the lazy folks (if you use classic style):
|
43
|
-
#
|
44
|
-
# require "sinatra"
|
45
|
-
# require "sinatra/big_band"
|
46
|
-
# # Yay, BigBand!
|
47
|
-
#
|
48
|
-
# Sinatra::BigBand is just an alias for BigBand. It was introduced manly to (in my opinion) have prettier
|
49
|
-
# class signatures. First "class Example < Sinatra::BigBand" looks like Sinatra "class Example < BigBand", lets
|
50
|
-
# give some credit to our beloved framework. Also, Sinatra::BigBand seems more akin to Sinatra::Base, Sinatra::Application
|
51
|
-
# and Sinatra::Default, than just BigBand. Other than that I do not plan to move BigBand completely into Sinatra simply
|
52
|
-
# to avoid more nesting. Last, but no least, the Sinatra docs sugest placing extensions inside Sinatra.
|
53
|
-
#
|
54
|
-
# Using just your favorite BigBand features:
|
55
|
-
#
|
56
|
-
# require "big_band"
|
57
|
-
# class Example < Sinatra::Base
|
58
|
-
# register BigBand::SomeFeature
|
59
|
-
# # Yay, SomeFeature!
|
60
|
-
# end
|
61
|
-
#
|
62
|
-
# Or, if you like a more handy syntax:
|
63
|
-
#
|
64
|
-
# require "sinatra/big_band"
|
65
|
-
# class Example < Sinatra::BigBand :SomeFeature, MyStuff::Extension, :development => :DevelopmentOnlyFeature
|
66
|
-
# # Yay, BigBand::SomeFeature!
|
67
|
-
# # Yay, MyStuff::Extension!
|
68
|
-
# # Yay, BigBand::DevelopmentOnlyFeature, if this is development mode!
|
69
|
-
# end
|
70
|
-
#
|
71
|
-
# Loading all but one feature:
|
72
|
-
#
|
73
|
-
# require "sinatra/big_band"
|
74
|
-
# class Example < Sinatra::BigBand :except => :SomeFeature
|
75
|
-
# # Yay, all but BigBand::SomeFeature!
|
76
|
-
# end
|
77
|
-
#
|
78
|
-
# Or just your favorite feature without you subclassing Sinatra::Base manually:
|
79
|
-
#
|
80
|
-
# require "sinatra"
|
81
|
-
# require "big_band/some_feature"
|
82
|
-
# Sinatra::Application.register BigBand::SomeFeature
|
83
|
-
# # Yay, BigBand::SomeFeature!
|
84
|
-
class BigBand < Sinatra::Base
|
85
|
-
|
86
|
-
# Classes generated by BigBand.generate_class will be extended
|
87
|
-
# with this class.
|
88
|
-
module Generated
|
89
|
-
|
90
|
-
attr_reader :big_band_extensions, :big_band_constructor
|
91
|
-
|
92
|
-
# Adds extensions to subclass
|
93
|
-
def inherited(klass)
|
94
|
-
super
|
95
|
-
BigBand.applications << klass
|
96
|
-
BigBand.load_extensions(klass, *big_band_extensions)
|
97
|
-
end
|
98
|
-
|
99
|
-
# Use Generated#name for inspection.
|
100
|
-
def inspect
|
101
|
-
name
|
102
|
-
end
|
103
|
-
|
104
|
-
# Nice output for inspect and friends:
|
105
|
-
# foo = Class.new BigBand(:SomeExtension)
|
106
|
-
# foo.name # => BigBand(:SomeExtension)
|
107
|
-
# Foo = foo
|
108
|
-
# foo.name # => Foo
|
109
|
-
def name
|
110
|
-
real_name = super
|
111
|
-
real_name.empty? ? big_band_constructor : real_name
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
extend Generated
|
117
|
-
|
118
|
-
def self.applications
|
119
|
-
@applications ||= []
|
120
|
-
end
|
121
|
-
|
122
|
-
# Extensions to load.
|
123
|
-
def self.big_band_extensions
|
124
|
-
default_extensions
|
125
|
-
end
|
126
|
-
|
127
|
-
# Generates a class for the given extensions. Note that this class is ment to be
|
128
|
-
# subclassed rather than used directly. Given extensione will only be available for
|
129
|
-
# subclasses.
|
130
|
-
#
|
131
|
-
# class Foo < BigBand.generate_class(:except => :SomeExtension)
|
132
|
-
# end
|
133
|
-
def self.generate_class(*options)
|
134
|
-
@generated_classes ||= {setify_parameters([]) => BigBand}
|
135
|
-
@generated_classes[setify_parameters(options)] ||= Class.new(Sinatra::Base) do
|
136
|
-
extend BigBand::Generated
|
137
|
-
@big_band_extensions = options
|
138
|
-
@big_band_constructor = "BigBand(#{options.map { |o| o.inspect}.join ", "})"
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
# Adds extensions to a Sinatra application:
|
143
|
-
#
|
144
|
-
# class MyApp < Sinatra::Base
|
145
|
-
# end
|
146
|
-
#
|
147
|
-
# BigBand.load_extensions MyApp, :SomeExtension, :development => :AnotherExtension
|
148
|
-
def self.load_extensions(klass, *extensions)
|
149
|
-
extensions = default_extensions if extensions.empty?
|
150
|
-
extensions.flatten.each do |extension|
|
151
|
-
if extension.respond_to? :each_pair
|
152
|
-
extension.each_pair do |key, value|
|
153
|
-
values = [value].flatten
|
154
|
-
case key
|
155
|
-
when :production, :test, :development
|
156
|
-
klass.configure(key) { BigBand.load_extensions(klass, *values) }
|
157
|
-
when :except
|
158
|
-
exts = @nonenv_extensions.reject { |e| values.include? e }
|
159
|
-
exts << @env_extensions.inject({}) do |accepted, (env, list)|
|
160
|
-
accepted.merge env => list.reject { |e| values.include? e }
|
161
|
-
end
|
162
|
-
load_extensions(klass, *exts)
|
163
|
-
else raise ArgumentError, "unknown key #{key.inspect}"
|
164
|
-
end
|
165
|
-
end
|
166
|
-
else
|
167
|
-
klass.register module_for(extension)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
# Returns the module for a given extension identifier:
|
173
|
-
#
|
174
|
-
# BigBand.module_for :BasicExtension # => BigBand::BasicExtension
|
175
|
-
# BigBand.module_for Array # => Array
|
176
|
-
# BigBand.module_for "Foo::Bar" # => BigBand::Foo::Bar or Foo::Bar or raises an exception
|
177
|
-
def self.module_for(extension)
|
178
|
-
case extension
|
179
|
-
when Module then extension
|
180
|
-
when String then extension.split("::").inject(self) { |klass, name| klass.const_get name }
|
181
|
-
when Symbol then const_get(extension)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
def self.setify_parameters(args)
|
186
|
-
case args
|
187
|
-
when Hash then args.inject({}) { |h,(k,v)| h k => setify_parameters(v) }
|
188
|
-
when Array then args.flatten.to_set
|
189
|
-
else args
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
# Default extensions that will be used whenever you subclass BigBand. You can also use this to create
|
194
|
-
# your own extension collection:
|
195
|
-
#
|
196
|
-
# class MyExtensions < BigBand(:except => :ExtensionIDontLike)
|
197
|
-
# default_extension FunkyExtension, :development => DevExtension
|
198
|
-
# end
|
199
|
-
#
|
200
|
-
# Note: If given a string or symbol, it will also try to setup an autoloader:
|
201
|
-
#
|
202
|
-
# MyExtensions.default_extensions :Foo
|
203
|
-
def self.default_extensions(*extensions)
|
204
|
-
return @default_extensions if @default_extensions and extensions.empty?
|
205
|
-
@nonenv_extensions ||= []
|
206
|
-
@env_extensions ||= {:development => []}
|
207
|
-
extensions.each do |extension|
|
208
|
-
if extension.respond_to? :each_pair
|
209
|
-
extension.each_pair { |env, exts| (@env_extensions[env] ||= []).push(*exts) }
|
210
|
-
else
|
211
|
-
@nonenv_extensions.push(*extension)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
@default_extensions = [@nonenv_extensions, @env_extensions].flatten
|
215
|
-
end
|
216
|
-
|
217
|
-
def self.default_extension(name, path = nil, env = nil)
|
218
|
-
autoload name, path if path
|
219
|
-
default_extensions(env ? {env => name} : name)
|
220
|
-
end
|
221
|
-
|
222
|
-
default_extension :AdvancedRoutes, "big_band/advanced_routes"
|
223
|
-
default_extension :BasicExtensions, "big_band/basic_extensions"
|
224
|
-
default_extension :Compass, "big_band/compass"
|
225
|
-
default_extension :ConfigFile, "big_band/config_file"
|
226
|
-
default_extension :MoreHelpers, "big_band/more_helpers"
|
227
|
-
default_extension :MoreServer, "big_band/more_server"
|
228
|
-
default_extension :Reloader, "big_band/reloader", :development
|
229
|
-
default_extension :Sass, "big_band/sass"
|
230
|
-
default_extension :WebInspector, "big_band/web_inspector", :development
|
1
|
+
warn "#{caller.detect { |c| c !~ /require/ }}: require 'big_band' is deprecated, use require 'sinatra/big_band' instead."
|
2
|
+
require "sinatra/big_band"
|
231
3
|
|
4
|
+
def BigBand(*args, &block)
|
5
|
+
warn "#{caller.first}: Using BigBand is deprecated, use Sinatra::BigBand instead. It will be removed in BigBand 0.5."
|
6
|
+
Monkey.invisible { Sinatra::BigBand(*args, &block) }
|
232
7
|
end
|
233
8
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
class << self
|
243
|
-
alias register_without_big_band register
|
244
|
-
def register(*extensions, &block)
|
245
|
-
big_band, normal = extensions.partition { |e| e.respond_to? :big_band_extensions }
|
246
|
-
big_band.each { |e| e.load_extensions self }
|
247
|
-
register_without_big_band(*normal, &block)
|
248
|
-
extensions
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
module Delegator
|
253
|
-
# Hooks into Sinatra to allow easy integration with "require 'sinatra'".
|
254
|
-
def self.included(klass)
|
255
|
-
BigBand.inherited(Sinatra::Application)
|
256
|
-
Sinatra::Application.extensions.each do |ext|
|
257
|
-
delegate(*ext.delegations) if ext.respond_to? :delegations
|
258
|
-
end
|
9
|
+
Module.class_eval do
|
10
|
+
alias const_missing_without_deprecation_warnings const_missing
|
11
|
+
def const_missing(name)
|
12
|
+
Monkey.invisible __FILE__ do
|
13
|
+
return const_missing_without_deprecation_warnings(name) unless name == :BigBand and self != ::Sinatra
|
14
|
+
from = caller.detect { |e| e !~ /const_missing/ }
|
15
|
+
warn "#{from}: Using BigBand is deprecated, use Sinatra::BigBand instead. It will be removed in BigBand 0.5."
|
16
|
+
Sinatra::BigBand
|
259
17
|
end
|
260
18
|
end
|
261
19
|
end
|
262
|
-
|
263
|
-
# If require "sinatra" came before require "big_band" Sinatra::Delegator.included has not been called.
|
264
|
-
Sinatra::Delegator.included(self) if is_a? Sinatra::Delegator
|