twitter_bootstrap_helper 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,10 +15,8 @@ module TwitterBootstrapHelper
15
15
  # ==== Options
16
16
  # * <tt>:icon</tt> - Optionally display an icon before the name.
17
17
  # * All other options are passed through the the link_to helper.
18
- def tb_link(name, link="#", options = {})
19
- options = {
20
- icon: nil,
21
- }.merge(options)
18
+ def tb_link(name, link="#", options = nil)
19
+ options ||= {}
22
20
 
23
21
  icon = nil
24
22
  if options[:icon]
@@ -45,7 +43,7 @@ module TwitterBootstrapHelper
45
43
  class: "btn",
46
44
  icon: nil,
47
45
  type: :submit,
48
- }.merge(options)
46
+ }.merge(options || {})
49
47
 
50
48
  options = options.nil? ? default_options : default_options.merge(options)
51
49
 
@@ -67,8 +65,7 @@ module TwitterBootstrapHelper
67
65
  # ==== Options
68
66
  # * <tt>:class</tt> - Defaults to "badge", any other class specified will be appended to the "badge" class.
69
67
  def tb_badge(name, options = {})
70
- options = {
71
- }.merge(options)
68
+ options ||= {}
72
69
 
73
70
  options[:class] = "badge #{options[:class]}"
74
71
 
@@ -79,8 +76,7 @@ module TwitterBootstrapHelper
79
76
  # ==== Options
80
77
  # * <tt>:class</tt> - Defaults to "label", any other class specified will be appended to the "label" class.
81
78
  def tb_label(name, options = {})
82
- options = {
83
- }.merge(options)
79
+ options ||= {}
84
80
 
85
81
  options[:class] = "label #{options[:class]}"
86
82
 
@@ -94,11 +90,9 @@ module TwitterBootstrapHelper
94
90
  # * <tt>:badge_class</tt> - Optional badge class to add. Eg "badge-success"
95
91
  # * <tt>:active</tt> - adds the active class showing the item is selected
96
92
  def tb_sidebar_link(name, link="#", options = {})
97
- default_options = {
98
- icon: nil,
99
- badge: 0,
93
+ options = {
100
94
  active: (request.fullpath == link)
101
- }.merge(options)
95
+ }.merge(options || {})
102
96
 
103
97
  icon = nil
104
98
  li_class = []
@@ -112,24 +106,105 @@ module TwitterBootstrapHelper
112
106
  if options[:active]
113
107
  li_class << "active"
114
108
  i_class << "icon-white"
109
+ options.delete(:active)
115
110
  end
116
111
 
117
112
  i_class << icon
118
- badge = options[:badge] > 0 ? " #{tb_badge(options[:badge], :class => "pull-right #{options[:badge_class]}")}".html_safe : ""
113
+ badge = (options[:badge] || 0) > 0 ? " #{tb_badge(options[:badge], :class => "pull-right #{options[:badge_class]}")}".html_safe : ""
119
114
  icon_tag = content_tag(:i, "", :class => i_class.join(" "))
120
115
  content_tag(:li, link_to(icon_tag + name + badge, link, options), :class => li_class.empty? ? nil : li_class.join(" "))
121
116
  end
122
117
 
