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_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 |
# 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 tag(:div, body, :class => 'mui') + script end |
#mui_browser ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/global_helpers.rb', line 69 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
82 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 |
# File 'app/helpers/global_helpers.rb', line 82 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
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/helpers/global_helpers.rb', line 110 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
132 133 134 135 136 |
# File 'app/helpers/global_helpers.rb', line 132 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
138 139 140 |
# File 'app/helpers/global_helpers.rb', line 138 def mui_date(name, = {}) tag(:div, date_field(name, :label => [:title]), :class => 'mui_date') end |
#mui_date_span(options = {}) ⇒ Object
142 143 144 |
# File 'app/helpers/global_helpers.rb', line 142 def mui_date_span( = {}) tag(:span, relative_date_span([[:created], [:updated]]), :class => 'mui_date') end |
#mui_delete(options = {}) ⇒ Object
146 147 148 149 150 151 |
# File 'app/helpers/global_helpers.rb', line 146 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
153 154 155 |
# File 'app/helpers/global_helpers.rb', line 153 def mui_divider self_closing_tag(:hr, :class => 'mui_divider') end |
#mui_form(name, options = {}, &block) ⇒ Object
157 158 159 |
# File 'app/helpers/global_helpers.rb', line 157 def mui_form(name, = {}, &block) form_for(name, , &block) end |
#mui_grid(options = {}, &block) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'app/helpers/global_helpers.rb', line 161 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
178 179 180 181 182 183 184 |
# File 'app/helpers/global_helpers.rb', line 178 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
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'app/helpers/global_helpers.rb', line 186 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
205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'app/helpers/global_helpers.rb', line 205 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
219 220 221 222 223 224 225 226 227 |
# File 'app/helpers/global_helpers.rb', line 219 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
229 230 231 232 233 234 235 236 237 238 239 |
# File 'app/helpers/global_helpers.rb', line 229 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
241 242 243 |
# File 'app/helpers/global_helpers.rb', line 241 def mui_paragraph(={}, &block) tag(:p, (capture(&block) if block_given?), :class => 'mui_paragraph') end |
#mui_password(name, options = {}) ⇒ Object
245 246 247 248 249 250 251 |
# File 'app/helpers/global_helpers.rb', line 245 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_path(type) ⇒ Object
253 254 255 |
# File 'app/helpers/global_helpers.rb', line 253 def mui_path(type) ::MerbUi.public_path_for type end |
#mui_search(options = {}) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'app/helpers/global_helpers.rb', line 257 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
270 271 272 |
# File 'app/helpers/global_helpers.rb', line 270 def mui_status(&block) tag(:div, capture(&block), :class => 'mui_status') end |
#mui_tab(options = {}, &block) ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'app/helpers/global_helpers.rb', line 274 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
303 304 305 306 |
# File 'app/helpers/global_helpers.rb', line 303 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
308 309 310 311 312 313 314 315 316 |
# File 'app/helpers/global_helpers.rb', line 308 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
318 319 320 321 322 323 324 |
# File 'app/helpers/global_helpers.rb', line 318 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
326 327 328 329 330 331 332 |
# File 'app/helpers/global_helpers.rb', line 326 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
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'app/helpers/global_helpers.rb', line 334 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
366 367 368 369 370 371 372 373 374 |
# File 'app/helpers/global_helpers.rb', line 366 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
376 377 378 379 380 |
# File 'app/helpers/global_helpers.rb', line 376 def mui_window_redirect url = session[:mui_referer] || '/' session.delete(:mui_referer) redirect(url) end |
#mui_window_referer ⇒ Object
382 383 384 |
# File 'app/helpers/global_helpers.rb', line 382 def mui_window_referer session[:mui_referer] = request.referer end |