Module: Atreides::ApplicationHelper
- Includes:
- Extendable
- Defined in:
- app/helpers/atreides/application_helper.rb
Overview
Methods added to this helper will be available to all templates in the application.
Instance Method Summary collapse
- #action_link(action, record, record_name, final_options = {}) ⇒ Object
- #body_classes ⇒ Object
- #col_to_class_name(col) ⇒ Object
-
#col_to_field(col) ⇒ Object
Forms and Lists.
- #facebook_meta_tags ⇒ Object
-
#flash_messages ⇒ Object
Common.
- #link_current_block ⇒ Object
- #message_for_item(message, item = nil) ⇒ Object
- #page_description ⇒ Object
- #page_object ⇒ Object
- #page_title ⇒ Object
- #remote_function(options) ⇒ Object
- #session_key ⇒ Object
- #sort_col(col) ⇒ Object
- #sortable_element(element_id, options = {}) ⇒ Object
-
#sortable_element_js(element_id, options = {}) ⇒ Object
ScriptaculousHelper overrides for jQuery.
- #truncate_words(txt, ops = {}) ⇒ Object
Instance Method Details
#action_link(action, record, record_name, final_options = {}) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'app/helpers/atreides/application_helper.rb', line 186 def action_link(action, record, record_name, = {}) url = case action.to_sym when :show, :destroy, :update "#{record_name}_path" when :edit "edit_#{record_name}_path" when :new "new_#{record_name}_path" else "#{action}_#{record_name}_path" end = case action.to_sym when :destroy {:confirm => 'Are you sure?', :method => :delete} when :moderate {:confirm => 'Are you sure?', :method => :put } end ||= {} link_to action.capitalize, send(url, record), {:class => action}.merge().merge() end |
#body_classes ⇒ Object
93 94 95 96 97 98 |
# File 'app/helpers/atreides/application_helper.rb', line 93 def body_classes con = params[:controller].split('/').last.strip act = params[:action].strip id = resource ? resource.to_param : nil "#{con} #{con}-#{act} #{id} #{@body_classes.to_s}" end |
#col_to_class_name(col) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'app/helpers/atreides/application_helper.rb', line 163 def col_to_class_name(col) case col.type when :text :textarea when :boolean :checkbox when :date, :datetime, :time :select else :text end end |
#col_to_field(col) ⇒ Object
Forms and Lists
148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/helpers/atreides/application_helper.rb', line 148 def col_to_field(col) case col.type when :text :text_area when :boolean :check_box when :date :date_select when :datetime, :time :datetime_select else :text_field end end |
#facebook_meta_tags ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/atreides/application_helper.rb', line 4 def return unless page_object title = Settings.app_name + " - #{page_title}" str = tag(:meta, :name => "title", :content => title) + "\n" str += tag(:meta, :name => "description", :content => page_description) + "\n" str += tag(:meta, :property => "og:title", :content => title) + "\n" str += tag(:meta, :property => "og:description", :content => page_description) + "\n" str += tag(:meta, :property => "og:url", :content => request.url) + "\n" str += tag(:meta, :property => "og:site_name", :content => Settings.app_name) + "\n" str += tag(:meta, :property => "og:type", :content => "article") + "\n" return str unless page_object.respond_to?(:post_type) str += case page_object.post_type.to_s when "video" unless page_object.videos.empty? v = page_object.videos.first tag(:link, :rel => "video_src", :href => v., :title => title) + "\n" + tag(:meta, :rel => "video_height", :content => v.height) + "\n" + tag(:meta, :rel => "video_width", :content => v.width) + "\n" + tag(:meta, :rel => "video_type", :content => "application/x-shockwave-flash") + "\n" + tag(:link, :rel => "image_src", :href => v.thumb_url, :title => title) + "\n" + tag(:meta, :property => "og:video", :content => v.) + "\n" + tag(:meta, :property => "og:video:height", :content => v.height) + "\n" + tag(:meta, :property => "og:video:width", :content => v.width) + "\n" + tag(:meta, :property => "og:video:type", :content => "application/x-shockwave-flash") + "\n" + tag(:meta, :property => "og:image", :content => v.thumb_url) end else if page_object.thumbnail tag(:link, :rel => "image_src", :href => page_object.thumbnail, :title => title) + "\n" + tag(:meta, :name => "medium", :content => "image") + "\n" + tag(:meta, :property => "og:image", :content => page_object.thumbnail) + "\n" end end str.html_safe end |
#flash_messages ⇒ Object
Common
66 67 68 69 70 71 72 73 74 75 |
# File 'app/helpers/atreides/application_helper.rb', line 66 def return unless = flash.keys.select{|k| [:notice, :message, :warning, :error].include?(k)} content_tag(:div, :id => "flash") do .map do |type| content_tag :div, :id => "flash-#{type.to_s}", :class => "flash #{type.to_s}" do content_tag :span, (flash[type], flash["#{type}_item".to_sym]).html_safe end end.join.html_safe end end |
#link_current_block ⇒ Object
89 90 91 |
# File 'app/helpers/atreides/application_helper.rb', line 89 def link_current_block @link_current_block ||= Proc.new { |name| content_tag(:span, name) } end |
#message_for_item(message, item = nil) ⇒ Object
77 78 79 80 81 82 83 |
# File 'app/helpers/atreides/application_helper.rb', line 77 def (, item = nil) if item.is_a?(Array) % link_to(*item) else end end |
#page_description ⇒ Object
52 53 54 55 |
# File 'app/helpers/atreides/application_helper.rb', line 52 def page_description return "" if page_object.nil? truncate_words((page_object.body), :length => 20, :omission => "...") end |
#page_object ⇒ Object
57 58 59 60 61 |
# File 'app/helpers/atreides/application_helper.rb', line 57 def page_object page_object ||= @post || @page page_object ||= @posts.first if @posts page_object end |
#page_title ⇒ Object
46 47 48 49 50 |
# File 'app/helpers/atreides/application_helper.rb', line 46 def page_title return "" if page_object.nil? page_object.title end |
#remote_function(options) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/helpers/atreides/application_helper.rb', line 129 def remote_function() opts = { :type => [:type] || [:method] || 'post', :dataType => [:dataType] || 'script', :url => [:url] || url_for(params) } opts.each_pair{|k,v| opts[k] = "'#{v}'" } opts[:data] = [:data] if .key?(:data) [:success, :complete, :beforeSend, :error].each do |k| opts[k] = "function(){" + [k] + "}" if .key?(k) end %($.ajax(#{(opts)});) end |
#session_key ⇒ Object
85 86 87 |
# File 'app/helpers/atreides/application_helper.rb', line 85 def session_key @session_key ||= Rails.application.config.[:key] end |
#sort_col(col) ⇒ Object
176 177 178 179 180 181 182 183 184 |
# File 'app/helpers/atreides/application_helper.rb', line 176 def sort_col(col) col_sym = col.class.to_s.downcase.to_sym rescue nil case col_sym when :datetime, :time "date-iso" else "text" end end |
#sortable_element(element_id, options = {}) ⇒ Object
125 126 127 |
# File 'app/helpers/atreides/application_helper.rb', line 125 def sortable_element(element_id, = {}) javascript_tag(sortable_element_js(element_id, )) end |
#sortable_element_js(element_id, options = {}) ⇒ Object
ScriptaculousHelper overrides for jQuery
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/helpers/atreides/application_helper.rb', line 112 def sortable_element_js(element_id, = {}) #:nodoc: # Make AJAX callback request if URL provided if .key?(:url) [:data] = %($(#{ActiveSupport::JSON.encode(element_id)}).sortable('serialize')) [:update] = "function(){" + remote_function() + "}" .delete(:url) .delete(:data) end [:axis].each {|k| [k] = "'#{[k]}'" } %($(#{ActiveSupport::JSON.encode(element_id)}).sortable(#{()});) end |
#truncate_words(txt, ops = {}) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'app/helpers/atreides/application_helper.rb', line 100 def truncate_words(txt, ops = {}) ops.reverse_merge({ :length => 100, :omission => "..." }) words = txt.to_s.split() words[0..(ops[:length]-1)].join(' ').to_s + (words.length > ops[:length] ? ops[:omission] : '').to_s end |