helper function fa_icon added

This commit is contained in:
Alexander Meindl 2017-06-29 16:11:47 +02:00
parent 74994705dd
commit 77aec782ca
5 changed files with 39 additions and 9 deletions

View File

@ -22,7 +22,7 @@ Metrics/PerceivedComplexity:
# Offense count: 15
Metrics/AbcSize:
Max: 25
Max: 30
Style/Documentation:
Enabled: false

View File

@ -2,10 +2,10 @@ Changelog
=========
2.0.1 (not released)
+++++
++++++++++++++++++++
- Simplified Chinese support has been added (thanks to @archonwang)
- Helper function fa_icon has been added
2.0.0
+++++

View File

@ -204,6 +204,36 @@ module Additionals
safe_join(s)
end
def fa_icon(name, options = {})
post_text = ''
classes = ['fa']
classes << name
options['aria-hidden'] = 'true'
options[:class] = if options[:class].present?
classes.join(' ') + ' ' + options[:class]
else
classes.join(' ')
end
s = []
if options[:pre_text].present?
s << options[:pre_text]
s << ' '
options.delete(:pre_text)
end
if options[:post_text].present?
post_text = options[:post_text]
options.delete(:post_text)
end
s << content_tag('span', '', options)
if post_text.present?
s << ' '
s << post_text
end
safe_join(s)
end
def query_default_sort(query, fall_back_sort)
criteria = query.sort_criteria.any? ? query.sort_criteria : fall_back_sort
return unless criteria.is_a?(Array)

View File

@ -12,18 +12,18 @@ module Additionals
case name[0..1]
when 'r/'
link_to(content_tag('span', '', class: 'fa fa-reddit') + ' ' + name,
link_to(fa_icon('fa-reddit', post_text: name),
"https://www.reddit.com/#{name}",
class: 'external reddit',
title: l(:label_reddit_subject))
when 'u/'
link_to(content_tag('span', '', class: 'fa fa-reddit-square') + ' ' + name,
link_to(fa_icon('fa-reddit-square', post_text: name),
"https://www.reddit.com/username/#{name[2..-1]}",
class: 'external reddit',
title: l(:label_reddit_user_account))
else
name = 'r/' + name
link_to(content_tag('span', '', class: 'fa fa-reddit') + ' ' + name,
link_to(fa_icon('fa-reddit', post_text: name),
"https://www.reddit.com/#{name}",
class: 'external reddit',
title: l(:label_reddit_subject))

View File

@ -11,17 +11,17 @@ module Additionals
name = args[0].strip
case name[0]
when '@'
link_to(content_tag('span', '', class: 'fa fa-twitter') + ' ' + name,
link_to(fa_icon('fa-twitter', post_text: name),
"https://twitter.com/#{name[1..-1]}",
class: 'external twitter',
title: l(:label_twitter_account))
when '#'
link_to(content_tag('span', '', class: 'fa fa-twitter-square') + ' ' + name,
link_to(fa_icon('fa-twitter-square', post_text: name),
"https://twitter.com/hashtag/#{name[1..-1]}",
class: 'external twitter',
title: l(:label_twitter_hashtag))
else
link_to(content_tag('span', '', class: 'fa fa-twitter') + " @#{name}",
link_to(fa_icon('fa-twitter', post_text: " @#{name}"),
"https://twitter.com/#{name}",
class: 'external twitter',
title: l(:label_twitter_account))