Module: RightRails::Helpers::Misc
- Defined in:
- lib/right_rails/helpers/misc.rb
Overview
Misc view helpers for RightJS
Instance Method Summary collapse
-
#autocomplete_result(entries, *args) ⇒ Object
(also: #autocompleter_result)
the autocompletion list result.
-
#flashes ⇒ Object
Just a simple flashes generator, might be replaced in the application.
-
#link_to_lightbox(name, url = {}, options = {}, &block) ⇒ Object
Generates a link that whil load the refered address in a lightbox.
-
#resizable(options = {}, &block) ⇒ Object
The resizable unit helper.
- #tab(title, options = {}, &block) ⇒ Object
-
#tabs(options = {}, &block) ⇒ Object
Tabs container generator.
Instance Method Details
#autocomplete_result(entries, *args) ⇒ Object Also known as: autocompleter_result
the autocompletion list result
USAGE:
it might work in several ways
autocomplete_result(list_of_strings)
autocomplete_result(list_of_strings, :highlight => 'search')
autocomplete_result(list_of_strings, :highlight => 'search', :escape => false)
autocomplete_result(list_of_objects, method)
autocomplete_result(list_of_objects, method, :highlight => 'search')
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/right_rails/helpers/misc.rb', line 31 def autocomplete_result(entries, *args) return if entries.empty? = args.last.is_a?(Hash) ? args.pop : {} highlight = [:highlight] escape = [:escape].nil? ? true : [:escape] field = args.first items = entries.collect{ |entry| entry = entry.send(field) if field text = highlight ? highlight(entry, highlight) : escape ? ERB::Util.html_escape(entry) : entry content_tag :li, RightRails::Helpers.html_safe(text) }.join("") content_tag :ul, RightRails::Helpers.html_safe(items) end |
#flashes ⇒ Object
Just a simple flashes generator, might be replaced in the application
8 9 10 11 12 13 14 15 |
# File 'lib/right_rails/helpers/misc.rb', line 8 def flashes items = flash.collect{ |key, text| content_tag(:div, text, :class => key) }.sort.join("") content_tag(:div, RightRails::Helpers.html_safe(items), :id => :flashes, :style => (flash.empty? ? 'display: none' : nil)) end |
#link_to_lightbox(name, url = {}, options = {}, &block) ⇒ Object
Generates a link that whil load the refered address in a lightbox
USAGE:
Same as the #link_to method, plus you might specify the :roadtrip argument
to make it a link to a lightbox roadtrip
<%= link_to_lightbox image_tag('/image.thmb'), '/image.full', :roadtrip => true %>
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/right_rails/helpers/misc.rb', line 62 def link_to_lightbox(name, url={}, ={}, &block) rightjs_require_module 'lightbox' group = .delete(:roadtrip) || .delete(:group) if RightRails::Config.rightjs_version < 2 [:rel] = 'lightbox' [:rel] << "[roadtrip]" if group else [:group] = group.to_s if group end RightRails::Helpers.(, 'lightbox') link_to name, url, , &block end |
#resizable(options = {}, &block) ⇒ Object
The resizable unit helper
USAGE:
<% resizable(:direction => 'bottom', :minHeight => '100px') do %>
Some content in here
<% end -%>
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/right_rails/helpers/misc.rb', line 180 def resizable(={}, &block) rightjs_require_module 'resizable' RightRails::Helpers.(, 'resizable') .delete('data-resizable') if ['data-resizable'] == "{}" [:class] ||= '' [:class] << " #{RightRails::Helpers.css_prefix}-resizable#{[:direction] ? "-#{.delete(:direction)}" : ''}" [:class].strip! content = content_tag(:div, ( content_tag(:div, RightRails::Helpers.html_safe(capture(&block)), :class => "#{RightRails::Helpers.css_prefix}-resizable-content") + content_tag(:div, '', :class => "#{RightRails::Helpers.css_prefix}-resizable-handle") ), ) defined?(Rails) && Rails::VERSION::MAJOR < 3 ? concat(content) : content end |
#tab(title, options = {}, &block) ⇒ Object
162 163 164 165 166 167 168 169 170 |
# File 'lib/right_rails/helpers/misc.rb', line 162 def tab(title, ={}, &block) [:id] = "tab-#{rand.to_s.split('.').last}" if ![:id] && ![:url] @__tabs << { :title => title, :options => , :content => block_given? ? capture(&block) : nil } end |
#tabs(options = {}, &block) ⇒ Object
Tabs container generator
USAGE:
<% tabs do %>
<% tab "Tab 1", :id => :my-tab-1 do %>
content for tab 1
<% end -%>
<% tab "Tab 2", :url => tab2_path %>
<% end -%>
You also can use the :type option with :carousel or :harmonica value
and you can pass along any standard Tabs unit options along with it
<% tabs :type => :carousel, :url => '/tabs/%{id}', :cache => true do %>
<% tab image_tag(image1.thumb_url), :id => image1.id %>
<% tab image_tag(image2.thumb_url), :id => image2.id %>
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/right_rails/helpers/misc.rb', line 98 def tabs(={}, &block) rightjs_require_module 'tabs' @__tabs = [] yield() .stringify_keys! tabs_type = .delete('type') ['id'] = .delete('id') || "tabs-#{rand.to_s.split('.').last}" # checking for the carousel class if tabs_type == :carousel ['class'] ||= '' ['class'] << (['class'] == '' ? '' : ' ') + "#{RightRails::Helpers.css_prefix}-tabs-carousel" end # extracting the tab id prefix option tab_id_prefix = [:idPrefix] || ['idPrefix'] || [:id_prefix] || ['id_prefix'] || '' RightRails::Helpers.(, 'tabs') = .delete('data-tabs') || .delete('data-tabs-options') # simple tabs and carousels generator content = if tabs_type != :harmonica # tabs list tabs_list = content_tag(:ul, RightRails::Helpers.html_safe( @__tabs.collect{ |tab| content_tag(:li, content_tag(:a, tab[:title], :href => tab[:options][:id] ? "##{tab[:options][:id]}" : tab[:options][:url] )) }.join("\n") ) ) + "\n"; # contents list bodies_list = @__tabs.collect{|tab| tab[:content] ? content_tag(:li, tab[:content], :id => "#{tab_id_prefix}#{tab[:options][:id]}") + "\n" : '' }.join("") content_tag(:ul, tabs_list + RightRails::Helpers.html_safe(bodies_list), ) else # the harmonicas generator content_tag(:dl, RightRails::Helpers.html_safe( @__tabs.collect{ |tab| content_tag(:dt, content_tag(:a, tab[:title], :href => tab[:options][:id] ? "##{tab[:options][:id]}" : tab[:options][:url] )) + "\n" + content_tag(:dd, tab[:content] || '', :id => tab[:options][:id] ? "#{tab_id_prefix}#{tab[:options][:id]}" : nil) }.join("\n") ), ) end content = content + RightRails::Helpers.html_safe("\n") + javascript_tag( "new Tabs('#{['id']}', #{ || '{}'});" ) defined?(Rails) && Rails::VERSION::MAJOR < 3 ? concat(content) : content end |