Module: Merb::GlobalHelpers

Defined in:
app/helpers/global_helpers.rb

Instance Method Summary collapse

Instance Method Details

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



3
4
5
# File 'app/helpers/global_helpers.rb', line 3

def mui_bar(options = {}, &block)
  tag(:div, capture(&block), :class => 'mui_bar')
end

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



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/helpers/global_helpers.rb', line 7

def mui_block(options = {}, &block)
  attributes = {}
  attributes[:align] = options[:align] if options[:align]
  attributes[:class] = 'mui_block'
  attributes[:class] << ' mui_subtle' if options[:subtle]
  attributes[:class] << ' mui_scroll' if options[:scroll]
  attributes[:class] << ' mui_truncate' if options[:truncate]
  if options[:inline]
    tag_type = :span
  else
    tag_type = :div
  end
  if options[:height] || options[:width]
    attributes[:style] = ''
    attributes[:style] << "height:#{options[:height]};" if options[:height]
    attributes[:style] << "width:#{options[:width]};" if options[:width]
  end
  content = ''
  content << mui_title(:title => options[:title], :title_size => options[:title_size]) if options[:title]
  content << capture(&block) if block_given?
  tag(tag_type, content, attributes)
end

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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/global_helpers.rb', line 30

def mui_body(options = {}, &block)
  attributes = {}
  attributes[:class] = 'mui_desktop'
  attributes[:class] << ' mui_gallery' if controller_name == 'merb_photos/photos'
  body = ''
  body << capture(&block)
  copyright_now = Time.now.year
  copyright_then = MerbUi[:year] || copyright_now
  if copyright_now == copyright_then
    copyright_years = copyright_now
  else
    copyright_years = "#{copyright_then}-#{copyright_now}"
  end
  copyright_owner = " #{MerbUi[:owner]}" if MerbUi[:owner]
  copyright_text = "Copyright &copy; #{copyright_years}#{copyright_owner}. All rights reserved."
  copyright = tag(:div, copyright_text, :class => 'mui_copyright')
  content = tag(:div, catch_content(:for_layout) + copyright, attributes)
  if thrown_content? :mui_sidebar
    body << tag(:table, tag(:tr, tag(:td, catch_content(:mui_sidebar), :class => 'mui_sidebar') + tag(:td, content), :valign => 'top'), :class => 'mui_grid')
  else
    body << content
  end
  body << tag(:div, :class => 'mui_window_target')
  body << tag(:div, :class => 'mui_message_target')
  if session[:mui_window]
    script_window = "muiWindowOpen('#{session[:mui_window]}');"
    session.delete(:mui_window)
  end
  if session[:mui_message]
    script_message = "muiMessageOpen('#{session[:mui_message]}');"
    session.delete(:mui_message)
  end
  script = ''
  if script_window || script_message
    script << tag(:script, "$(document).ready(function(){#{script_window}#{script_message}});", :type => 'text/javascript')
  end
  body << mui_password_status if mui_password?
  tag(:div, body, :class => 'mui') + script
end

#mui_browserObject



70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/helpers/global_helpers.rb', line 70

def mui_browser
  browser = request.user_agent
  if browser.include? 'MSIE'
    'msie'
  elsif browser.include? 'Gecko/'
    'gecko'
  elsif browser.include? 'AppleWebKit'
    'webkit'
  else
    'unknown'
  end
end

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



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/helpers/global_helpers.rb', line 83

def mui_button(options = {}, &block)
  attributes = {}
  attributes[:class] = 'mui_button'
  attributes[:class] << " mui_button_#{options[:tone]}" if options[:tone]
  attributes[:class] << ' mui_click'
  attributes[:class] << "_message_#{options[:message]}" if options[:message]
  attributes[:class] << "_window_#{options[:window]}" if options[:window]
  attributes[:id] = options[:url] if options[:url]
  attributes[:name] = options[:name] if options[:name]
  if options[:title_size] || options[:width]
    attributes[:style] = ''
    attributes[:style] << "font-size:#{options[:title_size]};" if options[:title_size]
    attributes[:style] << "width:#{options[:width]};" if options[:width]
  end
  attributes[:type] = options[:submit] == true ? 'submit' : 'button'
  attributes[:value] = options[:title] if options[:title]
  if block_given?
    if options[:title]
      content = tag(:table, tag(:tr, tag(:td, capture(&block)) + tag(:td, options[:title], :width => '100%')))
    else
      content = capture(&block)
    end
    tag(:button, content, attributes)
  else
    self_closing_tag(:input, attributes)
  end
end

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



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'app/helpers/global_helpers.rb', line 111

