Module: Spotlight::PagesHelper

Includes:
RenderingHelper
Defined in:
app/helpers/spotlight/pages_helper.rb

Overview

Sir-trevor helpers methods

Instance Method Summary collapse

Methods included from RenderingHelper

#render_markdown

Instance Method Details

#configurations_for_current_pageObject



80
81
82
# File 'app/helpers/spotlight/pages_helper.rb', line 80

def configurations_for_current_page
  Spotlight::PageConfigurations.new(context: self, page: @page).as_json
end

#content_editor_class(page) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'app/helpers/spotlight/pages_helper.rb', line 9

def content_editor_class(page)
  page_content = page.content_type

  if page_content == 'SirTrevor'
    'js-st-instance'
  else
    "js-#{page_content.parameterize}-instance"
  end
end

#disable_save_pages_button?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/helpers/spotlight/pages_helper.rb', line 44

def disable_save_pages_button?
  page_collection_name == 'about_pages' && @pages.empty?
end

#get_search_widget_search_results(block) ⇒ Object



48
49
50
51
52
53
54
# File 'app/helpers/spotlight/pages_helper.rb', line 48

def get_search_widget_search_results(block)
  if block.search.present?
    search_results(block.search.merge_params_for_search(params, blacklight_config))
  else
    []
  end
end

#nestable_data_attributes(type) ⇒ Object



56
57
58
59
60
# File 'app/helpers/spotlight/pages_helper.rb', line 56

def nestable_data_attributes(type)
  nestable_data_attributes_hash(type).map do |attr, val|
    "#{attr}='#{val}'"
  end.join(' ')
end

#nestable_data_attributes_hash(type) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/helpers/spotlight/pages_helper.rb', line 62

def nestable_data_attributes_hash(type)
  case type
  when 'feature_pages'
    { 'data-max-depth' => '2',
      'data-expand-btn-HTML' => '',
      'data-collapse-btn-HTML' => '' }
  when 'about_pages'
    { 'data-max-depth' => '1' }
  else
    {}
  end
end

#render_contact_email_address(address) ⇒ Object

Insert soft breaks into email addresses so they wrap nicely



76
77
78
# File 'app/helpers/spotlight/pages_helper.rb', line 76

def render_contact_email_address(address)
  mail_to address, sanitize(address).gsub(/([@\.])/, '\1<wbr />').html_safe
end

#sir_trevor_format(text, format: :markdown) ⇒ Object



19
20
21
22
23
24
25
# File 'app/helpers/spotlight/pages_helper.rb', line 19

def sir_trevor_format(text, format: :markdown)
  if format.to_s.to_sym == :html
    sir_trevor_html(text)
  else
    sir_trevor_markdown(text)
  end
end

#sir_trevor_html(text) ⇒ Object



27
28
29
# File 'app/helpers/spotlight/pages_helper.rb', line 27

def sir_trevor_html(text)
  sanitize(text, tags: %w[b i a br p sup])
end

#sir_trevor_markdown(text) ⇒ Object

Override the default #sir_trevor_markdown so we can use a more complete markdown rendered



34
35
36
37
38
39
40
41
42
# File 'app/helpers/spotlight/pages_helper.rb', line 34

def sir_trevor_markdown(text)
  clean_text = if text
                 text.gsub('<br>', "\n\n").gsub('<p>', '').gsub('</p>', "\n\n")
               else
                 ''
               end

  render_markdown(clean_text)
end