sinatra-bells 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98d7abf3723618e62f1581222f4cc1cfc104b310
4
- data.tar.gz: aae9d2fea9ccbc9a5d7e10a00920be9c20fe601d
3
+ metadata.gz: 53f2b23d0ae7f154e44a3e397757c6f7a2046db7
4
+ data.tar.gz: 61e1dc3ca04412604688581b82a14e9a81309db1
5
5
  SHA512:
6
- metadata.gz: 0d07e09b9fea86fbd557a73bd5c8a05bcbcb7ab819fd92572695878342a57fb19c373f8d6d5a634e6f010e507566e2ffee99645dd14dfdcbd0b422afbd1e0006
7
- data.tar.gz: ebf36cc4c4eae35d5a21fc2388c1c7cf4ffb7a52377b7214dbef14f68217094c0f885c286db9c26fd96a232e289d1a30cab4ab3190848ce741496a0f234d46d8
6
+ metadata.gz: 0f1c43831f29db9ebc8d591a1d375b79be25e1698be93fa127c47755eee98657b639d1ca90030b01fce0ec0b8b54fcd327f7006126ed04a8913b5480fab1b78c
7
+ data.tar.gz: f4e93040f59afa2e9fb4aa863db1d7f88e4ba24ed642844b3f18aa891f372a13ad76092be52fe4635a5b0ea27c478dde0171171e90557dd73a1013c98e260b22
data/ChangeLog CHANGED
@@ -2,13 +2,20 @@
2
2
 
3
3
  = Revision history for sinatra-bells
4
4
 
5
+ == 0.0.3 [2015-02-11]
6
+
7
+ * Renamed Sinatra::Bells::Helpers::HTML to Sinatra::Bells::Helpers::View.
8
+ * Extended Sinatra::Bells::Helpers::View#link_to to accept an anchor.
9
+ * Added Sinatra::Bells::Helpers::View#format_label.
10
+ * Added Sinatra::Bells.set_hash.
11
+
5
12
  == 0.0.2 [2014-12-19]
6
13
 
7
14
  * Sinatra::Bells::Helpers::Controller installs default error handlers.
8
15
  * Added Sinatra::Bells::Helpers::HTML#link_to_if.
9
16
  * Added Sinatra::Bells::Helpers::HTML#disabled?.
10
17
  * Added Sinatra::Bells::Helpers::HTML#active?.
11
- * Extended Sinatra::Bells#route to handle regexp paths.
18
+ * Extended Sinatra::Bells.route to handle regexp paths.
12
19
  * Extended Sinatra::Bells::Helpers::HTML#link_to to accept query params.
13
20
 
14
21
  == 0.0.1 [2014-04-14]
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to sinatra-bells version 0.0.2
5
+ This documentation refers to sinatra-bells version 0.0.3
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -24,7 +24,7 @@ RubyGem:: https://rubygems.org/gems/sinatra-bells
24
24
 
25
25
  == LICENSE AND COPYRIGHT
26
26
 
27
- Copyright (C) 2014 Jens Wille
27
+ Copyright (C) 2014-2015 Jens Wille
28
28
 
29
29
  sinatra-bells is free software: you can redistribute it and/or modify it
30
30
  under the terms of the GNU Affero General Public License as published by
@@ -5,7 +5,7 @@
5
5
  # #
6
6
  # sinatra-bells -- Sinatra with some more bells and whistles #
7
7
  # #
8
- # Copyright (C) 2014 Jens Wille #
8
+ # Copyright (C) 2014-2015 Jens Wille #
9
9
  # #
10
10
  # Authors: #
11
11
  # Jens Wille <jens.wille@gmail.com> #
@@ -32,7 +32,19 @@ class Sinatra::Bells
32
32
 
33
33
  module Helpers
34
34
 
35
- module HTML
35
+ module View
36
+
37
+ LABEL_FORMAT_RE = %r{
38
+ \{
39
+ ( \w+ ) # field
40
+ (?: \( ( .*? ) \) )? # separator
41
+ (?: : ( .*? ) )? # format string
42
+ \}
43
+ }x.freeze
44
+
45
+ DEFAULT_FORMAT = '%s'.freeze
46
+
47
+ DEFAULT_SEPARATOR = '; '.freeze
36
48
 
