big_band 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +27 -0
- data/README.rdoc +303 -0
- data/README.rdoc.erb +39 -0
- data/Rakefile +129 -0
- data/big_band.gemspec +29 -0
- data/example/example.rb +13 -0
- data/example/views/index.haml +8 -0
- data/example/views/layout.haml +2 -0
- data/example/views/stylesheets/_base.sass +1 -0
- data/example/views/stylesheets/screen.sass +12 -0
- data/lib/big_band/advanced_routes.rb +184 -0
- data/lib/big_band/basic_extensions.rb +176 -0
- data/lib/big_band/compass/big_band.rb +4 -0
- data/lib/big_band/compass/stylesheets/_big_band.sass +1 -0
- data/lib/big_band/compass/stylesheets/big_band/_blueprint.sass +1 -0
- data/lib/big_band/compass/stylesheets/big_band/_utilities.sass +6 -0
- data/lib/big_band/compass/stylesheets/big_band/blueprint/_html5.sass +4 -0
- data/lib/big_band/compass/stylesheets/big_band/layouts/_inspector.sass +103 -0
- data/lib/big_band/compass/stylesheets/big_band/utilities/_border_radius.sass +27 -0
- data/lib/big_band/compass/stylesheets/big_band/utilities/_css3_prefix.sass +14 -0
- data/lib/big_band/compass/stylesheets/big_band/utilities/_fancy_buttons.sass +62 -0
- data/lib/big_band/compass/stylesheets/big_band/utilities/_html5.sass +3 -0
- data/lib/big_band/compass.rb +94 -0
- data/lib/big_band/files/overlay-button.png +0 -0
- data/lib/big_band/integration/bacon.rb +10 -0
- data/lib/big_band/integration/monk.rb +26 -0
- data/lib/big_band/integration/rake.rb +60 -0
- data/lib/big_band/integration/rspec.rb +11 -0
- data/lib/big_band/integration/test/spec.rb +2 -0
- data/lib/big_band/integration/test/unit.rb +2 -0
- data/lib/big_band/integration/test.rb +42 -0
- data/lib/big_band/integration/test_spec.rb +8 -0
- data/lib/big_band/integration/test_unit.rb +10 -0
- data/lib/big_band/integration/yard.rb +104 -0
- data/lib/big_band/integration.rb +42 -0
- data/lib/big_band/more_helpers.rb +50 -0
- data/lib/big_band/more_server/rainbows.rb +13 -0
- data/lib/big_band/more_server/unicorn.rb +28 -0
- data/lib/big_band/more_server.rb +14 -0
- data/lib/big_band/reloader.rb +113 -0
- data/lib/big_band/sass.rb +28 -0
- data/lib/big_band/version.rb +3 -0
- data/lib/big_band/web_inspector.rb +178 -0
- data/lib/big_band.rb +239 -0
- data/lib/big_bang.rb +6 -0
- data/lib/yard-sinatra.rb +2 -0
- data/spec/big_band/advanced_routes_spec.rb +70 -0
- data/spec/big_band/basic_extensions_spec.rb +39 -0
- data/spec/big_band/more_server_spec.rb +7 -0
- data/spec/big_band/sass_spec.rb +21 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +4 -0
- data/yard-sinatra.gemspec +24 -0
- metadata +167 -0
@@ -0,0 +1,178 @@
|
|
1
|
+
require "sinatra/base"
|
2
|
+
require "monkey-lib"
|
3
|
+
require "big_band/compass"
|
4
|
+
|
5
|
+
class BigBand < Sinatra::Base
|
6
|
+
|
7
|
+
# The WebInspector allowes you to inspect a running Sinatra app.
|
8
|
+
# Just browse http://localhost:4567/\_\_inspect\_\_
|
9
|
+
#
|
10
|
+
# Per default this will only be activated in development mode.
|
11
|
+
module WebInspector
|
12
|
+
|
13
|
+
attr_reader :middleware
|
14
|
+
|
15
|
+
class Middleware < Sinatra::Base
|
16
|
+
|
17
|
+
attr_accessor :sinatra_app
|
18
|
+
use_in_file_templates! __FILE__
|
19
|
+
register BasicExtensions
|
20
|
+
set :app_file, __FILE__
|
21
|
+
|
22
|
+
# If this is a git project, then it returns the path to the .git directory.
|
23
|
+
def git_directory
|
24
|
+
@git_directory ||= root_glob(".{,.,./..,./../..}/.git").first
|
25
|
+
end
|
26
|
+
|
27
|
+
# Whether or not this is a git project.
|
28
|
+
def git?
|
29
|
+
!!git_directory
|
30
|
+
end
|
31
|
+
|
32
|
+
# Figures out some URLs to public git hosts by parsing the remote urls from the git config.
|
33
|
+
# Currently detects: GitHub, Codaset and Gitorious.
|
34
|
+
def git_remotes
|
35
|
+
@git_remotes ||= (File.read(git_directory / :config).scan(/\s*url\s*=\s*(.*)\n/).flatten.collect do |url|
|
36
|
+
case url
|
37
|
+
when %r{(github.com)[:/](.+)/(.+)/?\.git$} then [$3, "GitHub", "http://#$1/#$2/#$3", "http://#$1"]
|
38
|
+
when %r{(codaset.com)[:/](.+)/(.+)?\.git$} then [$3, "Codaset", "http://#$1/#$2/#$3", "http://#$1"]
|
39
|
+
when %r{(gitorious.org)[:/](.+)/.+/?\.git$} then [$2, "Gitorious", "http://#$1/#$2", "http://#$1"]
|
40
|
+
end
|
41
|
+
end).compact
|
42
|
+
end
|
43
|
+
|
44
|
+
# Recent git log.
|
45
|
+
def git_log
|
46
|
+
@git_format ||= begin
|
47
|
+
line = ["<a href='mailto:%ae'>%an</a>", "%s", "<date>%ai</date>"].map { |e| "<td>#{e}</td>" }.join
|
48
|
+
"<tr>#{line}</tr>"
|
49
|
+
end
|
50
|
+
%x[git log -50 --pretty=format:"#{@git_format}"]
|
51
|
+
end
|
52
|
+
|
53
|
+
# webinspector stylesheet.
|
54
|
+
get "/__inspect__/screen.css" do
|
55
|
+
content_type 'text/css', :charset => 'utf-8'
|
56
|
+
sass :stylesheet, ::Compass.sass_engine_options
|
57
|
+
end
|
58
|
+
|
59
|
+
# Route for inspection. Currently we display all information on a single page. In case the amount of data
|
60
|
+
# increases, we might split this on multiple pages. Also, this would ease hooking own data into the front-end.
|
61
|
+
get "/__inspect__/?" do
|
62
|
+
ruby_env = %w[RUBY_VERSION RUBY_DESCRIPTION RUBY_PATCHLEVEL RUBY_PLATFORM RUBY_ENGINE RUBY_ENGINE_VERSION]
|
63
|
+
ruby_env.map! { |var| [var, eval("#{var}.inspect if defined? #{var}")] }
|
64
|
+
haml :inspect, {}, :ruby_env => ruby_env
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.registered(klass)
|
70
|
+
klass.register BasicExtensions
|
71
|
+
klass.register AdvancedRoutes
|
72
|
+
klass.use(Middleware) { |m| m.sinatra_app = klass }
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
__END__
|
79
|
+
|
80
|
+
@@layout
|
81
|
+
!!!
|
82
|
+
%html
|
83
|
+
%head
|
84
|
+
%meta{:charset=>"utf-8"}/
|
85
|
+
%link{:rel => "stylesheet", :href => "/__inspect__/screen.css", :type => "text/css"}/
|
86
|
+
%title= "#{sinatra_app.name}.inspect"
|
87
|
+
%body
|
88
|
+
%header
|
89
|
+
%h1= "#{sinatra_app.name}.inspect"
|
90
|
+
Generated on
|
91
|
+
%date= Time.now
|
92
|
+
%nav
|
93
|
+
%a{:href => "/__inspect__/#routes" } Routes
|
94
|
+
%a{:href => "/__inspect__/#extensions" } Extensions
|
95
|
+
%a{:href => "/__inspect__/#middleware" } Middleware
|
96
|
+
%a{:href => "/__inspect__/#system" } System
|
97
|
+
- if git?
|
98
|
+
%a{:href => "/__inspect__/#git_log" } Git Log
|
99
|
+
%article
|
100
|
+
!=yield
|
101
|
+
%footer
|
102
|
+
powered by
|
103
|
+
%a{:href => "http://www.sinatrarb.com"} Sinatra
|
104
|
+
and
|
105
|
+
%a{:href => "http://github.com/rkh/big_band"} BigBand
|
106
|
+
|
107
|
+
@@stylesheet
|
108
|
+
@import big_band/layouts/inspector.sass
|
109
|
+
+layout_inspector
|
110
|
+
|
111
|
+
@@inspect
|
112
|
+
|
113
|
+
%a{ :name => "routes" }
|
114
|
+
%h2 Routes
|
115
|
+
%table
|
116
|
+
%tr
|
117
|
+
%th Verb
|
118
|
+
%th Pattern
|
119
|
+
%th File
|
120
|
+
%th Keys
|
121
|
+
%th Conditions
|
122
|
+
- sinatra_app.each_route do |route|
|
123
|
+
%tr
|
124
|
+
%td= route.verb
|
125
|
+
%td= route.pattern.inspect
|
126
|
+
%td
|
127
|
+
- if route.file?
|
128
|
+
= route.file
|
129
|
+
%i= "(line #{route.line})" if route.line
|
130
|
+
%td= route.keys.map { |e| e.inspect }.join ", "
|
131
|
+
%td= route.conditions.map { |e| e.inspect }.join ", "
|
132
|
+
|
133
|
+
%a{ :name => "extensions" }
|
134
|
+
%h2 Extensions
|
135
|
+
%table
|
136
|
+
%tr
|
137
|
+
%th Extension
|
138
|
+
%th Status
|
139
|
+
- sinatra_app.extensions.each do |extension|
|
140
|
+
%tr
|
141
|
+
%td= extension.name
|
142
|
+
%td= extension.status if extension.respond_to? :status
|
143
|
+
|
144
|
+
%a{ :name => "middleware" }
|
145
|
+
%h2 Middleware
|
146
|
+
%table
|
147
|
+
%tr
|
148
|
+
%th Middleware
|
149
|
+
%th Arguments
|
150
|
+
%th Block Given
|
151
|
+
- sinatra_app.middleware.each do |name, arguments, block|
|
152
|
+
%tr
|
153
|
+
%td= name
|
154
|
+
%td= arguments.map { |e| e.inspect }.join ", "
|
155
|
+
%td= block ? "yes" : "no"
|
156
|
+
|
157
|
+
%a{ :name => "system" }
|
158
|
+
%h2 System
|
159
|
+
%table
|
160
|
+
%tr
|
161
|
+
%th Variable
|
162
|
+
%th Value
|
163
|
+
- ruby_env.each do |key, value|
|
164
|
+
%tr
|
165
|
+
%td= key
|
166
|
+
%td= value
|
167
|
+
|
168
|
+
- if git?
|
169
|
+
%a{ :name => "git_log" }
|
170
|
+
%h2 Recent Git Log
|
171
|
+
- git_remotes.each do |name, service, url, service_url|
|
172
|
+
.note Visit <a href="#{url}">#{name}</a> on <a href="#{service_url}">#{service}</a>.
|
173
|
+
%table
|
174
|
+
%tr
|
175
|
+
%th Author
|
176
|
+
%th Subject
|
177
|
+
%th Date
|
178
|
+
!= git_log
|
data/lib/big_band.rb
ADDED
@@ -0,0 +1,239 @@
|
|
1
|
+
require "sinatra/base"
|
2
|
+
#require "monkey-lib"
|
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
|
+
# * Rails-like helpers, like content_for
|
13
|
+
# * Unicorn and Rainbows integration
|
14
|
+
# * Smart code reloader only reloading changed files and getting rid of old routes
|
15
|
+
# * Sass extensions
|
16
|
+
# * Routes for inspection in development mode
|
17
|
+
# * Helpers and configuration for Bacon, RSpec, Test::Spec and Test::Unit
|
18
|
+
# * Tasks listing all routes for Monk and Rake.
|
19
|
+
# * YARD: Add Sinatra routes to generated documentation
|
20
|
+
#
|
21
|
+
# Planned features:
|
22
|
+
# * More template helpers
|
23
|
+
# * ORM integration
|
24
|
+
# * Configuration handling
|
25
|
+
# * MSpec integration
|
26
|
+
#
|
27
|
+
# == Usage
|
28
|
+
#
|
29
|
+
# Using all BigBand features:
|
30
|
+
#
|
31
|
+
# require "big_band"
|
32
|
+
# class Example < BigBand
|
33
|
+
# # Yay, BigBand!
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# Or for the lazy folks (read: you would don't subclass Sinatra::Base on your own):
|
37
|
+
#
|
38
|
+
# require "sinatra"
|
39
|
+
# require "big_band"
|
40
|
+
# # Yay, BigBand!
|
41
|
+
#
|
42
|
+
# Using just your favorite BigBand features:
|
43
|
+
#
|
44
|
+
# require "big_band"
|
45
|
+
# class Example < Sinatra::Base
|
46
|
+
# register BigBand::SomeFeature
|
47
|
+
# # Yay, BigBand::SomeFeature!
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# Or, if you like a more handy syntax:
|
51
|
+
#
|
52
|
+
# require "big_band"
|
53
|
+
# class Example < BigBand :SomeFeature, MyStuff::Extension, :development => :DevelopmentOnlyFeature
|
54
|
+
# # Yay, BigBand::SomeFeature!
|
55
|
+
# # Yay, MyStuff::Extension!
|
56
|
+
# # Yay, BigBand::DevelopmentOnlyFeature, if this is development mode!
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# Loading all but one feature:
|
60
|
+
#
|
61
|
+
# require "big_band"
|
62
|
+
# class Example < BigBand :except => :SomeFeature
|
63
|
+
# # Yay, all but BigBand::SomeFeature!
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# Or just your favorite feature without you subclassing Sinatra::Base manually:
|
67
|
+
#
|
68
|
+
# require "sinatra"
|
69
|
+
# require "big_band/some_feature"
|
70
|
+
# Sinatra::Application.register BigBand::SomeFeature
|
71
|
+
# # Yay, BigBand::SomeFeature!
|
72
|
+
class BigBand < Sinatra::Base
|
73
|
+
|
74
|
+
# Classes generated by BigBand.generate_class will be extended
|
75
|
+
# with this class.
|
76
|
+
module Generated
|
77
|
+
|
78
|
+
attr_reader :big_band_extensions, :big_band_constructor
|
79
|
+
|
80
|
+
# Adds extensions to subclass
|
81
|
+
def inherited(klass)
|
82
|
+
super
|
83
|
+
BigBand.applications << klass
|
84
|
+
BigBand.load_extensions(klass, *big_band_extensions)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Use Generated#name for inspection.
|
88
|
+
def inspect
|
89
|
+
name
|
90
|
+
end
|
91
|
+
|
92
|
+
# Nice output for inspect and friends:
|
93
|
+
# foo = Class.new BigBand(:SomeExtension)
|
94
|
+
# foo.name # => BigBand(:SomeExtension)
|
95
|
+
# Foo = foo
|
96
|
+
# foo.name # => Foo
|
97
|
+
def name
|
98
|
+
real_name = super
|
99
|
+
real_name.empty? ? big_band_constructor : real_name
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
extend Generated
|
105
|
+
|
106
|
+
def self.applications
|
107
|
+
@applications ||= []
|
108
|
+
end
|
109
|
+
|
110
|
+
# Extensions to load.
|
111
|
+
def self.big_band_extensions
|
112
|
+
default_extensions
|
113
|
+
end
|
114
|
+
|
115
|
+
# Generates a class for the given extensions. Note that this class is ment to be
|
116
|
+
# subclassed rather than used directly. Given extensione will only be available for
|
117
|
+
# subclasses.
|
118
|
+
#
|
119
|
+
# class Foo < BigBand.generate_class(:except => :SomeExtension)
|
120
|
+
# end
|
121
|
+
def self.generate_class(*options)
|
122
|
+
@generated_classes ||= {setify_parameters([]) => BigBand}
|
123
|
+
@generated_classes[setify_parameters(options)] ||= Class.new(Sinatra::Base) do
|
124
|
+
extend BigBand::Generated
|
125
|
+
@big_band_extensions = options
|
126
|
+
@big_band_constructor = "BigBand(#{options.map { |o| o.inspect}.join ", "})"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Adds extensions to a Sinatra application:
|
131
|
+
#
|
132
|
+
# class MyApp < Sinatra::Base
|
133
|
+
# end
|
134
|
+
#
|
135
|
+
# BigBand.load_extensions MyApp, :SomeExtension, :development => :AnotherExtension
|
136
|
+
def self.load_extensions(klass, *extensions)
|
137
|
+
extensions = default_extensions if extensions.empty?
|
138
|
+
extensions.flatten.each do |extension|
|
139
|
+
if extension.respond_to? :each_pair
|
140
|
+
extension.each_pair do |key, value|
|
141
|
+
values = [value].flatten
|
142
|
+
case key
|
143
|
+
when :production, :test, :development
|
144
|
+
klass.configure(key) { BigBand.load_extensions(klass, *values) }
|
145
|
+
when :except
|
146
|
+
exts = @nonenv_extensions.reject { |e| values.include? e }
|
147
|
+
exts << @env_extensions.inject({}) do |accepted, (env, list)|
|
148
|
+
accepted.merge env => list.reject { |e| values.include? e }
|
149
|
+
end
|
150
|
+
load_extensions(klass, *exts)
|
151
|
+
else raise ArgumentError, "unknown key #{key.inspect}"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
else
|
155
|
+
klass.register module_for(extension)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# Returns the module for a given extension identifier:
|
161
|
+
#
|
162
|
+
# BigBand.module_for :BasicExtension # => BigBand::BasicExtension
|
163
|
+
# BigBand.module_for Array # => Array
|
164
|
+
# BigBand.module_for "Foo::Bar" # => BigBand::Foo::Bar or Foo::Bar or raises an exception
|
165
|
+
def self.module_for(extension)
|
166
|
+
case extension
|
167
|
+
when Module then extension
|
168
|
+
when String then extension.split("::").inject(self) { |klass, name| klass.const_get name }
|
169
|
+
when Symbol then const_get(extension)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def self.setify_parameters(args)
|
174
|
+
case args
|
175
|
+
when Hash then args.inject({}) { |h,(k,v)| h k => setify_parameters(v) }
|
176
|
+
when Array then args.flatten.to_set
|
177
|
+
else args
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# Default extensions that will be used whenever you subclass BigBand. You can also use this to create
|
182
|
+
# your own extension collection:
|
183
|
+
#
|
184
|
+
# class MyExtensions < BigBand(:except => :ExtensionIDontLike)
|
185
|
+
# default_extension FunkyExtension, :development => DevExtension
|
186
|
+
# end
|
187
|
+
#
|
188
|
+
# Note: If given a string or symbol, it will also try to setup an autoloader:
|
189
|
+
#
|
190
|
+
# MyExtensions.default_extensions :Foo
|
191
|
+
def self.default_extensions(*extensions)
|
192
|
+
return @default_extensions if @default_extensions and extensions.empty?
|
193
|
+
@nonenv_extensions ||= []
|
194
|
+
@env_extensions ||= {:development => []}
|
195
|
+
extensions.each do |extension|
|
196
|
+
if extension.respond_to? :each_pair
|
197
|
+
extension.each_pair { |env, exts| (@env_extensions[env] ||= []).push(*exts) }
|
198
|
+
else
|
199
|
+
@nonenv_extensions.push(*extension)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
@default_extensions = [@nonenv_extensions, @env_extensions].flatten
|
203
|
+
end
|
204
|
+
|
205
|
+
def self.default_extension(name, path = nil, env = nil)
|
206
|
+
autoload name, path if path
|
207
|
+
default_extensions(env ? {env => name} : name)
|
208
|
+
end
|
209
|
+
|
210
|
+
default_extension :AdvancedRoutes, "big_band/advanced_routes"
|
211
|
+
default_extension :BasicExtensions, "big_band/basic_extensions"
|
212
|
+
default_extension :Compass, "big_band/compass"
|
213
|
+
default_extension :MoreHelpers, "big_band/more_helpers"
|
214
|
+
default_extension :MoreServer, "big_band/more_server"
|
215
|
+
default_extension :Reloader, "big_band/reloader", :development
|
216
|
+
default_extension :Sass, "big_band/sass"
|
217
|
+
default_extension :WebInspector, "big_band/web_inspector", :development
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
# Shorthand for BigBand.generate_class
|
222
|
+
def BigBand(*options)
|
223
|
+
BigBand.generate_class(*options)
|
224
|
+
end
|
225
|
+
|
226
|
+
module Sinatra
|
227
|
+
module Delegator
|
228
|
+
# Hooks into Sinatra to allow easy integration with "require 'sinatra'".
|
229
|
+
def self.included(klass)
|
230
|
+
BigBand.inherited(Sinatra::Application)
|
231
|
+
Sinatra::Application.extensions.each do |ext|
|
232
|
+
delegate(*ext.delegations) if ext.respond_to? :delegations
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
# If require "sinatra" came before require "big_band" Sinatra::Delegator.included has not been called.
|
239
|
+
Sinatra::Delegator.included(self) if is_a? Sinatra::Delegator
|
data/lib/big_bang.rb
ADDED
data/lib/yard-sinatra.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.expand_path(__FILE__ + "/../../spec_helper.rb")
|
2
|
+
|
3
|
+
describe BigBand::AdvancedRoutes do
|
4
|
+
before { app :AdvancedRoutes }
|
5
|
+
|
6
|
+
[:get, :head, :post, :put, :delete].each do |verb|
|
7
|
+
|
8
|
+
describe "HTTP #{verb.to_s.upcase}" do
|
9
|
+
|
10
|
+
describe "activation" do
|
11
|
+
|
12
|
+
it "is able to deactivate routes from the outside" do
|
13
|
+
route = define_route(verb, "/foo") { "bar" }
|
14
|
+
route.should be_active
|
15
|
+
browse_route(verb, "/foo").should be_ok
|
16
|
+
route.deactivate
|
17
|
+
route.should_not be_active
|
18
|
+
browse_route(verb, "/foo").should_not be_ok
|
19
|
+
end
|
20
|
+
|
21
|
+
it "is able to deacitvate routes from a before filter" do
|
22
|
+
route = define_route(verb, "/foo") { "bar" }
|
23
|
+
app.before { route.deactivate }
|
24
|
+
route.should be_active
|
25
|
+
browse_route(verb, "/foo").should_not be_ok
|
26
|
+
route.should_not be_active
|
27
|
+
end
|
28
|
+
|
29
|
+
it "is able to reactivate deactivated routes" do
|
30
|
+
route = define_route(verb, "/foo") { "bar" }
|
31
|
+
route.deactivate
|
32
|
+
route.activate
|
33
|
+
route.should be_active
|
34
|
+
browse_route(verb, "/foo").should be_ok
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "inspection" do
|
40
|
+
it "exposes app, path, file, verb, pattern, " do
|
41
|
+
route = define_route(verb, "/foo") { }
|
42
|
+
route.app.should == app
|
43
|
+
route.path.should == "/foo"
|
44
|
+
route.file.should == __FILE__.expand_path
|
45
|
+
route.verb.should == verb.to_s.upcase
|
46
|
+
route.pattern.should == route[0]
|
47
|
+
route.keys.should == route[1]
|
48
|
+
route.conditions.should == route[2]
|
49
|
+
route.block.should == route[3]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "promotion" do
|
54
|
+
it "preffers promoted routes over earlier defined routes" do
|
55
|
+
next if verb == :head # cannot check body for head
|
56
|
+
bar = define_route(verb, "/foo") { "bar" }
|
57
|
+
baz = define_route(verb, "/foo") { "baz" }
|
58
|
+
browse_route(verb, "/foo").body.should == "bar"
|
59
|
+
baz.promote
|
60
|
+
browse_route(verb, "/foo").body.should == "baz"
|
61
|
+
bar.promote
|
62
|
+
browse_route(verb, "/foo").body.should == "bar"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path(__FILE__ + "/../../spec_helper.rb")
|
2
|
+
|
3
|
+
describe BigBand::BasicExtensions do
|
4
|
+
|
5
|
+
before { app :BasicExtensions }
|
6
|
+
|
7
|
+
describe "set" do
|
8
|
+
|
9
|
+
it "adds hooks to Sinatra::Base#set" do
|
10
|
+
extension = Module.new
|
11
|
+
extension.should_receive(:set_foo).with(app)
|
12
|
+
extension.should_receive(:set_value).with(app, :foo)
|
13
|
+
app.register extension
|
14
|
+
app.set :foo, 42
|
15
|
+
end
|
16
|
+
|
17
|
+
it "allows passing a block" do
|
18
|
+
app.set(:foo) { 42 }
|
19
|
+
app.foo.should == 42
|
20
|
+
end
|
21
|
+
|
22
|
+
it "merges hash values" do
|
23
|
+
app.set :foo, :bar => 42
|
24
|
+
app.set :foo, :baz => 23
|
25
|
+
app.foo[:bar].should == 42
|
26
|
+
app.foo[:baz].should == 23
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "register" do
|
32
|
+
it "registers an extension only once" do
|
33
|
+
extension = Module.new
|
34
|
+
extension.should_receive(:registered).once.with(app)
|
35
|
+
10.times { app.register extension }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require File.expand_path(__FILE__ + "/../../spec_helper.rb")
|
2
|
+
|
3
|
+
describe BigBand::MoreServer do
|
4
|
+
before { app :MoreServer }
|
5
|
+
it("should offer unicorn") { app.server.should include("unicorn") }
|
6
|
+
it("should offer rainbows") { app.server.should include("rainbows") }
|
7
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(__FILE__ + "/../../spec_helper.rb")
|
2
|
+
|
3
|
+
describe BigBand::Sass do
|
4
|
+
|
5
|
+
def evaluate_sass(value)
|
6
|
+
Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new).to_s
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns the smaller value for min" do
|
10
|
+
evaluate_sass("min(10px, 20px)").should == evaluate_sass("10px")
|
11
|
+
evaluate_sass("min(50%, 10%)").should == evaluate_sass("10%")
|
12
|
+
evaluate_sass("min(42, 42)").should == evaluate_sass("42")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns the greater value for max" do
|
16
|
+
evaluate_sass("max(10px, 20px)").should == evaluate_sass("20px")
|
17
|
+
evaluate_sass("max(50%, 10%)").should == evaluate_sass("50%")
|
18
|
+
evaluate_sass("max(42, 42)").should == evaluate_sass("42")
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
$LOAD_PATH.unshift "lib"
|
2
|
+
require "lib/big_band/version"
|
3
|
+
|
4
|
+
YARD_SINATRA_SPEC = Gem::Specification.new do |s|
|
5
|
+
|
6
|
+
s.name = "yard-sinatra"
|
7
|
+
s.version = BigBand::VERSION
|
8
|
+
s.date = BigBand::DATE
|
9
|
+
s.author = "Konstantin Haase"
|
10
|
+
s.email = "konstantin.mailinglists@googlemail.com"
|
11
|
+
s.homepage = "http://github.com/rkh/big_band"
|
12
|
+
s.platform = Gem::Platform::RUBY
|
13
|
+
s.summary = "YARD plugin for parsing sinatra routes"
|
14
|
+
s.files = ["yard-sinatra.gemspec", "lib/yard-sinatra.rb", "lib/big_band/version.rb"]
|
15
|
+
s.require_paths = ['lib']
|
16
|
+
s.description = s.summary + " See README.rdoc for more infos."
|
17
|
+
s.has_rdoc = false
|
18
|
+
|
19
|
+
s.add_dependency "big_band", "= #{BigBand::VERSION}"
|
20
|
+
|
21
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
22
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
23
|
+
|
24
|
+
end
|