Class: MetadataPresenter::EngineController

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/metadata_presenter/engine_controller.rb

Instance Method Summary collapse

Instance Method Details

#allow_analytics?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 45

def allow_analytics?
  cookies[analytics_cookie_name] == 'accepted'
end


40
41
42
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 40

def analytics_cookie_name
  @analytics_cookie_name ||= "analytics-#{service.service_name.parameterize}"
end

#analytics_tags_present?Boolean

Returns:

  • (Boolean)


55
56
57
58
59
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 55

def analytics_tags_present?
  Rails.application.config.supported_analytics.values.flatten.any? do |analytic|
    ENV[analytic].present?
  end
end

#answered?(component_id) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 35

def answered?(component_id)
  @page_answers.send(component_id).present?
end


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 18

def back_link
  previous_page = PreviousPage.new(
    service: service,
    user_data: load_user_data,
    current_page: @page,
    referrer: request.referrer
  ).page

  if previous_page
    @back_link ||= File.join(
      request.script_name,
      previous_page.url
    )
  end
end


73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 73

def external_or_relative_link(link)
  uri = URI.parse(link)
  return link if uri.scheme.present? && uri.host.present?

  if editor_preview?
    File.join(request.script_name, link)
  else
    link.starts_with?('/') ? link : link.prepend('/')
  end
end

#load_autocomplete_itemsObject



62
63
64
65
66
67
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 62

def load_autocomplete_items
  if @page.autocomplete_component_present?
    items = autocomplete_items(@page.components)
    @page.assign_autocomplete_items(items)
  end
end

#maintenance_mode?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 69

def maintenance_mode?
  ENV['MAINTENANCE_MODE'].present? && ENV['MAINTENANCE_MODE'] == '1'
end

#reload_user_dataObject



10
11
12
13
14
15
16
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 10

def reload_user_data
  if defined? super
    super
  else
    load_user_data
  end
end

Returns:

  • (Boolean)


50
51
52
# File 'app/controllers/metadata_presenter/engine_controller.rb', line 50

def show_cookie_banner?
  (Rails.application.config.respond_to?(:global_ga4) || analytics_tags_present?) && no_analytics_cookie?
end