Module: HomesteadingHelpers::ApplicationHelper
- Defined in:
- app/helpers/homesteading_helpers/application_helper.rb
Instance Method Summary collapse
- #autofocus_value ⇒ Object
- #canonical_url(post = nil) ⇒ Object
- #editing? ⇒ Boolean
- #external_silo_url_key(name) ⇒ Object
- #external_silos ⇒ Object
- #human_readable_date(datetime) ⇒ Object
- #human_readable_time(datetime) ⇒ Object
- #in_reply_to_urls(post) ⇒ Object
- #index_action? ⇒ Boolean
- #is_a_reply?(post) ⇒ Boolean
- #license_html ⇒ Object
- #license_text ⇒ Object
- #link_to_syndication(post) ⇒ Object
- #logged_in? ⇒ Boolean
- #nth_of_day(post) ⇒ Object
- #page_description(post = nil) ⇒ Object
- #post_type ⇒ Object
- #rel_canonical_link_tag(post) ⇒ Object
- #setting(key) ⇒ Object
- #short_url(post) ⇒ Object
- #shorturl_link_tag(post) ⇒ Object
- #show_action? ⇒ Boolean
- #site_title ⇒ Object
-
#site_url ⇒ Object
TODO: do this without #eval ?.
- #small_word_tag(word) ⇒ Object
- #space ⇒ Object
- #tag_url(tag) ⇒ Object
- #write_action? ⇒ Boolean
Instance Method Details
#autofocus_value ⇒ Object
109 110 111 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 109 def autofocus_value !editing? end |
#canonical_url(post = nil) ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 39 def canonical_url(post=nil) if post.nil? "http://#{setting :long_domain}" else "http://#{setting :long_domain}/#{post.path}" end end |
#editing? ⇒ Boolean
89 90 91 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 89 def editing? action_name == "edit" end |
#external_silo_url_key(name) ⇒ Object
194 195 196 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 194 def external_silo_url_key(name) "#{name.downcase}_url".to_sym end |
#external_silos ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 179 def external_silos %w[ Facebook Foursquare Instagram Medium Tumblr Twitter Vimeo Vine WordPress YouTube ] end |
#human_readable_date(datetime) ⇒ Object
93 94 95 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 93 def human_readable_date(datetime) datetime.strftime("%F") end |
#human_readable_time(datetime) ⇒ Object
97 98 99 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 97 def human_readable_time(datetime) datetime.strftime("%l:%M%p").downcase end |
#in_reply_to_urls(post) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 137 def in_reply_to_urls(post) html = [] post.in_reply_to.split(" ").each do |in_reply_to| text = in_reply_to.gsub(/^https?:\/\//, "").gsub(/\//, "/<wbr />").html_safe url = in_reply_to unless url.match(/^http/) url = "http://#{url}" end rel = show_action? ? "in-reply-to external" : "external" html << link_to(text, url, class: "u-in-reply-to h-cite", rel: rel).html_safe end html.join(" ").html_safe end |
#index_action? ⇒ Boolean
75 76 77 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 75 def index_action? action_name == "index" end |
#is_a_reply?(post) ⇒ Boolean
198 199 200 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 198 def is_a_reply?(post) !post.in_reply_to.blank? end |
#license_html ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 211 def license_html output = [] # license license = ::License.find(setting(:license)) if license.name == "All Rights Reserved" # Default output << "#{license.name} #{license.short_code}" else # Creative Commons and Public Domain (CC0) output << link_to("#{license.name} (#{license.short_code})", license.url, rel: "license") end # range of years years_range = Time.now.year first_post = Post.first first_post_year = first_post.nil? ? years_range : first_post.published_at.year if first_post_year == years_range output << years_range else output << "#{first_post_year}–#{years_range}" end # author's name output << link_to(setting(:author_name), setting(:author_url), class: "p-author h-card") output.join(" ").html_safe end |
#license_text ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 245 def license_text output = [] # license license = ::License.find(setting(:license)) if license.name == "All Rights Reserved" # Default output << "#{license.name} #{license.short_code}" else # Creative Commons and Public Domain (CC0) output << "#{license.name} (#{license.short_code})" output << license.url end # range of years years_range = Time.now.year first_post = Post.first first_post_year = first_post.nil? ? years_range : first_post.published_at.year if first_post_year == years_range output << years_range else output << "#{first_post_year}–#{years_range}" end # author's name output << setting(:author_name) output.join("\n") end |
#link_to_syndication(post) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 155 def (post) html = content_tag(:p, "Also posted to") links = [] external_silos.each do |external| if post.respond_to?(external_silo_url_key(external)) && post.send(external_silo_url_key(external)) && !post.send(external_silo_url_key(external)).blank? rel = "external " rel << "syndication" if show_action? links << content_tag(:li, link_to(external, post.send(external_silo_url_key(external)), rel: rel, class: "u-syndication")) end end if links.blank? space else html << content_tag(:ul, links.flatten.join.html_safe) end end |
#logged_in? ⇒ Boolean
105 106 107 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 105 def logged_in? Rails.env.development? end |
#nth_of_day(post) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 25 def nth_of_day(post) nth = Post.where( year: post.year, month: post.month, day: post.day ).all.sort_by{|n| n.published_at}.index(post) + 1 if nth.nil? nth = 1 end nth.to_sxg end |
#page_description(post = nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 59 def page_description(post=nil) if index_action? page_description = "#{setting(:post_type).pluralize.capitalize} by #{setting :author_name}" elsif show_action? page_description = post.content else page_description = setting(:site_description) end page_description end |
#post_type ⇒ Object
113 114 115 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 113 def post_type setting(:post_type) end |
#rel_canonical_link_tag(post) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 47 def rel_canonical_link_tag(post) url = "http://#{setting :long_domain}" if index_action? url = "http://#{setting :long_domain}/#{setting(:post_type).pluralize.downcase}" elsif show_action? url = canonical_url(post) end tag(:link, id: "canonical", rel: "canonical", type: "text/html", href: url) end |
#setting(key) ⇒ Object
133 134 135 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 133 def setting(key) ::Setting.where(key: key).first.content end |
#short_url(post) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 16 def short_url(post) pieces = [setting(:post_short_code)] pieces << Date.parse("#{post.year}-#{post.month}-#{post.day}").to_sxg pieces << nth_of_day(post) "http://#{setting :short_domain}/#{pieces.join}" end |
#shorturl_link_tag(post) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 4 def shorturl_link_tag(post) if index_action? url = "http://#{setting :short_domain}/#{setting(:post_short_code)}" elsif show_action? url = short_url(post) else url = "http://#{setting :short_domain}" end tag(:link, id: "shortlink", rel: "shortlink", type: "text/html", href: url) end |
#show_action? ⇒ Boolean
79 80 81 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 79 def show_action? action_name == "show" end |
#site_title ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 117 def site_title title = "" if setting(:site_title).blank? title << post_type.capitalize.pluralize else title << setting(:site_title) end if @page_title title << " - #{@page_title}" end title.html_safe end |
#site_url ⇒ Object
TODO: do this without #eval ?
203 204 205 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 203 def site_url eval "#{setting(:post_type).pluralize}_url" end |
#small_word_tag(word) ⇒ Object
101 102 103 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 101 def small_word_tag(word) content_tag(:b, word, class: "small-word small-word-#{word}") end |
#space ⇒ Object
71 72 73 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 71 def space " " end |
#tag_url(tag) ⇒ Object
207 208 209 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 207 def tag_url(tag) site_url + "/tags/" + tag.gsub(/ /, "+") end |
#write_action? ⇒ Boolean
83 84 85 86 87 |
# File 'app/helpers/homesteading_helpers/application_helper.rb', line 83 def write_action? unless controller_name == "settings" action_name =~ /new|edit/ end end |