Module: Merb::GlobalHelpers
- Defined in:
- app/helpers/global_helpers.rb
Instance Method Summary collapse
- #mui_bar(options = {}, &block) ⇒ Object
- #mui_block(options = {}, &block) ⇒ Object
- #mui_body(options = {}, &block) ⇒ Object
- #mui_browser ⇒ Object
- #mui_button(options = {}, &block) ⇒ Object
- #mui_cell(options = {}, &block) ⇒ Object
- #mui_check(name, options = {}) ⇒ Object
- #mui_date(name, options = {}) ⇒ Object
- #mui_date_span(options = {}) ⇒ Object
- #mui_delete(options = {}) ⇒ Object
- #mui_divider ⇒ Object
- #mui_form(name, options = {}, &block) ⇒ Object
- #mui_grid(options = {}, &block) ⇒ Object
- #mui_head ⇒ Object
- #mui_image(options = {}) ⇒ Object
- #mui_link(options = {}, &block) ⇒ Object
- #mui_list(parents = []) ⇒ Object
- #mui_message(options = {}, &block) ⇒ Object
- #mui_paragraph(options = {}, &block) ⇒ Object
- #mui_password(name, options = {}) ⇒ Object
- #mui_password? ⇒ Boolean
- #mui_password_status ⇒ Object
- #mui_path(type) ⇒ Object
- #mui_search(options = {}) ⇒ Object
- #mui_status(&block) ⇒ Object
- #mui_tab(options = {}, &block) ⇒ Object
- #mui_tab_group(options = {}, &block) ⇒ Object
- #mui_text(name, options = {}) ⇒ Object
- #mui_textarea(name, options = {}) ⇒ Object
- #mui_title(options = {}) ⇒ Object
- #mui_tray(options = {}, &block) ⇒ Object
- #mui_window(options = {}, &block) ⇒ Object
- #mui_window_redirect ⇒ Object
- #mui_window_referer ⇒ Object
Instance Method Details
#mui_bar(options = {}, &block) ⇒ Object
3 4 5 |
# File 'app/helpers/global_helpers.rb', line 3 def ( = {}, &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( = {}, &block) attributes = {} attributes[:align] = [:align] if [:align] attributes[:class] = 'mui_block' attributes[:class] << ' mui_subtle' if [:subtle] attributes[:class] << ' mui_scroll' if [:scroll] attributes[:class] << ' mui_truncate' if [:truncate] if [:inline] tag_type = :span else tag_type = :div end if [:height] || [:width] attributes[:style] = '' attributes[:style] << "height:#{options[:height]};" if [:height] attributes[:style] << "width:#{options[:width]};" if [:width] end content = '' content << mui_title(:title => [:title], :title_size => [:title_size]) if [: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( = {}, &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 © #{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? : 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] = "muiMessageOpen('#{session[:mui_message]}');" session.delete(:mui_message) end script = '' if script_window || 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_browser ⇒ Object
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 ( = {}, &block) attributes = {} attributes[:class] = 'mui_button' attributes[:class] << " mui_button_#{options[:tone]}" if [:tone] attributes[:class] << ' mui_click' attributes[:class] << "_message_#{options[:message]}" if [:message] attributes[:class] << "_window_#{options[:window]}" if [:window] attributes[:id] = [:url] if [:url] attributes[:name] = [:name] if [:name] if [:title_size] || [:width] attributes[:style] = '' attributes[:style] << "font-size:#{options[:title_size]};" if [:title_size] attributes[:style] << "width:#{options[:width]};" if [:width] end attributes[:type] = [:submit] == true ? 'submit' : 'button' attributes[:value] = [:title] if [:title] if block_given? if [:title] content = tag(:table, tag(:tr, tag(:td, capture(&block)) + tag(:td, [: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( = {}, &block) return unless block_given? and @mui_grid @mui_grid[:count] += 1 attributes = {} attributes[:align] = @mui_grid[:align] || [:align] || nil attributes[:nowrap] = 'nowrap' if [:wrap] == false if [:height] || [:width] || @mui_grid[:height] || @mui_grid[:width] height = [:height] || @mui_grid[:height] || nil width = [: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] || [: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, = {}) columns = tag(:td, check_box(name, :class => 'mui_check')) columns << tag(:td, tag(:label, [: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, = {}) tag(:div, date_field(name, :label => [: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( = {}) tag(:span, relative_date_span([[:created], [: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( = {}) attributes = {} attributes[:class] = 'mui_button mui_button_negative' attributes[:style] = "width:#{options[:width]};" if [:width] ([:url], [:title], attributes) end |
#mui_divider ⇒ Object
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, = {}, &block) form_for(name, , &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( = {}, &block) return unless block_given? mui_grid_temp = @mui_grid if @mui_grid @mui_grid = {} @mui_grid[:align] = [:cell_align] if [:cell_align] @mui_grid[:count] = 0 @mui_grid[:columns] = [:columns] || 1 @mui_grid[:valign] = [:cell_valign] if [:cell_valign] @mui_grid[:width] = [:cell_width] if [:cell_width] attributes = {} attributes[:class] = 'mui_grid' attributes[:style] = "width:#{options[:width]}" if [:width] html = tag(:table, tag(:tr, capture(&block)), attributes) @mui_grid = mui_grid_temp if mui_grid_temp html end |
#mui_head ⇒ Object
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(={}) attributes={} attributes[:align] = [:align] if [:align] attributes[:class] = 'mui_image' attributes[:class] << ' mui_image_border' if [:border] == true if [:height] && [:width] attributes[:class] << ' mui_image_rounded' if [: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 [:photo] == true attributes[:class] << ' mui_inline' if [:inline] == true self_closing_tag(:img, attributes) end |
#mui_link(options = {}, &block) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'app/helpers/global_helpers.rb', line 206 def mui_link(={}, &block) attributes = {} attributes[:class] = 'mui_link' attributes[:href] = [:url] if block_given? content = capture(&block) attributes[:title] = [:title] else content = [:title] end attributes[:style] = "font-size:#{options[:title_size]};" if [: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 ( = {}, &block) = '' << tag(:td, [:title], :class => 'mui_message_title') if [:title] << tag(:td, (:title => '×', :message => 'close'), :class => 'mui_message_bar_end') = tag(:tr, tag(:td, tag(:table, tag(:tr, ), :class => 'mui_message_bar'))) content = tag(:tr, tag(:td, capture(&block), :class => 'mui_message_content')) = {} [:class] = 'mui_message' [:class] << " mui_message_#{options[:tone]}" if [:tone] tag(:div, tag(:table, + content), ) end |
#mui_paragraph(options = {}, &block) ⇒ Object
242 243 244 |
# File 'app/helpers/global_helpers.rb', line 242 def mui_paragraph(={}, &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, = {}) attributes = {} attributes[:class] = 'mui_input' attributes[:class] << ' mui_focus' if [:focus] == true attributes[:label] = [:title] password_field(name, attributes) end |
#mui_password? ⇒ Boolean
254 255 256 |
# File 'app/helpers/global_helpers.rb', line 254 def mui_password? session[:mui_password_id] ? true : false end |
#mui_password_status ⇒ Object
258 259 260 261 262 |
# File 'app/helpers/global_helpers.rb', line 258 def mui_password_status = (:title => 'Update Password', :title_size => '0.75em', :url => url(:merb_words_password_update), :window => 'open') = (: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( = {}) attributes = {} attributes[:class] = 'mui_input mui_search' attributes[:class] << ' mui_focus' if [:focus] == true attributes[:name] = :q attributes[:style] = "width:#{options[:width]};" if [:width] attributes[:type] = :text attributes[:value] = @query if @query inputs = self_closing_tag(:input, attributes) + (:submit => true, :title => 'Search') form = tag(:form, inputs, :action => [: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( = {}, &block) attributes = {} if type = [:type] if type == 'merb_words' controller = 'merb_words/pages' attributes[:value] = [:title] || MerbWords[:title] || 'Untitled' attributes[:id] = [:url] || url(:merb_words_index) elsif type == 'merb_photos' controller = 'merb_photos/photos' attributes[:value] = [:title] || MerbPhotos[:title] || 'Untitled' attributes[:id] = [:url] || url(:merb_photos_index) end else controller = [:controller] || 'application' attributes[:value] = [:title] || 'Untitled' attributes[:id] = [:url] || '/' end attributes[:class] = 'mui_tab' attributes[:class] << ' mui_selected' if controller == controller_name || [:selected] == true attributes[:class] << ' mui_click' if [: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( = {}, &block) @@mui_tab_width = [:tab_width] if [: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, = {}) attributes = {} attributes[:class] = 'mui_input' attributes[:class] << ' mui_focus' if [:focus] == true attributes[:label] = [:title] attributes[:maxlength] = [:length] || 50 attributes[:style] = "width:#{options[:width]};" if [: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, = {}) attributes = {} attributes[:class] = 'mui_textarea' attributes[:class] << ' mui_focus' if [:focus] == true attributes[:label] = [: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( = {}) size = [:title_size] || '1.5em' attributes = {} attributes[:class] = 'mui_title' attributes[:style] = "font-size:#{size}" tag(:div, [: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( = {}, &block) attributes = {} attributes[:align] = [:align] if [:align] attributes[:class] = 'mui_tray' if [:inline] tag_type = :span else tag_type = :div end if [:height] || [:width] attributes[:style] = '' attributes[:style] << "height:#{options[:height]};" if [:height] attributes[:style] << "width:#{options[:width]};" if [:width] end content = '' if [:title] title_attributes = {} title_attributes[:class] = 'mui_tray_title mui_truncate' if [:title_url] title_attributes[:class] << ' mui_link' title_attributes[:href] = [:title_url] title_attributes[:title] = [:title].gsub(/<\/?[^>]*>/, '') title_type = :a else title_type = :div end content << tag(title_type, [: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( = {}, &block) = '' << tag(:td, [:buttons], :class => 'mui_bar_buttons') if [:buttons] << tag(:td, [:title], :class => 'mui_window_title') if [:title] << tag(:td, (:title => '×', :window => 'close'), :class => 'mui_window_bar_end') = tag(:tr, tag(:td, tag(:table, tag(:tr, ), :class => 'mui_window_bar'))) content = tag(:tr, tag(:td, capture(&block), :class => 'mui_window_content')) tag(:table, + content, :class => 'mui_window') end |
#mui_window_redirect ⇒ Object
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_referer ⇒ Object
393 394 395 |
# File 'app/helpers/global_helpers.rb', line 393 def mui_window_referer session[:mui_referer] = request.referer end |