def mui_cell(options = {}, &block)
  return unless block_given? and @mui_grid
  @mui_grid[:count] += 1
  attributes = {}
  attributes[:align] = @mui_grid[:align] || options[:align] || nil
  attributes[:nowrap] = 'nowrap' if options[:wrap] == false
  if options[:height] || options[:width] || @mui_grid[:height] || @mui_grid[:width]
    height = options[:height] || @mui_grid[:height] || nil
    width = options[:width] ||= @mui_grid[:width] || nil
    attributes[:style] = ''
    attributes[:style] << "height:#{height};" if height
    attributes[:style] << "width:#{width};" if width
  end
  attributes[:valign] = @mui_grid[:valign] || options[:valign] || nil
  html = ''
  if @mui_grid[:count] > @mui_grid[:columns]
    @mui_grid[:count] = 0
    html << close_tag(:tr) + open_tag(:tr)
  end
  html << tag(:td, capture(&block), attributes)
end

#mui_check(name, options = {}) ⇒ Object



133
134
135
136
137
# File 'app/helpers/global_helpers.rb', line 133

def mui_check(name, options = {})
  columns = tag(:td, check_box(name, :class => 'mui_check'))
  columns << tag(:td, tag(:label, options[:title]))
  tag(:table, tag(:tr, columns))
end

#mui_date(name, options = {}) ⇒ Object



139
140
141
# File 'app/helpers/global_helpers.rb', line 139

def mui_date(name, options = {})
  tag(:div, date_field(name, :label => options[:title]), :class => 'mui_date')
end

#mui_date_span(options = {}) ⇒ Object



143
144
145
# File 'app/helpers/global_helpers.rb', line 143

def mui_date_span(options = {})
  tag(:span, relative_date_span([options[:created], options[:updated]]), :class => 'mui_date')
end

#mui_delete(options = {}) ⇒ Object



147
148
149
150
151
152
# File 'app/helpers/global_helpers.rb', line 147

def mui_delete(options = {})
  attributes = {}
  attributes[:class] = 'mui_button mui_button_negative'
  attributes[:style] = "width:#{options[:width]};" if options[:width]
  delete_button(options[:url], options[:title], attributes)
end

#mui_dividerObject



154
155
156
# File 'app/helpers/global_helpers.rb', line 154

def mui_divider
  self_closing_tag(:hr, :class => 'mui_divider')
end

#mui_form(name, options = {}, &block) ⇒ Object



158
159
160
# File 'app/helpers/global_helpers.rb', line 158

def mui_form(name, options = {}, &block)
  form_for(name, options, &block)
end

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



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'app/helpers/global_helpers.rb', line 162

def mui_grid(options = {}, &block)
  return unless block_given?
  mui_grid_temp = @mui_grid if @mui_grid
  @mui_grid = {}
  @mui_grid[:align] = options[:cell_align] if options[:cell_align]
  @mui_grid[:count] = 0
  @mui_grid[:columns] = options[:columns] || 1
  @mui_grid[:valign] = options[:cell_valign] if options[:cell_valign]
  @mui_grid[:width] = options[:cell_width] if options[:cell_width]
  attributes = {}
  attributes[:class] = 'mui_grid'
  attributes[:style] = "width:#{options[:width]}" if options[:width]
  html = tag(:table, tag(:tr, capture(&block)), attributes)
  @mui_grid = mui_grid_temp if mui_grid_temp
  html
end

#mui_headObject



179
180
181
182
183
184
185
# File 'app/helpers/global_helpers.rb', line 179

