sinatra-bells 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57016c69fd1b998d1323cc40e5437050f5c8671e
4
- data.tar.gz: 47519eea26151cc039ef97fb96204175051f3fe9
3
+ metadata.gz: f48f7ee9c1145221ed496d9b54c6e491b8d1f970
4
+ data.tar.gz: 368bf27da21c3a1f6cca9c27a161480464680c25
5
5
  SHA512:
6
- metadata.gz: 8e90aa46fbd00e900a62a91ab25eb3e39e0faa9fc3b72cd323a55a18346a4571afc66ba0b23f203b0d539bbe676df3f954458644d5d183483bdea726601918fe
7
- data.tar.gz: cdd04af5f6571dcb581e9f2eb7fa61df1d468e294bcd8fd3e80c35c96178c151fd58950910f75125aec14f2513ec079202fa655847ce9165140e32b81bae68bb
6
+ metadata.gz: f551cba21b9e5a3d3b5108f60b5f2e676ce606b0326c82b0276e50180f0911c1b947dc4a9a08028e45b531912928aa9af538fe3ae00ed361d1e422d97e1d7b50
7
+ data.tar.gz: 276ab6664c6bc8fc35f2479d59dc9d78043fbe5659ece2ed011017d6e5d1ca717ac19bd852427984bf76b87c26f872fe00ec635c6594397fec8e495657376abd
data/ChangeLog CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  = Revision history for sinatra-bells
4
4
 
5
+ == 0.2.0 [2015-11-18]
6
+
7
+ * Added shortcuts for all HTML elements to Sinatra::Bells::Helpers::View.
8
+ * Added Sinatra::Bells.set_defer.
9
+ * Added Sinatra::Bells.set_async.
10
+
5
11
  == 0.1.0 [2015-10-02]
6
12
 
7
13
  * Changed Sinatra::Bells::Helpers::View method names from <tt>_<tag></tt> to
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to sinatra-bells version 0.1.0
5
+ This documentation refers to sinatra-bells version 0.2.0
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -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> #
@@ -35,15 +35,18 @@ module Sinatra
35
35
  class << self
36
36
 
37
37
  def set(option, *args, &block)
38
- if block
39
- args[0] = lambda {
40
- value = instance_eval(&block)
41
- set(option, value)
42
- value
43
- }
44
- end
38
+ block ? !args.empty? ?
39
+ raise(ArgumentError, 'both block and arguments given') :
40
+ set_defer(option, &block) : super(option, *args, &nil)
41
+ end
42
+
43
+ def set_defer(option, &block)
44
+ set(option, lambda { set(option, value = instance_eval(&block)); value })
45
+ end
45
46
 
46
- super(option, *args, &nil)
47
+ def set_async(option, &block)
48
+ thread = Thread.new(&block)
49
+ set_defer(option) { thread.value }
47
50
  end
48
51
 
49
52
  def set_hash(opt, ary, suf = nil, &block)
@@ -46,6 +46,52 @@ class Sinatra::Bells
46
46
 
47
47
  DEFAULT_SEPARATOR = '; '.freeze
48
48
 
49
+ HTML_ELEMENTS = %w[
50
+ a abbr address area article aside audio b base bdi bdo blockquote body
51
+ br button canvas caption cite code col colgroup command content datalist
52
+ decorator del details dfn dialog div dl element em embed fieldset
53
+ figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hr html i
54
+ iframe img input ins kbd keygen label legend li link main map mark math
55
+ menu menuitem meta meter nav noscript object optgroup option output p
56
+ param picture pre progress q rp rt ruby s samp script section select
57
+ shadow small source span strong style sub summary sup svg table tbody td
58
+ template textarea tfoot th thead time title tr track u var video wbr
59
+ ].freeze
60
+
61
+ LIST_ELEMENTS = %w[ol ul].freeze
62
+
63
+ class << self
64
+
65
+ def define_html_tag_method(*names)
66
+ names.each { |name|
67
+ class_eval <<-EOT, __FILE__, __LINE__ + 1
68
+ def #{name}_(*args, &block)
69
+ tag_(#{name.inspect}, *args, &block)
70
+ end
71
+ EOT
72
+ }
73
+ end
74
+
75
+ def define_list_tag_method(*names)
76
+ names.each { |name|
77
+ class_eval <<-EOT, __FILE__, __LINE__ + 1
78
+ def #{name}_(*args, &block)
79
+ if args.first.respond_to?(:each)
80
+ raise ArgumentError, 'no block given' unless block
81
+
82
+ list, block_, block = args.shift, block, lambda { |tag|
83
+ list.each { |*item| tag << li_(*block_[*item]) }
84
+ }
85
+ end
86
+
87
+ tag_(#{name.inspect}, *args, &block)
88
+ end
89
+ EOT
90
+ }
91
+ end
92
+
93
+ end
94
+
49
95
  protected
50
96
 
51
97
  def link_to(text, *args)
@@ -86,17 +132,8 @@ class Sinatra::Bells
86
132
  args.push('</', name, '>').join
87
133
  end
88
134
 
89
- def a_(*args)
90
- tag_(:a, *args)
91
- end
92
-
93
- def li_(*args)
94
- tag_(:li, *args)
95
- end
96
-
97
- def ul_(list, *args)
98
- tag_(:ul, *args) { |tag| list.each { |*item| tag << yield(*item) } }
99
- end
135
+ define_html_tag_method(*HTML_ELEMENTS)
136
+ define_list_tag_method(*LIST_ELEMENTS)
100
137
 
101
138
  def active?(path)
102
139
  'active' if request.path_info =~ /\A#{Regexp.escape(path)}(?:\/|\?|\z)/
@@ -5,7 +5,7 @@ module Sinatra
5
5
  module Version
6
6
 
7
7
  MAJOR = 0
8
- MINOR = 1
8
+ MINOR = 2
9
9
  TINY = 0
10
10
 
11
11
  class << self
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-02 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -83,14 +83,15 @@ licenses:
83
83
  metadata: {}
84
84
  post_install_message: |2+
85
85
 
86
- sinatra-bells-0.1.0 [2015-10-02]:
86
+ sinatra-bells-0.2.0 [2015-11-18]:
87
87
 
88
- * Changed Sinatra::Bells::Helpers::View method names from <tt>_<tag></tt> to
89
- <tt><tag>_</tt>.
88
+ * Added shortcuts for all HTML elements to Sinatra::Bells::Helpers::View.
89
+ * Added Sinatra::Bells.set_defer.
90
+ * Added Sinatra::Bells.set_async.
90
91
 
91
92
  rdoc_options:
92
93
  - "--title"
93
- - sinatra-bells Application documentation (v0.1.0)
94
+ - sinatra-bells Application documentation (v0.2.0)
94
95
  - "--charset"
95
96
  - UTF-8
96
97
  - "--line-numbers"
@@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  requirements: []
113
114
  rubyforge_project:
114
- rubygems_version: 2.4.8
115
+ rubygems_version: 2.5.0
115
116
  signing_key:
116
117
  specification_version: 4
117
118
  summary: Sinatra with some more bells and whistles.