asciinema.org/app/helpers/application_helper.rb

74 lines
1.3 KiB
Ruby
Raw Normal View History

module ApplicationHelper
2013-10-19 16:25:30 +00:00
2012-07-25 18:24:20 +00:00
def page_title
2013-09-22 12:07:42 +00:00
title = "asciinema"
2012-07-25 18:24:20 +00:00
if @title
title = "#{@title} - #{title}"
end
title
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
user = current_user || @user
if user
"'#{user.email}'".html_safe
2013-10-19 16:25:30 +00:00
else
'null'
end
end
2012-04-05 20:30:57 +00:00
def markdown(&block)
2012-06-08 07:08:30 +00:00
text = capture(&block)
2012-06-09 13:23:56 +00:00
MKD_RENDERER.render(capture(&block)).html_safe
2012-04-05 20:30:57 +00:00
end
2012-11-19 21:20:45 +00:00
def indented_text(string, width)
string.lines.map { |l| "#{' ' * width}#{l}" }.join('')
end
2012-07-25 18:24:20 +00:00
2012-11-19 21:16:39 +00:00
def link_to_category(text, url, name)
2012-07-25 18:24:20 +00:00
opts = {}
if name == @current_category
opts[:class] = 'active'
end
link_to text, url, opts
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
def avatar_image_tag(user, options = {})
klass = options[:class] || "avatar"
title = options[:title] || user.try(:nickname)
avatar = user.try(:avatar_url) || default_avatar_filename
image_tag avatar, :alt => title, :class => klass
end
def default_avatar_filename
image_path "default_avatar.png"
end
2013-05-27 20:03:16 +00:00
def color_check_asciicast_path
if id = CFG['COLOR_CHECK_CAST_ID']
asciicast_path(id)
end
end
2013-10-19 16:25:30 +00:00
end