def mui_head
  jquery = tag(:script, '', :src => 'http://ajax.googleapis.com/ajax/libs/jquery/1.2/jquery.min.js', :type => 'text/javascript')
  jquery_ui = tag(:script, '', :src => 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.5/jquery-ui.min.js', :type => 'text/javascript')
  require_css 'mui'
  require_js("#{mui_path :javascript}/keybinder", "#{mui_path :javascript}/main")
  jquery + jquery_ui + include_required_js + include_required_css + catch_content(:feeds)
end

#mui_image(options = {}) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'app/helpers/global_helpers.rb', line 187

def mui_image(options={})
  attributes={}
  attributes[:align] = options[:align] if options[:align]
  attributes[:class] = 'mui_image'
  attributes[:class] << ' mui_image_border' if options[:border] == true
  if options[:height] && options[:width]
    attributes[:class] << ' mui_image_rounded' if options[:rounded] == true
    attributes[:src] = "#{mui_path :image}/nil.png"
    attributes[:style] = %{background-image: url('#{options[:url]}');}
    attributes[:style] << "height: #{options[:height]}px;"
    attributes[:style] << "width: #{options[:width]}px;"
  else
    attributes[:src] = file
  end
  attributes[:class] << ' mui_photo' if options[:photo] == true
  attributes[:class] << ' mui_inline' if options[:inline] == true
  self_closing_tag(:img, attributes)
end


206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'app/helpers/global_helpers.rb', line 206

def mui_link(options={}, &block)
  attributes = {}
  attributes[:class] = 'mui_link'
  attributes[:href] = options[:url]
  if block_given?
    content = capture(&block)
    attributes[:title] = options[:title]
  else
    content = options[:title]
  end
  attributes[:style] = "font-size:#{options[:title_size]};" if options[:title_size]
  tag(:a, content, attributes)
end

#mui_list(parents = []) ⇒ Object



220
221
222
223
224
225
226
227
228
# File 'app/helpers/global_helpers.rb', line 220

def mui_list(parents = [])
  children = ''
  parents.each do |p|
    p.each do |c|
      children << tag(:li, c, :class => 'mui_list_item')
    end
  end
  tag(:ul, children, :class => 'mui_list')
end

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



230
231
232
233
234
235
236
237
238
239
240
# File 'app/helpers/global_helpers.rb', line 230

def mui_message(options = {}, &block)
  bar_content = ''
  bar_content << tag(:td, options[:title], :class => 'mui_message_title') if options[:title]
  bar_content << tag(:td, mui_button(:title => '&#215;', :message => 'close'), :class => 'mui_message_bar_end')
  bar = tag(:tr, tag(:td, tag(:table, tag(:tr, bar_content), :class => 'mui_message_bar')))
  content = tag(:tr, tag(:td, capture(&block), :class => 'mui_message_content'))
  message_attributes = {}
  message_attributes[:class] = 'mui_message'
  message_attributes[:class] << " mui_message_#{options[:tone]}" if options[:tone]
  tag(:div, tag(:table, bar + content), message_attributes)
end

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



242
243
244
# File 'app/helpers/global_helpers.rb', line 242

def mui_paragraph(options={}, &block)
  tag(:p, (capture(&block) if block_given?), :class => 'mui_paragraph')
end

#mui_password(name, options = {}) ⇒ Object



246
247
248
249
250
251
252
# File 'app/helpers/global_helpers.rb', line 246

def mui_password(name, options = {})
  attributes = {}
  attributes[:class] = 'mui_input'
  attributes[:class] << ' mui_focus' if options[:focus] == true
  attributes[:label] = options[:title]
  password_field(name, attributes)
end

#mui_password?Boolean

Returns:

  • (Boolean)


254
255
256
# File 'app/helpers/global_helpers.rb', line 254

def mui_password?
  session[:mui_password_id] ? true : false
end

#mui_password_statusObject



258
259
260
261
262
# File 'app/helpers/global_helpers.rb', line 258

def mui_password_status
  update_button = mui_button(:title => 'Update Password', :title_size => '0.75em', :url => url(:merb_words_password_update), :window => 'open')
  exit_button = mui_button(:title => 'Exit', :title_size => '0.75em', :tone => 'positive', :url => url(:merb_words_password_exit))
  mui_status{"#{update_button} #{exit_button}"}
end

#mui_path(type) ⇒ Object



264
265
266
# File 'app/helpers/global_helpers.rb', line 264

def mui_path(type)
  ::MerbUi.public_path_for type
end

#mui_search(options = {}) ⇒ Object



268
269
270
271
272
273
274
275
276
277
278
279
# File 'app/helpers/global_helpers.rb', line 268

def mui_search(options = {})
  attributes = {}
  attributes[:class] = 'mui_input mui_search'
  attributes[:class] << ' mui_focus' if options[:focus] == true
  attributes[:name] = :q
  attributes[:style] = "width:#{options[:width]};" if options[:width]
  attributes[:type] = :text
  attributes[:value] = @query if @query
  inputs = self_closing_tag(:input, attributes) + mui_button(:submit => true, :title => 'Search')
  form = tag(:form, inputs, :action => options[:action])
  mui_block(:inline => true){form}
end

#mui_status(&block) ⇒ Object



281
282
283
# File 'app/helpers/global_helpers.rb', line 281

def mui_status(&block)
  tag(:div, capture(&block), :class => 'mui_status')
end

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



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'app/helpers/global_helpers.rb', line 285

def mui_tab(options = {}, &block)
  attributes = {}
  if type = options[:type]
    if type == 'merb_words'
      controller = 'merb_words/pages'
      attributes[:value] = options[:title] || MerbWords[:title] || 'Untitled'
      attributes[:id] = options[:url] || url(:merb_words_index)
    elsif type == 'merb_photos'
      controller = 'merb_photos/photos'
      attributes[:value] = options[:title] || MerbPhotos[:title] || 'Untitled'
      attributes[:id] = options[:url] || url(:merb_photos_index)
    end
  else
    controller = options[:controller] || 'application'
    attributes[:value] = options[:title] || 'Untitled'
    attributes[:id] = options[:url] || '/'
  end
  attributes[:class] = 'mui_tab'
  attributes[:class] << ' mui_selected' if controller == controller_name || options[:selected] == true
  attributes[:class] << ' mui_click'
  if options[:width]
    attributes[:style] = "width:#{options[:width]}"
  elsif @@mui_tab_width
    attributes[:style] = "width:#{@@mui_tab_width}"
  end
  attributes[:type] = 'button'
  self_closing_tag(:input, attributes)
end

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



314
315
316
317
# File 'app/helpers/global_helpers.rb', line 314

def mui_tab_group(options = {}, &block)
  @@mui_tab_width = options[:tab_width] if options[:tab_width]
  tag(:span, capture(&block), :class => 'mui_tab_group')
end

#mui_text(name, options = {}) ⇒ Object



319
320
321
322
323
324
325
326
327
# File 'app/helpers/global_helpers.rb', line 319

def mui_text(name, options = {})
  attributes = {}
  attributes[:class] = 'mui_input'
  attributes[:class] << ' mui_focus' if options[:focus] == true
  attributes[:label] = options[:title]
  attributes[:maxlength] = options[:length] || 50
  attributes[:style] = "width:#{options[:width]};" if options[:width]
  text_field(name, attributes)
end

#mui_textarea(name, options = {}) ⇒ Object



329
330
331
332
333
334
335
# File 'app/helpers/global_helpers.rb', line 329

def mui_textarea(name, options = {})
  attributes = {}
  attributes[:class] = 'mui_textarea'
  attributes[:class] << ' mui_focus' if options[:focus] == true
  attributes[:label] = options[:title]
  text_area(name, attributes)
end

#mui_title(options = {}) ⇒ Object



337
338
339
340
341
342
343
# File 'app/helpers/global_helpers.rb', line 337

def mui_title(options = {})
  size = options[:title_size] || '1.5em'
  attributes = {}
  attributes[:class] = 'mui_title'
  attributes[:style] = "font-size:#{size}"
  tag(:div, options[:title], attributes)
end

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



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'app/helpers/global_helpers.rb', line 345

def mui_tray(options = {}, &block)
  attributes = {}
  attributes[:align] = options[:align] if options[:align]
  attributes[:class] = 'mui_tray'
  if options[:inline]
    tag_type = :span
  else
    tag_type = :div
  end
  if options[:height] || options[:width]
    attributes[:style] = ''
    attributes[:style] << "height:#{options[:height]};" if options[:height]
    attributes[:style] << "width:#{options[:width]};" if options[:width]
  end
  content = ''
  if options[:title]
    title_attributes = {}
    title_attributes[:class] = 'mui_tray_title mui_truncate'
    if options[:title_url]
      title_attributes[:class] << ' mui_link'
      title_attributes[:href] = options[:title_url]
      title_attributes[:title] = options[:title].gsub(/<\/?[^>]*>/, '')
      title_type = :a
    else
      title_type = :div
    end
    content << tag(title_type, options[:title], title_attributes)
  end
  content << capture(&block) if block_given?
  tag(tag_type, content, attributes)
end

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



377
378
379
380
381
382
383
384
385
# File 'app/helpers/global_helpers.rb', line 377

def mui_window(options = {}, &block)
  bar_content = ''
  bar_content << tag(:td, options[:buttons], :class => 'mui_bar_buttons') if options[:buttons]
  bar_content << tag(:td, options[:title], :class => 'mui_window_title') if options[:title]
  bar_content << tag(:td, mui_button(:title => '&#215;', :window => 'close'), :class => 'mui_window_bar_end')
  bar = tag(:tr, tag(:td, tag(:table, tag(:tr, bar_content), :class => 'mui_window_bar')))
  content = tag(:tr, tag(:td, capture(&block), :class => 'mui_window_content'))
  tag(:table, bar + content, :class => 'mui_window')
end

#mui_window_redirectObject



387
388
389
390
391
# File 'app/helpers/global_helpers.rb', line 387

def mui_window_redirect
  url = session[:mui_referer] || '/'
  session.delete(:mui_referer)
  redirect(url)
end

#mui_window_refererObject



393
394
395
# File 'app/helpers/global_helpers.rb', line 393

def mui_window_referer
  session[:mui_referer] = request.referer
end