asciinema.org/app/helpers/application_helper.rb

65 lines
1.3 KiB
Ruby
Raw Normal View History

module ApplicationHelper
2013-10-19 16:25:30 +00:00
2013-11-18 11:17:05 +00:00
class CategoryLinks
def initialize(current_category, view_context)
@current_category = current_category
@view_context = view_context
end
def link_to(*args)
@view_context.link_to_category(@current_category, *args)
end
end
2014-02-20 22:00:44 +00:00
def current_user
decorated_current_user
end
2012-07-25 18:24:20 +00:00
def page_title
2013-11-18 17:52:34 +00:00
if content_for?(:title)
"#{content_for(:title)} - Asciinema"
else
"Asciinema - Record and share your terminal sessions, the right way"
2012-07-25 18:24:20 +00:00
end
end
2012-02-26 15:40:30 +00:00
def twitter_auth_path
"/auth/twitter"
end
def github_auth_path
"/auth/github"
end
2012-03-03 07:52:10 +00:00
2013-10-19 16:25:30 +00:00
def browser_id_user
email = current_user && current_user.email || session[:new_user_email]
email ? "'#{email}'".html_safe : 'null'
2013-10-19 16:25:30 +00:00
end
2013-11-18 11:17:05 +00:00
def category_links(current_category, &blk)
links = CategoryLinks.new(current_category, self)
content_tag(:ul, class: 'nav nav-pills nav-stacked') do
blk.call(links)
end
end
def link_to_category(current_category, text, url, name)
2012-07-25 18:24:20 +00:00
opts = {}
2013-11-18 11:17:05 +00:00
if name == current_category
2012-07-25 18:24:20 +00:00
opts[:class] = 'active'
end
2013-11-18 11:17:05 +00:00
content_tag(:li, link_to(text, url), opts)
2012-07-25 18:24:20 +00:00
end
2012-11-19 21:18:29 +00:00
def time_ago_tag(time, options = {})
options[:class] ||= "timeago"
content_tag(:abbr, time.to_s, options.merge(:title => time.getutc.iso8601))
end
2012-12-08 21:29:21 +00:00
end