Module: CommonwealthVlrEngine::ApplicationHelper
- Defined in:
- app/helpers/commonwealth_vlr_engine/application_helper.rb
Instance Method Summary collapse
-
#datastream_disseminator_url(pid, datastream_id) ⇒ Object
returns the direct URL to a datastream in Fedora.
-
#get_image_metadata(image_pid) ⇒ Object
returns a hash with width/height from IIIF info.json response.
-
#iiif_image_tag(image_pid, options) ⇒ Object
create an image tag from an IIIF image server.
-
#iiif_image_url(image_pid, options) ⇒ Object
return the IIIF image url.
-
#iiif_square_img_path(image_pid, size) ⇒ Object
return a square image of the supplied size (in pixels).
- #insert_google_analytics ⇒ Object
- #insert_opengraph_markup ⇒ Object
- #link_to_county_facet(field_value, field) ⇒ Object
- #link_to_facet(field_value, field, displayvalue = nil) ⇒ Object
-
#link_to_facets(field_values, fields, displayvalue = nil) ⇒ Object
link to a combination of facets (series + subseries, for ex).
-
#link_to_field(fieldname, fieldvalue, displayvalue = nil) ⇒ Object
from psu scholarsphere TODO: this isn’t used anywhere in the app, get rid of it?.
-
#osd_nav_images(path_to_directory) ⇒ Object
returns a hash with the location of the OpenSeadragon custom images.
-
#render_format(value) ⇒ Object
show the display-friendly value for the Format facet.
- #render_format_index(args) ⇒ Object
-
#render_object_icon_path(format) ⇒ Object
return the path to the icon for objects with no thumbnail.
Instance Method Details
#datastream_disseminator_url(pid, datastream_id) ⇒ Object
returns the direct URL to a datastream in Fedora
82 83 84 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 82 def datastream_disseminator_url pid, datastream_id "#{FEDORA_URL['url']}/objects/#{pid}/datastreams/#{datastream_id}/content" end |
#get_image_metadata(image_pid) ⇒ Object
returns a hash with width/height from IIIF info.json response
117 118 119 120 121 122 123 124 125 126 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 117 def (image_pid) iiif_response = Typhoeus::Request.get(IIIF_SERVER['url'] + image_pid + '/info.json') if iiif_response.response_code == 200 && !iiif_response.response_body.empty? iiif_info = JSON.parse(iiif_response.body) = {height: iiif_info["height"].to_i, width: iiif_info["width"].to_i} else = {height: 0, width: 0} end end |
#iiif_image_tag(image_pid, options) ⇒ Object
create an image tag from an IIIF image server
87 88 89 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 87 def iiif_image_tag(image_pid,) image_tag iiif_image_url(image_pid, ), :alt => [:alt].presence, :class => [:class].presence end |
#iiif_image_url(image_pid, options) ⇒ Object
return the IIIF image url
92 93 94 95 96 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 92 def iiif_image_url(image_pid, ) size = [:size] ? [:size] : 'full' region = [:region] ? [:region] : 'full' "#{IIIF_SERVER['url']}#{image_pid}/#{region}/#{size}/0/default.jpg" end |
#iiif_square_img_path(image_pid, size) ⇒ Object
return a square image of the supplied size (in pixels)
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 99 def iiif_square_img_path(image_pid, size) img_info = (image_pid) width = img_info[:width] height = img_info[:height] if width > height offset = (width - height) / 2 iiif_image_url(image_pid, {:region => "#{offset},0,#{height},#{height}", :size => "#{size},#{size}"}) elsif height > width offset = (height - width) / 2 iiif_image_url(image_pid, {:region => "0,#{offset},#{width},#{width}", :size => "#{size},#{size}"}) else iiif_image_url(image_pid, {:size => "#{size},#{size}"}) end end |
#insert_google_analytics ⇒ Object
136 137 138 139 140 141 142 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 136 def insert_google_analytics if Rails.env.to_s == 'production' content_for(:head) do render :partial=>'/layouts/google_analytics' end end end |
#insert_opengraph_markup ⇒ Object
128 129 130 131 132 133 134 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 128 def insert_opengraph_markup if controller_name == 'catalog' && action_name == 'show' content_for(:head) do render :partial=>'/catalog/opengraph', :locals => {:document => @document} end end end |
#link_to_county_facet(field_value, field) ⇒ Object
77 78 79 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 77 def link_to_county_facet(field_value, field) link_to(field_value + ' County', search_catalog_path(:f => {field => [field_value + ' (county)']})) end |
#link_to_facet(field_value, field, displayvalue = nil) ⇒ Object
60 61 62 63 64 65 66 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 60 def link_to_facet(field_value, field, displayvalue = nil) if field == 'genre_basic_ssim' link_to(render_format(field_value), search_catalog_path(:f => {field => [field_value]})) else link_to(displayvalue.presence || field_value, search_catalog_path(:f => {field => [field_value]})) end end |
#link_to_facets(field_values, fields, displayvalue = nil) ⇒ Object
link to a combination of facets (series + subseries, for ex)
69 70 71 72 73 74 75 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 69 def link_to_facets(field_values, fields, displayvalue = nil) facets = {} fields.each_with_index do |field, index| facets[field] = [field_values[index]] end link_to(displayvalue.presence || field_values[0], search_catalog_path(:f => facets)) end |
#link_to_field(fieldname, fieldvalue, displayvalue = nil) ⇒ Object
from psu scholarsphere TODO: this isn’t used anywhere in the app, get rid of it?
53 54 55 56 57 58 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 53 def link_to_field(fieldname, fieldvalue, displayvalue = nil) p = {:search_field => fieldname, :q => '"'+fieldvalue+'"'} link_url = search_catalog_path(p) display = displayvalue.blank? ? fieldvalue: displayvalue link_to(display, link_url) end |
#osd_nav_images(path_to_directory) ⇒ Object
returns a hash with the location of the OpenSeadragon custom images
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 145 def osd_nav_images(path_to_directory) { zoomIn: { REST: path_to_image("#{path_to_directory}/zoomin_rest.png"), GROUP: path_to_image("#{path_to_directory}/zoomin_grouphover.png"), HOVER: path_to_image("#{path_to_directory}/zoomin_hover.png"), DOWN: path_to_image("#{path_to_directory}/zoomin_pressed.png") }, zoomOut: { REST: path_to_image("#{path_to_directory}/zoomout_rest.png"), GROUP: path_to_image("#{path_to_directory}/zoomout_grouphover.png"), HOVER: path_to_image("#{path_to_directory}/zoomout_hover.png"), DOWN: path_to_image("#{path_to_directory}/zoomout_pressed.png") }, home: { REST: path_to_image("#{path_to_directory}/home_rest.png"), GROUP: path_to_image("#{path_to_directory}/home_grouphover.png"), HOVER: path_to_image("#{path_to_directory}/home_hover.png"), DOWN: path_to_image("#{path_to_directory}/home_pressed.png") }, fullpage: { REST: path_to_image("#{path_to_directory}/fullpage_rest.png"), GROUP: path_to_image("#{path_to_directory}/fullpage_grouphover.png"), HOVER: path_to_image("#{path_to_directory}/fullpage_hover.png"), DOWN: path_to_image("#{path_to_directory}/fullpage_pressed.png") }, rotateleft: { REST: path_to_image("#{path_to_directory}/rotateleft_rest.png"), GROUP: path_to_image("#{path_to_directory}/rotateleft_grouphover.png"), HOVER: path_to_image("#{path_to_directory}/rotateleft_hover.png"), DOWN: path_to_image("#{path_to_directory}/rotateleft_pressed.png") }, rotateright: { REST: path_to_image("#{path_to_directory}/rotateright_rest.png"), GROUP: path_to_image("#{path_to_directory}/rotateright_grouphover.png"), HOVER: path_to_image("#{path_to_directory}/rotateright_hover.png"), DOWN: path_to_image("#{path_to_directory}/rotateright_pressed.png") }, previous: { REST: path_to_image("#{path_to_directory}/previous_rest.png"), GROUP: path_to_image("#{path_to_directory}/previous_grouphover.png"), HOVER: path_to_image("#{path_to_directory}/previous_hover.png"), DOWN: path_to_image("#{path_to_directory}/previous_pressed.png") }, next: { REST: path_to_image("#{path_to_directory}/next_rest.png"), GROUP: path_to_image("#{path_to_directory}/next_grouphover.png"), HOVER: path_to_image("#{path_to_directory}/next_hover.png"), DOWN: path_to_image("#{path_to_directory}/next_pressed.png") } }.to_json end |
#render_format(value) ⇒ Object
show the display-friendly value for the Format facet
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 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 5 def render_format(value) case value when 'Albums' 'Albums/Scrapbooks' when 'Drawings' 'Drawings/Illustrations' when 'Maps' 'Maps/Atlases' when 'Motion pictures' 'Film/Video' when 'Music' 'Music (recordings)' when 'Objects' 'Objects/Artifacts' when 'Musical notation' 'Sheet music' when 'Sound recordings' 'Audio recordings (nonmusical)' when 'Cards' 'Postcards/Cards' when 'Correspondence' 'Letters/Correspondence' else value end end |
#render_format_index(args) ⇒ Object
32 33 34 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 32 def render_format_index(args) render_format(args[:document][args[:field]]) end |
#render_object_icon_path(format) ⇒ Object
return the path to the icon for objects with no thumbnail
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 37 def render_object_icon_path(format) case format when 'still image' icon = 'image' when 'sound recording', 'sound recording-nonmusical', 'sound recording-musical' icon = 'audio' when 'moving image' icon = 'moving-image' else icon = 'text' end "commonwealth-vlr-engine/dc_#{icon}-icon.png" end |