118
+ ## Nav Helpers
119
+
120
+ def tb_nav(nav_type = nil, content_or_options_with_block = {}, options = {}, &block)
121
+ if block_given?
122
+ options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
123
+ content = capture(&block)
124
+ else
125
+ content = content_or_options_with_block
126
+ end
127
+
128
+ options = {
129
+ :type => nil, # :tabs, :pills or :list
130
+ :stacked => false,
131
+ :dropdown_menu => false,
132
+ :html => {}
133
+ }.merge(options || {})
134
+
135
+ classes = [].tap do |c|
136
+ unless nav_type == :dropdown_menu
137
+ c << "nav"
138
+ c << "nav-#{nav_type.to_s}" unless nav_type.nil?
139
+ else
140
+ c << "dropdown-menu"
141
+ end
142
+ c << "nav-stacked" if options[:stacked]
143
+ c << options[:html][:class] if options[:html][:class]
144
+ end.join(" ")
145
+
146
+ options[:html][:class] = classes.blank? ? nil : classes
147
+ content_tag :ul, content, options[:html]
148
+ end
149
+
150
+ def tb_nav_item(content_or_options_with_block = nil, options = nil, &block)
151
+ if block_given?
152
+ options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
153
+ content = capture(&block)
154
+ else
155
+ content = content_or_options_with_block
156
+ end
157
+
158
+ options = {
159
+ :header => false,
160
+ :active => false,
161
+ :disabled => false,
162
+ :dropdown => false,
163
+ :dropdown_submenu => false,
164
+ :html => {}
165
+ }.merge(options || {})
166
+
167
+ classes = [].tap do |c|
168
+ if [:divider, :divider_vertical].include?(content)
169
+ c << content.to_s.gsub("_", "-")
170
+ content = nil
171
+ end
172
+ c << options[:html][:class] if options[:html][:class]
173
+ options.except(:html, :nav_header).each_pair do |key, value|
174
+ c << key.to_s.gsub("_", "-") if value
175
+ end
176
+ c << "nav-header" if options[:header]
177
+ end.join(" ")
178
+
179
+ options[:html][:class] = classes.blank? ? nil : classes
180
+ content = tb_dropdown_toggle(options[:dropdown]) + content if options[:dropdown]
181
+ content_tag :li, content, options[:html]
182
+ end
183
+
184
+ def tb_nav_items(items)
185
+ [].tap do |l|
186
+ items.each_pair do |title, options|
187
+ l << tb_nav_item(tb_link(title, options[:path], options[:link]), options[:nav])
188
+ end
189
+ end.join.html_safe
190
+ end
191
+
192
+ def tb_dropdown_toggle(name, options = {})
193
+ options["data-toggle"] = "dropdown"
194
+ options[:class] = "dropdown-toggle #{options[:class]}"
195
+ tb_link "#{name} <b class=\"caret\"></b>".html_safe, "#", options
196
+ end
197
+
123
198
  ## Modal Helpers
124
199
 
125
200
  # Creates a button with the given +name+ that will active a Twitter Bootstrap Modal with the id of +modal_id+.
126
201
  # ==== Options
127
202
  # * <tt>:data-toggle</tt> - Defaults to modal
128
203
  # * All other options are passed to tb_link
129
- def tb_modal_button(name, modal_id, options={})
204
+ def tb_modal_button(name, modal_id, options=nil)
130
205
  options = {
131
206
  "data-toggle" => "modal"
132
- }.merge(options)
207
+ }.merge(options || {})
133
208
 
134
209
  tb_link name, "##{modal_id}", options
135
210
  end
@@ -146,7 +221,14 @@ module TwitterBootstrapHelper
146
221
  # * <tt>:ok_link</tt> - The link for the ok button. Default: "#"
147
222
  # * <tt>:remote</tt> - (untested) The remote link for the model to get it's content
148
223
  def tb_modal(modal_id, content_or_options_with_block = nil, options = nil, &block)
149
- default_options = {
224
+ if block_given?
225
+ options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
226
+ content = capture(&block)
227
+ else
228
+ content = content_or_options_with_block
229
+ end
230
+
231
+ options = {
150
232
  title: "Alert",
151
233
  fade: true,
152
234
  cancel_label: "Cancel",
@@ -156,18 +238,9 @@ module TwitterBootstrapHelper
156
238
  ok_class: "btn btn-primary",
157
239
  ok_link: "#",
158
240
  remote: nil,
159
- }
160
-
161
- if block_given?
162
- options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
163
- content = capture(&block)
164
- else
165
- content = content_or_options_with_block
166
- end
167
-
168
- options = options.nil? ? default_options : default_options.merge(options)
241
+ }.merge(options || {})
169
242
 
170
- content_tag :div, :id => modal_id, :class => "modal hide #{ options[:fade] ? "fade" : ""}", "data-remote" => options[:remote] do
243
+ content_tag :div, :id => modal_id, :class => "modal hide #{ options[:fade] ? "fade" : ""}", "data-remote" => options[:remote] do
171
244
  [].tap do |modal|
172
245
  modal << content_tag(:div, :class => "modal-header") do
173
246
  [].tap do |header|
@@ -1,3 +1,3 @@
1
1
  module TwitterBootstrapHelper
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_bootstrap_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -71,7 +71,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
71
  version: '0'
72
72
  segments:
73
73
  - 0
74
- hash: -2840883431053187956
74
+ hash: 747899810726140837
75
75
  required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  none: false
77
77
  requirements:
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  version: '0'
81
81
  segments:
82
82
  - 0
83
- hash: -2840883431053187956
83
+ hash: 747899810726140837
84
84
  requirements: []
85
85
  rubyforge_project:
86
86
  rubygems_version: 1.8.24