Module: OrangewebBootStrapHelper::ViewHelper

Defined in:
lib/orangeweb_bootstrap_helper/view_helper.rb

Overview

Extends Application Helpers

Instance Method Summary collapse

Instance Method Details

#active_inactive_label(val) ⇒ Object



191
192
193
194
195
196
197
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 191

def active_inactive_label val
  if val then
    label_success "Ativo"
  else
    label_important "Inativo"
  end    
end

#alert_block(title, alert_context = :alert, &block) ⇒ Object



205
206
207
208
209
210
211
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 205

def alert_block title, alert_context = :alert, &block  
  raw '<div class="alert alert-block alert-' + alert_context.to_s + '" >' +
      '   <a class="close" data-dismiss="alert" href="#">×</a>' +
      '   <h4 class="alert-heading">' + title + '</h4>' +
          capture(&block) +
      '</div>'  
end

#alert_inline(title, alert_context = :alert, &block) ⇒ Object



213
214
215
216
217
218
219
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 213

def alert_inline title, alert_context = :alert, &block  
  raw '<div class="alert alert-' + alert_context.to_s + '" >' +
      '   <a class="close" data-dismiss="alert" href="#">×</a>' +
      '   <strong class="alert-heading">' + title + '</strong>' +
          capture(&block) +
      '</div>'  
end

#badge_default(value) ⇒ Object



38
39
40
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 38

def badge_default value
  bootstrap_badge value, :default    
end

#badge_important(value) ⇒ Object



50
51
52
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 50

def badge_important value
  bootstrap_badge value, :important 
end

#badge_info(value) ⇒ Object



54
55
56
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 54

def badge_info value
  bootstrap_badge value, :info 
end

#badge_inverse(value) ⇒ Object



58
59
60
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 58

def badge_inverse value
  bootstrap_badge value, :inverse
end

#badge_success(value) ⇒ Object



42
43
44
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 42

def badge_success value
  bootstrap_badge value, :success   
end

#badge_warning(value) ⇒ Object



46
47
48
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 46

def badge_warning value
  bootstrap_badge value, :warning   
end

#bootstrap_badge(value, type) ⇒ Object



34
35
36
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 34

def bootstrap_badge value, type
  raw( :span, value, :class => "badge badge-#{type.to_s}")
end

#bootstrap_label(value, type) ⇒ Object



62
63
64
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 62

def bootstrap_label value, type
  raw( :span, value, :class => "label label-#{type.to_s}")
end

#button_to_cancel(title, link, opts = {}) ⇒ Object



162
163
164
165
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 162

def button_to_cancel title, link, opts={}
  opts[:class] = "btn-default"
  button_to_crud title, link, :arrow_left, :black, opts
end

#button_to_crud(title, link, ico, color, opts = {}) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 144

def button_to_crud title, link, ico, color, opts={}
  opts[:class] += " btn "
  unless opts[:small].nil? then
    opts[:class] += " btn-small "
    opts.delete(:small)
  end    
  unless opts[:mini].nil? then
    opts[:class] += " btn-mini "
    opts.delete(:mini)
  end      
  link_to raw( icon(ico.to_sym, color.to_sym) + " " + title ).to_s, link, opts
end

#button_to_delete(title, link, opts = {}) ⇒ Object

Cria um botao para novos registros



174
175
176
177
178
179
180
181
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 174

def button_to_delete title, link, opts={}
  opts = {
            method: :delete,
            data: { confirm: 'Tem certeza que deseja apagar este registro?' }
         }
  opts[:class] = "btn-danger"
  button_to_crud title, link, :trash, :white, opts
end

#button_to_edit(title, link, opts = {}) ⇒ Object



157
158
159
160
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 157

def button_to_edit title, link, opts={}
  opts[:class] = "btn-warning"
  button_to_crud title, link, :pencil, :white, opts
end

#button_to_new(title, link, opts = {}) ⇒ Object



167
168
169
170
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 167

def button_to_new title, link, opts={}
  opts[:class] = "btn-primary"
  button_to_crud title, link, :plus, :white, opts
end

#fieldset(title, &block) ⇒ Object



227
228
229
230
231
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 227

def fieldset title, &block  
  raw '<div class="form-inputs"><fieldset><legend>' + title + "</legend>" +
  capture(&block) +
  "</fieldset></div>"
end

#form_actions(form, back_url, submit_title = "Gravar", cancel_title = "Cancelar") ⇒ Object



237
238
239
240
241
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 237

def form_actions form, back_url, submit_title = "Gravar", cancel_title = "Cancelar"
  form_actions_block do
   (form.button :submit, submit_title) + " " + (link_to cancel_title, back_url)
  end
end

#form_actions_block(&block) ⇒ Object



233
234
235
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 233

def form_actions_block  &block  
  (:div, capture(&block), :class => "form-actions" )
end

#icon(ico, color = :black) ⇒ Object



27
28
29
30
31
32
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 27

def icon(ico, color = :black)
  ico = ico.to_s
  color = color.to_s
  ico.gsub!(/_/, "-")
  raw( :i, "", :class => "icon icon-#{ico} icon-#{color}")
