ruby-x.github.io/app/helpers/application_helper.rb

40 lines
1.0 KiB
Ruby
Raw Permalink Normal View History

2018-04-10 17:25:46 +02:00
module ApplicationHelper
2018-04-11 18:34:35 +02:00
def post_link(post)
2018-04-10 21:48:23 +02:00
return "" unless post
2018-04-11 18:34:35 +02:00
link_to(blog_post_url(post.slug)) do
"#{post.title.capitalize} <span>(#{post.date})</span>".html_safe
end.html_safe
2018-04-10 21:48:23 +02:00
end
2018-04-11 09:45:50 +02:00
def ext_link(name = nil, options = nil, html_options = nil, &block)
target_blank = {target: "_blank"}
if block_given?
options ||= {}
options = options.merge(target_blank)
else
html_options ||= {}
html_options = html_options.merge(target_blank)
end
link_to(name, options, html_options, &block)
end
def title(title)
@title = title
end
2018-04-11 18:34:35 +02:00
def prev_post(post)
index = Post.posts.keys.index(post.slug)
nav_post(index + 1 , "prev")
end
def next_post(post)
index = Post.posts.keys.index(post.slug)
nav_post(index - 1 , "next")
end
def nav_post(index, dir)
return "" unless index >= 0
post = Post.posts.values[index]
return "" unless post
link_to("#{dir} <span>(#{post.date})</span>".html_safe , blog_post_url(post.slug) , alt: post.title.capitalize)
end
2018-04-10 17:25:46 +02:00
end