sinatra-bells 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +9 -0
- data/README +2 -2
- data/Rakefile +2 -2
- data/lib/sinatra/bells/helpers/controller.rb +22 -0
- data/lib/sinatra/bells/helpers/html.rb +27 -1
- data/lib/sinatra/bells/version.rb +1 -1
- data/lib/sinatra/bells.rb +16 -5
- metadata +23 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98d7abf3723618e62f1581222f4cc1cfc104b310
|
4
|
+
data.tar.gz: aae9d2fea9ccbc9a5d7e10a00920be9c20fe601d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d07e09b9fea86fbd557a73bd5c8a05bcbcb7ab819fd92572695878342a57fb19c373f8d6d5a634e6f010e507566e2ffee99645dd14dfdcbd0b422afbd1e0006
|
7
|
+
data.tar.gz: ebf36cc4c4eae35d5a21fc2388c1c7cf4ffb7a52377b7214dbef14f68217094c0f885c286db9c26fd96a232e289d1a30cab4ab3190848ce741496a0f234d46d8
|
data/ChangeLog
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
|
3
3
|
= Revision history for sinatra-bells
|
4
4
|
|
5
|
+
== 0.0.2 [2014-12-19]
|
6
|
+
|
7
|
+
* Sinatra::Bells::Helpers::Controller installs default error handlers.
|
8
|
+
* Added Sinatra::Bells::Helpers::HTML#link_to_if.
|
9
|
+
* Added Sinatra::Bells::Helpers::HTML#disabled?.
|
10
|
+
* Added Sinatra::Bells::Helpers::HTML#active?.
|
11
|
+
* Extended Sinatra::Bells#route to handle regexp paths.
|
12
|
+
* Extended Sinatra::Bells::Helpers::HTML#link_to to accept query params.
|
13
|
+
|
5
14
|
== 0.0.1 [2014-04-14]
|
6
15
|
|
7
16
|
* First release.
|
data/README
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
== VERSION
|
4
4
|
|
5
|
-
This documentation refers to sinatra-bells version 0.0.
|
5
|
+
This documentation refers to sinatra-bells version 0.0.2
|
6
6
|
|
7
7
|
|
8
8
|
== DESCRIPTION
|
@@ -12,7 +12,7 @@ Extends Sinatra[http://sinatrarb.com/] with some convenience shortcuts.
|
|
12
12
|
|
13
13
|
== LINKS
|
14
14
|
|
15
|
-
Documentation:: https://blackwinter.github.
|
15
|
+
Documentation:: https://blackwinter.github.com/sinatra-bells
|
16
16
|
Source code:: https://github.com/blackwinter/sinatra-bells
|
17
17
|
RubyGem:: https://rubygems.org/gems/sinatra-bells
|
18
18
|
|
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'lib/sinatra/bells/version'
|
2
2
|
|
3
3
|
begin
|
4
4
|
require 'hen'
|
@@ -13,7 +13,7 @@ begin
|
|
13
13
|
email: %q{jens.wille@gmail.com},
|
14
14
|
license: %q{AGPL-3.0},
|
15
15
|
homepage: :blackwinter,
|
16
|
-
dependencies:
|
16
|
+
dependencies: { sinatra: '~> 1.4' },
|
17
17
|
|
18
18
|
required_ruby_version: '>= 1.9.3'
|
19
19
|
}
|
@@ -34,8 +34,30 @@ class Sinatra::Bells
|
|
34
34
|
|
35
35
|
module Controller
|
36
36
|
|
37
|
+
def self.included(base)
|
38
|
+
error_code = Rack::Utils::HTTP_STATUS_CODES
|
39
|
+
|
40
|
+
base.class_eval {
|
41
|
+
[400, 401, 403, 404, 500].each { |code|
|
42
|
+
error(code) {
|
43
|
+
@code, @error = code, error_code[code]
|
44
|
+
render_error
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
[400, 401, 403].each { |code|
|
49
|
+
name = error_code[code].downcase.tr(' ', '_')
|
50
|
+
define_method(name) { |body = nil| error(code, body) }
|
51
|
+
}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
37
55
|
protected
|
38
56
|
|
57
|
+
def render_error
|
58
|
+
erb ''
|
59
|
+
end
|
60
|
+
|
39
61
|
def send_file(file, options = {})
|
40
62
|
options.is_a?(Hash) ? super :
|
41
63
|
File.readable?(file) ? super(file, type: options) : not_found
|
@@ -26,6 +26,8 @@
|
|
26
26
|
###############################################################################
|
27
27
|
#++
|
28
28
|
|
29
|
+
require 'cgi'
|
30
|
+
|
29
31
|
class Sinatra::Bells
|
30
32
|
|
31
33
|
module Helpers
|
@@ -36,7 +38,23 @@ class Sinatra::Bells
|
|
36
38
|
|
37
39
|
def link_to(text, *args)
|
38
40
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
39
|
-
|
41
|
+
|
42
|
+
href = uri(args.join('/'))
|
43
|
+
|
44
|
+
if params = options.delete(:params)
|
45
|
+
href << '?' << Array(params).flat_map { |key, value|
|
46
|
+
key = CGI.escape(key.to_s)
|
47
|
+
|
48
|
+
value.nil? ? key : Array(value)
|
49
|
+
.map { |val| "#{key}=#{CGI.escape(val.to_s)}" }
|
50
|
+
}.join('&')
|
51
|
+
end
|
52
|
+
|
53
|
+
_a(text, options.merge(href: href))
|
54
|
+
end
|
55
|
+
|
56
|
+
def link_to_if(condition, text, *args)
|
57
|
+
condition ? link_to(text, *args) : block_given? ? yield(text, *args) : text
|
40
58
|
end
|
41
59
|
|
42
60
|
def _tag(name, *args)
|
@@ -64,6 +82,14 @@ class Sinatra::Bells
|
|
64
82
|
_tag(:ul, *args) { |tag| list.each { |*item| tag << yield(*item) } }
|
65
83
|
end
|
66
84
|
|
85
|
+
def active?(path)
|
86
|
+
'active' if request.path_info =~ /\A#{Regexp.escape(path)}(?:\/|\?|\z)/
|
87
|
+
end
|
88
|
+
|
89
|
+
def disabled?(condition)
|
90
|
+
'disabled' unless condition
|
91
|
+
end
|
92
|
+
|
67
93
|
end
|
68
94
|
|
69
95
|
end
|
data/lib/sinatra/bells.rb
CHANGED
@@ -61,12 +61,10 @@ module Sinatra
|
|
61
61
|
template, render = render, settings.default_render
|
62
62
|
end
|
63
63
|
|
64
|
-
dot = '.' unless path.end_with?('/')
|
65
|
-
|
66
64
|
blocks = {}
|
67
65
|
|
68
|
-
render
|
69
|
-
super(verb,
|
66
|
+
type_paths(render, path) { |type_path, type, method|
|
67
|
+
super(verb, type_path, options, &blocks[type] = lambda {
|
70
68
|
content_type(type)
|
71
69
|
instance_eval(&block)
|
72
70
|
instance_eval(&method)
|
@@ -78,8 +76,21 @@ module Sinatra
|
|
78
76
|
send(settings.default_renderer, template)
|
79
77
|
}
|
80
78
|
|
79
|
+
blocks.each { |type, type_block|
|
80
|
+
super(verb, path, options.merge(provides: type), &type_block)
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
def type_paths(render, path)
|
85
|
+
path, re = path.source, path if path.is_a?(Regexp)
|
86
|
+
anchor = $& if re && path.sub!(/\\z|\$/i, '')
|
87
|
+
|
88
|
+
dot = '.' unless path.end_with?('/')
|
89
|
+
dot = Regexp.escape(dot) if dot && re
|
90
|
+
|
81
91
|
render.each { |type, method|
|
82
|
-
|
92
|
+
type_path = "#{path}#{dot}#{type}#{anchor}"
|
93
|
+
yield re ? Regexp.new(type_path, re.options) : type_path, type, method
|
83
94
|
}
|
84
95
|
end
|
85
96
|
|
metadata
CHANGED
@@ -1,43 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-bells
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Wille
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: hen
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
31
34
|
- - ">="
|
32
35
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
36
|
+
version: 0.8.1
|
34
37
|
type: :development
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.8'
|
38
44
|
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
46
|
+
version: 0.8.1
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: rake
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,13 +83,18 @@ licenses:
|
|
77
83
|
metadata: {}
|
78
84
|
post_install_message: |2+
|
79
85
|
|
80
|
-
sinatra-bells-0.0.
|
86
|
+
sinatra-bells-0.0.2 [2014-12-19]:
|
81
87
|
|
82
|
-
*
|
88
|
+
* Sinatra::Bells::Helpers::Controller installs default error handlers.
|
89
|
+
* Added Sinatra::Bells::Helpers::HTML#link_to_if.
|
90
|
+
* Added Sinatra::Bells::Helpers::HTML#disabled?.
|
91
|
+
* Added Sinatra::Bells::Helpers::HTML#active?.
|
92
|
+
* Extended Sinatra::Bells#route to handle regexp paths.
|
93
|
+
* Extended Sinatra::Bells::Helpers::HTML#link_to to accept query params.
|
83
94
|
|
84
95
|
rdoc_options:
|
85
96
|
- "--title"
|
86
|
-
- sinatra-bells Application documentation (v0.0.
|
97
|
+
- sinatra-bells Application documentation (v0.0.2)
|
87
98
|
- "--charset"
|
88
99
|
- UTF-8
|
89
100
|
- "--line-numbers"
|
@@ -104,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
115
|
version: '0'
|
105
116
|
requirements: []
|
106
117
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
118
|
+
rubygems_version: 2.4.5
|
108
119
|
signing_key:
|
109
120
|
specification_version: 4
|
110
121
|
summary: Sinatra with some more bells and whistles.
|