Module: Elabs::ApplicationHelper

Defined in:
app/helpers/elabs/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#boolean_icon_tag(value, true_icon = 'check', false_icon = 'times') ⇒ Object



22
23
24
25
26
27
# File 'app/helpers/elabs/application_helper.rb', line 22

def boolean_icon_tag(value, true_icon = 'check', false_icon = 'times')
  icon_class = [
    "fas fa-#{value ? true_icon : false_icon} fa-fw"
  ]
  (:i, nil, class: icon_class)
end

#icon(name, classes = [], base = 'fas') ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/elabs/application_helper.rb', line 29

def icon(name, classes = [], base = 'fas')
  icon_class = ["#{base} fa-#{name}"]
  icon_class += classes.map do |c|
    if %w[2x 3x 4x fw].include? c
      "fa-#{c}"
    else
      c
    end
  end

  (:i, nil, class: icon_class)
end

#icon_text(icon, text, icon_options = [], reverse = false) ⇒ Object



15
16
17
18
19
20
# File 'app/helpers/elabs/application_helper.rb', line 15

def icon_text(icon, text, icon_options = [], reverse = false)
  format(
    reverse ? _('%<text>s %<icon>s') : _('%<icon>s %<text>s'),
    icon: icon(icon, icon_options), text: text
  ).html_safe
end

#license_icon(license, classes = ['fw']) ⇒ Object



42
43
44
# File 'app/helpers/elabs/application_helper.rb', line 42

def license_icon(license, classes = ['fw'])
  icon license.icon, classes, 'fab'
end

#page_title(title, namespace = nil) ⇒ Object



46
47
48
49
50
51
52
# File 'app/helpers/elabs/application_helper.rb', line 46

def page_title(title, namespace = nil)
  out = [Elabs.site_name]
  out.push(namespace) if namespace
  out.push(title) if title

  out.join('::')
end

#show_item?(entity) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'app/helpers/elabs/application_helper.rb', line 7

def show_item?(entity)
  (entity.sfw? || show_nsfw?) && !entity.locked?
end

#show_nsfw?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'app/helpers/elabs/application_helper.rb', line 3

def show_nsfw?
  session[:show_nsfw]
end

#user_is_author_of(entity) ⇒ Object



11
12
13
# File 'app/helpers/elabs/application_helper.rb', line 11

def user_is_author_of(entity)
  current_user&.id && entity.user_id == current_user.id
end