Module: ReaderHelper
- Includes:
- Admin::RegionsHelper, SnailHelpers
- Included in:
- GroupTags, MessageTags, ReaderTags
- Defined in:
- app/helpers/reader_helper.rb
Instance Method Summary collapse
- #choose_page(object, field, select_options = {}) ⇒ Object
- #clean_html(text) ⇒ Object
- #country_options_for_select(selected = nil, default_selected = Snail.home_country) ⇒ Object
- #email_link(address) ⇒ Object
- #friendly_date(datetime) ⇒ Object
- #friendly_date_format(datetime) ⇒ Object
- #gravatar_for(reader = nil, gravatar_options = {}, img_options = {}) ⇒ Object
- #group_options_for_select ⇒ Object
- #home_page_link(options = {}) ⇒ Object
- #link_to_group(group) ⇒ Object
- #link_to_message(message) ⇒ Object
- #link_to_reader(reader) ⇒ Object
- #message_preview(subject, body, reader) ⇒ Object
-
#options_from_tree(tree, options = {}) ⇒ Object
Takes a hash of hashes in the format returned by Ancestry#arrange, returns an indented option set.
- #page_option_branch(page, depth = 0) ⇒ Object
- #pagination_and_summary_for(list, name = '') ⇒ Object
- #pagination_summary(list, name = '') ⇒ Object
- #parent_group_options_for_select(group = nil) ⇒ Object
- #scrub_html(text) ⇒ Object
- #standard_gravatar_for(reader = nil, url = nil) ⇒ Object
- #truncate_words(text = '', options = {}) ⇒ Object
Instance Method Details
#choose_page(object, field, select_options = {}) ⇒ Object
103 104 105 106 107 108 |
# File 'app/helpers/reader_helper.rb', line 103 def choose_page(object, field, ={}) root = Page.respond_to?(:homepage) ? Page.homepage : Page.find_by_parent_id(nil) = page_option_branch(root) .unshift [t("reader_extension.none_option"), nil] select object, field, , end |
#clean_html(text) ⇒ Object
57 58 59 |
# File 'app/helpers/reader_helper.rb', line 57 def clean_html(text) Sanitize.clean(textilize(text), Sanitize::Config::GENEROUS) end |
#country_options_for_select(selected = nil, default_selected = Snail.home_country) ⇒ Object
141 142 143 |
# File 'app/helpers/reader_helper.rb', line 141 def (selected = nil, default_selected = Snail.home_country) (selected, default_selected) end |
#email_link(address) ⇒ Object
153 154 155 |
# File 'app/helpers/reader_helper.rb', line 153 def email_link(address) mail_to address, nil, :encode => :hex, :replace_at => ' at ', :class => 'mailto' end |
#friendly_date(datetime) ⇒ Object
121 122 123 |
# File 'app/helpers/reader_helper.rb', line 121 def friendly_date(datetime) I18n.l(datetime, :format => friendly_date_format(datetime)) if datetime end |
#friendly_date_format(datetime) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/helpers/reader_helper.rb', line 125 def friendly_date_format(datetime) if datetime && date = datetime.to_date if (date.to_datetime == Date.today) :today elsif (date.to_datetime == Date.yesterday) :yesterday elsif (date.to_datetime > 6.days.ago) :recently elsif (date.year == Date.today.year) :this_year else :standard end end end |
#gravatar_for(reader = nil, gravatar_options = {}, img_options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/reader_helper.rb', line 16 def gravatar_for(reader=nil, ={}, ={}) size = [:size] || 40 [:size] ||= "#{size}x#{size}" [:default] ||= "#{request.protocol}#{request.host_with_port}/images/furniture/no_gravatar.png" [:alt] ||= reader.preferred_name if reader if reader.nil? || reader.email.blank? image_tag [:default], else image_tag gravatar_url(reader.email, ), end end |
#group_options_for_select ⇒ Object
145 146 147 |
# File 'app/helpers/reader_helper.rb', line 145 def (Group.arrange).unshift([t("reader_extension.any_option"), nil]) end |
#home_page_link(options = {}) ⇒ Object
48 49 50 51 |
# File 'app/helpers/reader_helper.rb', line 48 def home_page_link(={}) home_page = Page.find_by_parent_id(nil) link_to home_page.title, home_page.url, end |
#link_to_group(group) ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/helpers/reader_helper.rb', line 36 def link_to_group(group) if page = group.homepage link_to group.name, page.url else link_to group.name, group_url(group) end end |
#link_to_message(message) ⇒ Object
44 45 46 |
# File 'app/helpers/reader_helper.rb', line 44 def () link_to .subject, () end |
#link_to_reader(reader) ⇒ Object
28 29 30 31 32 33 34 |
# File 'app/helpers/reader_helper.rb', line 28 def link_to_reader(reader) if page = ReaderPage.first page.url_for(reader) else reader_url(reader) end end |
#message_preview(subject, body, reader) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/helpers/reader_helper.rb', line 88 def (subject, body, reader) preview = <<EOM From: #{current_user.name} <#{current_user.email}> To: #{reader.preferred_name} <#{reader.email}> Date: #{Time.now.to_date.to_s :long} <strong>Subject: #{subject}</strong> Dear #{reader.preferred_name}, #{body} EOM simple_format(preview) end |
#options_from_tree(tree, options = {}) ⇒ Object
Takes a hash of hashes in the format returned by Ancestry#arrange, returns an indented option set.
159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'app/helpers/reader_helper.rb', line 159 def (tree, ={}) option_list = [] depth = [:depth] || 0 exception = [:except] tree.each_pair do |key, values| unless key == exception option_list << [". " * depth + key.name, key.id] option_list << (values, :depth => depth + 1, :except => exception) if values.any? end end option_list.compact end |
#page_option_branch(page, depth = 0) ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'app/helpers/reader_helper.rb', line 110 def page_option_branch(page, depth=0) = [] unless page.title.first == '_' << ["#{". " * depth}#{h(page.title)}", page.id] page.children.each do |child| += page_option_branch(child, depth + 1) end end end |
#pagination_and_summary_for(list, name = '') ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/reader_helper.rb', line 71 def pagination_and_summary_for(list, name='') %{<div class="pagination"> #{will_paginate list, :container => false} <span class="pagination_summary"> #{pagination_summary(list, name)} </span> </div> } end |
#pagination_summary(list, name = '') ⇒ Object
81 82 83 84 85 86 |
# File 'app/helpers/reader_helper.rb', line 81 def pagination_summary(list, name='') total = list.total_entries start = list.offset + 1 finish = ((list.offset + list.per_page) < list.total_entries) ? list.offset + list.per_page : list.total_entries t("reader_extension.showing_of_total", :count => total, :start => start, :finish => finish, :name => name, :names => name.pluralize) end |
#parent_group_options_for_select(group = nil) ⇒ Object
149 150 151 |
# File 'app/helpers/reader_helper.rb', line 149 def (group=nil) (Group.arrange, :except => group).unshift([t("reader_extension.none_option"), nil]) end |
#scrub_html(text) ⇒ Object
53 54 55 |
# File 'app/helpers/reader_helper.rb', line 53 def scrub_html(text) Sanitize.clean(textilize(text)) end |
#standard_gravatar_for(reader = nil, url = nil) ⇒ Object
9 10 11 12 13 14 |
# File 'app/helpers/reader_helper.rb', line 9 def standard_gravatar_for(reader=nil, url=nil) size = Radiant::Config['reader.gravatar_size'] || 40 url ||= reader_url(reader) gravatar = gravatar_for(reader, {:size => size}, {:class => 'gravatar offset', :width => size, :height => size}) content_tag(:div, link_to(gravatar, url), :class => "speaker", :width => size, :height => size) end |
#truncate_words(text = '', options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/reader_helper.rb', line 61 def truncate_words(text='', ={}) return '' if text.blank? = {:length => } unless .is_a? Hash .reverse_merge!(:length => 30, :omission => '…') words = text.split length = [:length].to_i [:omission] = '' unless words.size > length words[0..(length-1)].join(" ") + [:omission] end |