-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapplication_helper.rb
83 lines (61 loc) · 2.19 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
module ApplicationHelper
def staging?
ENV['MAS_ENVIRONMENT'] == 'staging'
end
def tool_provides_data_layer?
content_for?(:page_name) && content_for?(:page_title)
end
def include_adobe_analytics_scripts?(request)
return false unless Rails.env.production? && ENV['INCLUDE_AEM_ANALYTICS'] == 'true'
request.original_url.match?(/[staging-]?partner-tools\.moneyhelper\.org\.uk/)
end
def css(line_numbers: false, &block)
source = strip_leading_indentation_from_source(capture(&block))
tokens = Rouge::Lexers::CSS.lex(source)
format_tokens_as_html(tokens, line_numbers)
end
def erb(line_numbers: false, &block)
source = strip_leading_indentation_from_source(capture(&block))
tokens = Rouge::Lexers::ERB.lex(source)
format_tokens_as_html(tokens, line_numbers)
end
def html(line_numbers: false, &block)
source = strip_leading_indentation_from_source(capture(&block))
tokens = Rouge::Lexers::HTML.lex(source)
format_tokens_as_html(tokens, line_numbers)
end
def scss(line_numbers: false, &block)
source = strip_leading_indentation_from_source(capture(&block))
tokens = Rouge::Lexers::Scss.lex(source)
format_tokens_as_html(tokens, line_numbers)
end
def Terminal256(line_numbers: false, &block)
source = strip_leading_indentation_from_source(capture(&block))
tokens = Rouge::Lexers::HTML.lex(source)
format_tokens_as_html(tokens, line_numbers)
end
def yaml(line_numbers: false, &block)
source = strip_leading_indentation_from_source(capture(&block))
tokens = Rouge::Lexers::YAML.lex(source)
format_tokens_as_html(tokens, line_numbers)
end
def locale_class
"theme-#{I18n.locale}" unless I18n.locale == :en
end
def translation?(key)
I18n.translate!(key)
rescue I18n::MissingTranslationData
false
end
def hide_sticky_header?
(request.fullpath =~ /^\/(cy|en)\/(tools|retirement-income-options)/).present?
end
private
def strip_leading_indentation_from_source(source)
source.strip.gsub(/^[ ]{2}/, '')
end
def format_tokens_as_html(tokens, line_numbers)
formatter = Rouge::Formatters::HTML.new(line_numbers: line_numbers)
formatter.format(tokens).html_safe
end
end