app/helpers/spotlight/pages_helper.rb in blacklight-spotlight-0.1.0 vs app/helpers/spotlight/pages_helper.rb in blacklight-spotlight-0.2.0
- old
+ new
@@ -1,15 +1,32 @@
module Spotlight
module PagesHelper
+ def sir_trevor_markdown text
+ GitHub::Markup.render(".md", text.gsub("<br>", "\n").gsub("<p>", "").gsub("</p>", "\n\n")).html_safe
+ end
def has_title? document
document_heading(document) != document.id
end
+ 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
def item_grid_block_objects(block)
objects = []
block.each do |key, value|
if value.present? and key.include?("item-grid-id")
- objects << {id: value, display: (block[key.gsub("-id", "-display")])}
+ if (display = block[key.gsub("-id", "-display")])
+ objects << {id: value,
+ display: display,
+ thumbnail: block[key.gsub("-id", "-thumbnail")]}
+ end
end
end
objects
end
def item_grid_block_ids(block)
@@ -19,24 +36,44 @@
end
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'
- return document_heading(document)
+ document_heading(document)
else
- return safe_join(Array(document[block[key]]), ", ")
+ render_index_field_value document, block[key]
end
end
end
def disable_save_pages_button?
page_collection_name == "about_pages" && @pages.empty?
end
- def get_search_widget_search_results sir_trevor_json
+ def get_search_widget_search_results block
begin
- search = Spotlight::Search.find(sir_trevor_json['searches-options'])
+ search = Spotlight::Search.find(block.send(:'searches-options'))
get_search_results(search.query_params.with_indifferent_access.merge(params))
rescue ActiveRecord::RecordNotFound
[]
end
+ end
+ def nestable_data_attributes(type)
+ nestable_data_attributes_hash(type).map do |attr, val|
+ "#{attr}='#{val}'"
+ end.join(' ')
+ end
+ 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
+ def render_contact_email_address(address)
+ mail_to address, address
end
end
end