end

#label_default(value) ⇒ Object



66
67
68
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 66

def label_default value
  bootstrap_label value, :default    
end

#label_important(value) ⇒ Object



78
79
80
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 78

def label_important value
  bootstrap_label value, :important 
end

#label_info(value) ⇒ Object



82
83
84
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 82

def label_info value
  bootstrap_label value, :info 
end

#label_inverse(value) ⇒ Object



86
87
88
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 86

def label_inverse value
  bootstrap_label value, :inverse
end

#label_success(value) ⇒ Object



70
71
72
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 70

def label_success value
  bootstrap_label value, :success   
end

#label_warning(value) ⇒ Object



74
75
76
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 74

def label_warning value
  bootstrap_label value, :warning   
end


132
133
134
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 132

def link_to_back title, link, opts={}
  link_to_cancel title, link, opts
end


115
116
117
118
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 115

def link_to_blank title, link, opts={}
  opts[:target] = :blank
  link_to raw(title + " " + icon(:share_alt)).to_s, link.to_s.delete('http://').insert(0, 'http://'), opts
end


128
129
130
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 128

def link_to_cancel title, link, opts={}
  link_to_crud title, link, :arrow_left, opts
end


120
121
122
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 120

def link_to_crud title, link, ico, opts={}
  link_to raw( icon(ico.to_sym) + " " + title ).to_s, link, opts
end


140
141
142
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 140

def link_to_delete title, link, opts={}
  link_to_crud title, link, :trash, method: :delete, data: { confirm: 'Tem certeza que deseja apagar este registro?' }
end


124
125
126
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 124

def link_to_edit title, link, opts={}
  link_to_crud title, link, :pencil, opts
end


102
103
104
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 102

def link_to_icon title, link, ico, opts={}
  link_to raw( icon(ico.to_sym) + " " + title ).to_s, link, opts
end


136
137
138
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 136

def link_to_new title, link, opts={}
  link_to_crud title, link, :plus, opts
end


106
107
108
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 106

def link_to_self link, opts={}
   link_to link, link.to_s.delete('http://').insert(0, 'http://'), opts
end


110
111
112
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 110

def link_to_self_blank link
  link_to_blank link, link
end

#page_section(title, options = {}) ⇒ Object



272
273
274
275
276
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 272

def page_section title, options = {}
  if options[:class].nil? then options[:class] = "" end
  options[:class].insert(-1, " row-fluid") 
  raw (:div, ((:h3, title) << (:br)), options)
end

#page_section_fluid(title, options = {}) ⇒ Object



266
267
268
269
270
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 266

def page_section_fluid title, options = {}
  if options[:class].nil? then options[:class] = "" end
  options[:class].insert(-1, " row-fluid") 
  raw (:div, ((:hr) << (:h3, title) << (:br)), options)
end

#popover(title, content, options = {}) ⇒ Object



90
91
92
93
94
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 90

def popover title, content, options={}
  options[:rel] = "popover"
  options[:data] = { :content => content, "original-title" => title }
  link_to icon(:info_sign), "#", options
end

#row(options = { :class => "" }, &block) ⇒ Object



243
244
245
246
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 243

def row options = { :class => "" }, &block
  options[:class].insert(-1, " row") 
  (:div, capture(&block), options)
end

#row_fluid(options = { :class => "" }, &block) ⇒ Object



248
249
250
251
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 248

def row_fluid options = { :class => "" }, &block
  options[:class].insert(-1, " row-fluid") 
  (:div, capture(&block), options)
end

#show_noticeObject



221
222
223
224
225
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 221

def show_notice
  unless notice.nil? then
    raw( :div, (alert_inline "Notificação: ", :info do (:span, notice) end), :id => "notice")        
  end    
end

#show_notifications(val) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 16

def show_notifications val
  
  out =  
  "<div class=\alert\">" <<
  "<button class=\"close\" data-dismiss=\"alert\">×</button>" <<
  "<strong>Warning!</strong> #{val}." <<
  "</div>"
  
  raw out
end

#span(cols, options = {}, &block) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 253

def span cols, options={}, &block
  offset = ""
  
  unless options[:offset].nil? then offset = " offset#{options[:offset]} " end
    
  if options[:class].nil? then options[:class] = "" end
  
  options.delete(:offset)
  
  options[:class].insert(-1, " span#{cols}" + offset) 
  (:div, capture(&block), options)
end

#toolbar(&block) ⇒ Object



199
200
201
202
203
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 199

def toolbar &block  
  raw '<div class="well">' + 
  capture(&block) +
  "</div>"
end


96
97
98
99
100
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 96

def tooltip_link title, link, tooltip, opts={}
  opts[:rel] = "tooltip"
  opts[:tooltip] = tooltip
  link_to title, link, opts
end

#yes_no_label(val) ⇒ Object



183
184
185
186
187
188
189
# File 'lib/orangeweb_bootstrap_helper/view_helper.rb', line 183

def yes_no_label val
  if val then
    label_success "Sim"
  else
    label_default "Não"
  end    
end