37
49
  protected
38
50
 
@@ -50,6 +62,10 @@ class Sinatra::Bells
50
62
  }.join('&')
51
63
  end
52
64
 
65
+ if anchor = options.delete(:anchor)
66
+ href << '#' << CGI.escape(anchor.to_s)
67
+ end
68
+
53
69
  _a(text, options.merge(href: href))
54
70
  end
55
71
 
@@ -90,6 +106,18 @@ class Sinatra::Bells
90
106
  'disabled' unless condition
91
107
  end
92
108
 
109
+ def format_label(label, hash = nil, &block)
110
+ hash ||= block
111
+
112
+ label.gsub(LABEL_FORMAT_RE) {
113
+ field, separator, format =
114
+ $1, $2 || DEFAULT_SEPARATOR, $3 || DEFAULT_FORMAT
115
+
116
+ value = Array(hash[field]).map(&:to_s).delete_if(&:empty?)
117
+ format % [value.join(separator), field] unless value.empty?
118
+ }
119
+ end
120
+
93
121
  end
94
122
 
95
123
  end
@@ -5,7 +5,7 @@
5
5
  # #
6
6
  # sinatra-bells -- Sinatra with some more bells and whistles #
7
7
  # #
8
- # Copyright (C) 2014 Jens Wille #
8
+ # Copyright (C) 2014-2015 Jens Wille #
9
9
  # #
10
10
  # Authors: #
11
11
  # Jens Wille <jens.wille@gmail.com> #
@@ -27,7 +27,7 @@
27
27
  #++
28
28
 
29
29
  require_relative 'helpers/controller'
30
- require_relative 'helpers/html'
30
+ require_relative 'helpers/view'
31
31
 
32
32
  class Sinatra::Bells
33
33
  helpers ERB::Util, *Helpers.constants.map { |mod| Helpers.const_get(mod) }
@@ -6,7 +6,7 @@ module Sinatra
6
6
 
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
- TINY = 2
9
+ TINY = 3
10
10
 
11
11
  class << self
12
12
 
data/lib/sinatra/bells.rb CHANGED
@@ -46,6 +46,12 @@ module Sinatra
46
46
  super(option, *args, &nil)
47
47
  end
48
48
 
49
+ def set_hash(opt, ary, suf = nil, &block)
50
+ (a, b = suf; ary.map! { |i| %W[#{i}#{a} #{i}#{b}] }) if suf
51
+ ary.map!(&block) if block
52
+ set(opt, Hash[ary])
53
+ end
54
+
49
55
  def set_root(file)
50
56
  set(:root, file.chomp(File.extname(file)))
51
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-bells
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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-12-19 00:00:00.000000000 Z
11
+ date: 2015-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -75,7 +75,7 @@ files:
75
75
  - lib/sinatra/bells.rb
76
76
  - lib/sinatra/bells/helpers.rb
77
77
  - lib/sinatra/bells/helpers/controller.rb
78
- - lib/sinatra/bells/helpers/html.rb
78
+ - lib/sinatra/bells/helpers/view.rb
79
79
  - lib/sinatra/bells/version.rb
80
80
  homepage: http://github.com/blackwinter/sinatra-bells
81
81
  licenses:
@@ -83,18 +83,16 @@ licenses:
83
83
  metadata: {}
84
84
  post_install_message: |2+
85
85
 
86
- sinatra-bells-0.0.2 [2014-12-19]:
86
+ sinatra-bells-0.0.3 [2015-02-11]:
87
87
 
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.
88
+ * Renamed Sinatra::Bells::Helpers::HTML to Sinatra::Bells::Helpers::View.
89
+ * Extended Sinatra::Bells::Helpers::View#link_to to accept an anchor.
90
+ * Added Sinatra::Bells::Helpers::View#format_label.
91
+ * Added Sinatra::Bells.set_hash.
94
92
 
95
93
  rdoc_options:
96
94
  - "--title"
97
- - sinatra-bells Application documentation (v0.0.2)
95
+ - sinatra-bells Application documentation (v0.0.3)
98
96
  - "--charset"
99
97
  - UTF-8
100
98
  - "--line-numbers"