Module: Spotlight::PagesHelper

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

Instance Method Summary collapse

Instance Method Details

#disable_save_pages_button?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/helpers/spotlight/pages_helper.rb', line 47

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

#get_search_widget_search_results(block) ⇒ Object



50
51
52
53
54
55
56
57
# File 'app/helpers/spotlight/pages_helper.rb', line 50

def get_search_widget_search_results block
  begin
    search = Spotlight::Search.find(block.send(:'searches-options'))
    get_search_results(search.query_params.with_indifferent_access.merge(params))
  rescue ActiveRecord::RecordNotFound
    []
  end
end

#has_title?(document) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'app/helpers/spotlight/pages_helper.rb', line 6

def has_title? document
  document_heading(document) != document.id
end

#item_grid_block_ids(block) ⇒ Object



32
33
34
35
36
# File 'app/helpers/spotlight/pages_helper.rb', line 32

def item_grid_block_ids(block)
  item_grid_block_objects(block).map do |object|
    object[:id] if object[:display]
  end.compact
end

#item_grid_block_objects(block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/spotlight/pages_helper.rb', line 19

def item_grid_block_objects(block)
  objects = []
  block.each do |key, value|
    if value.present? and key.include?("item-grid-id")
      if (display = block[key.gsub("-id", "-display")])
        objects << {id: value,
                    display: display,
                    thumbnail: block[key.gsub("-id", "-thumbnail")]}
      end
    end
  end
  objects
end

#item_grid_block_with_documents(block) ⇒ Object



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

def item_grid_block_with_documents(block)
  block_objects = item_grid_block_objects(block)
  ids = item_grid_block_ids(block)
  documents = get_solr_response_for_document_ids(ids).last
  block_objects.each do |object|
    if (doc = documents.find{ |d| d[:id] == object[:id] }).present?
      object[:solr_document] = doc
    end
  end
end

#multi_up_item_grid_caption(block, document, type = 'primary') ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/spotlight/pages_helper.rb', line 37

def multi_up_item_grid_caption(block, document, type='primary')
  key = "item-grid-#{type}-caption-field"
  if block[key].present?
    if block[key] == 'spotlight_title_field'
      document_heading(document)
    else
      render_index_field_value document, block[key]
    end
  end
end

#nestable_data_attributes(type) ⇒ Object



58
59
60
61
62
# File 'app/helpers/spotlight/pages_helper.rb', line 58

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



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

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



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

def render_contact_email_address(address)
  mail_to address, address
end

#sir_trevor_markdown(text) ⇒ Object



3
4
5
# File 'app/helpers/spotlight/pages_helper.rb', line 3

def sir_trevor_markdown text
  GitHub::Markup.render(".md", text.gsub("<br>", "\n").gsub("<p>", "").gsub("</p>", "\n\n")).html_safe
end