-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathapplication_helper.rb
94 lines (80 loc) · 1.98 KB
/
application_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# frozen_string_literal: true
module ApplicationHelper
APPLICATION_NAME = 'CodeOcean'
def application_name
APPLICATION_NAME
end
def clear_content_for(name)
view_flow.content.delete(name)
end
def code_tag(code, language = nil)
if code.present?
tag.pre do
tag.code(code, class: "language-#{language}")
end
else
empty
end
end
def empty
tag.i(nil, class: 'empty fa-solid fa-minus')
end
def label_column(label)
tag.div(class: 'col-md-3') do
tag.strong do
I18n.exists?("activerecord.attributes.#{label}") ? t("activerecord.attributes.#{label}") : t(label)
end
end
end
private :label_column
def no
tag.i(nil, class: 'fa-solid fa-xmark')
end
def per_page_param
if params[:per_page]
[params[:per_page].to_i, 100].min
else
WillPaginate.per_page
end
end
def progress_bar(value)
tag.div(class: value ? 'progress' : 'disabled progress') do
tag.div(value ? "#{value}%" : '', 'aria-valuemax': 100, 'aria-valuemin': 0,
'aria-valuenow': value, class: 'progress-bar progress-bar-striped', role: 'progressbar', style: "width: #{[value || 0, 100].min}%;")
end
end
def render_markdown(markdown)
ActionController::Base.helpers.sanitize Kramdown::Document.new(
markdown,
input: 'GFM',
hard_wrap: false,
smart_quotes: 'apos,apos,quot,quot',
footnote_backlink: nil
).to_html.strip
end
def row(options = {}, &)
tag.div(class: 'attribute-row row') do
label_column(options[:label]) + value_column(options[:value], &)
end
end
def symbol_for(value)
if value.is_a?(FalseClass)
no
elsif value.is_a?(TrueClass)
yes
elsif value.blank?
empty
else
value.to_s
end
end
def value_column(value)
tag.div(class: 'col-md-9') do
block_given? ? yield : symbol_for(value)
end
end
private :value_column
def yes
tag.i(nil, class: 'fa-solid fa-check')
end
end