Module: ResolveHelper
- Defined in:
- app/helpers/resolve_helper.rb
Constant Summary collapse
- @@bg_update_sections =
Methods to grab SectionRenderer definitions from config. Caching in class-level variables.
nil
- @@partial_update_sections =
nil
Instance Method Summary collapse
- #app_name ⇒ Object
-
#bg_update_sections ⇒ Object
Called by background updater to get a list of all sections configured in application config parameter resolve_sections to be included in background updates.
-
#cover_image_response(size = 'medium') ⇒ Object
size can be ‘small’, ‘medium’, or ‘large.
- #display_not_found_warning?(uml_request) ⇒ Boolean
-
#expand_contract_section(arg_heading, id, options = {}, &block) ⇒ Object
Generate content in an expand-contract block, with a heading that you can click on to show/hide it.
- #html_section_by_div_id(div_id) ⇒ Object
-
#html_sections(area) ⇒ Object
Called by resolve/index view to find sections configured in application config resolve_sections list for a specific part of the page.
-
#list_with_limit(id, list, options = {}, &block) ⇒ Object
Code-generating helper to add a “More” link to a list, with a maximum number of items to show before ‘more’.
-
#partial_html_sections ⇒ Object
Called by partial_html_sections action to get a list of all sections that should be included in the partial_html_sections api response.
-
#render_section(arguments = {}) ⇒ Object
Will render an Umlaut HTML section.
-
#response_content(service_response) ⇒ Object
If response has a :content key returns it – and marks it html_safe if response has a :content_html_safe == true key.
-
#user_entered_citation?(uml_request) ⇒ Boolean
Did this come from citation linker style entry? We check the referrer.
Instance Method Details
#app_name ⇒ Object
40 41 42 |
# File 'app/helpers/resolve_helper.rb', line 40 def app_name return umlaut_config.app_name end |
#bg_update_sections ⇒ Object
Called by background updater to get a list of all sections configured in application config parameter resolve_sections to be included in background updates.
205 206 207 208 209 210 211 212 |
# File 'app/helpers/resolve_helper.rb', line 205 def bg_update_sections unless (@@bg_update_sections) @@bg_update_sections = umlaut_config.lookup!("resolve_sections", []).find_all do |section| section[:bg_update] != false end end @@bg_update_sections end |
#cover_image_response(size = 'medium') ⇒ Object
size can be ‘small’, ‘medium’, or ‘large. returns a ServiceResponse object, or nil.
47 48 49 50 51 52 53 |
# File 'app/helpers/resolve_helper.rb', line 47 def cover_image_response(size='medium') cover_images = get_service_type('cover_image') cover_images.each do |service_response| return service_response if service_response.service_data[:size] == size end return nil end |
#display_not_found_warning?(uml_request) ⇒ Boolean
66 67 68 69 70 71 |
# File 'app/helpers/resolve_helper.rb', line 66 def display_not_found_warning?(uml_request) = uml_request.referent. display_manually_entered_typo_warning = umlaut_config.lookup!("entry_not_in_kb_warning", false) return (['genre'] != 'book' && ['object_id'].blank? && user_entered_citation?(@user_request) && display_manually_entered_typo_warning) end |
#expand_contract_section(arg_heading, id, options = {}, &block) ⇒ Object
Generate content in an expand-contract block, with a heading that you can click on to show/hide it. Actual content in block. Example, in view:
<% expand_contract_section("My Content", "div_id_to_use") do %>
this will be hidden and shown
<% end %>
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/helpers/resolve_helper.rb', line 80 def (arg_heading, id, ={}, &block) = (params["umlaut.show_#{id}"] == "true") || [:initial_expand] || false icon = image_tag( ( ? "list_open.png" : "list_closed.png"), :alt => "", :class => "toggle_icon", :border => "0") heading = content_tag(:span,( ? "Hide " : "Show "), :class=>'expand_contract_action_label') + arg_heading link_params = params.merge('umlaut.request_id' => @user_request.id, "umlaut.show_#{id}" => (! ).to_s , # Need to zero out format-related params for when we're coming # from a partial html api request, so the link we generate # is not to format json/xml/etc. :format => nil, 'umlaut.response_format' => nil, 'umlaut.jsonp'=>nil, # In Rails3, an :anchor param will actually be used for #fragmentIdentifier # on end of url :anchor => "#{id}_toggle_link" ) # Make sure a self-referencing link from partial_html_sections # really goes to full HTML view. link_params[:action] = "index" if link_params[:action] == "partial_html_sections" return content_tag(:div, :class => "expand_contract_section") do link_to( icon + heading, link_params, :id => "#{id}_toggle_link", :class => "expand_contract_toggle" ) + "\n" + content_tag(:div, :id => id, :class => "expand_contract_content", :style => ("display: none;" unless ), &block) end end |
#html_section_by_div_id(div_id) ⇒ Object
234 235 236 237 238 |
# File 'app/helpers/resolve_helper.rb', line 234 def html_section_by_div_id(div_id) umlaut_config.lookup!("resolve_sections", []).find do |defn| defn[:div_id] == div_id end end |
#html_sections(area) ⇒ Object
Called by resolve/index view to find sections configured in application config resolve_sections list for a specific part of the page. :main, :sidebar, or :resource_info.
228 229 230 231 232 |
# File 'app/helpers/resolve_helper.rb', line 228 def html_sections(area) umlaut_config.lookup!("resolve_sections", []).find_all do |section| section[:html_area] == area end end |
#list_with_limit(id, list, options = {}, &block) ⇒ Object
Code-generating helper to add a “More” link to a list, with a maximum number of items to show before ‘more’. AJAXy show, with unobtrusive degredation when no javascript. Based on the idea here for a helper that takes a block. Uses expand_contract_section for actual hidden overflow. Will split list into two different <ul>‘s, one before the cut and one after. Will generate <ul> tags itself. blog.zmok.net/articles/2008/04/22/block-level-helpers-in-ruby-on-rails
id: id to use for HTML div for hidden part of list. Other ids
will be based on this id too.
list: your list limit: how many lines to show before cut off. Default 5. Note that
at least two items will always be included in 'more'. If cutoff
is 5 and your list is 5, all 5 will be shown. If cut-off is 5
and list is 6, 4 items will be shown, with more. This is five
total lines if the 'more' is considered a line.
block: will be passed |item, index|, should generate html for that
item in block.
Example, in a view: <% list_with_limit(“div_id_for_list”, list, :limit=>10) do |item, index| %>
<li>Item Number: <%= index %>: <%= item.title %></li>
<% end %>
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 |
# File 'app/helpers/resolve_helper.rb', line 160 def list_with_limit(id, list, = {}, &block) # backwards compatible to when third argument was just a number # for limit. = {:limit => } unless .kind_of?(Hash) [:limit] ||= 5 return "" if list.empty? content = "".html_safe content << content_tag(:ul, :class => [:ul_class]) do list.slice(0, [:limit]).enum_for(:each_with_index).collect do |item, index| yield(item, index) end.join(" \n ").html_safe end if (list.length > [:limit] ) content << ("#{list.length - [:limit] } more", id) do content_tag(:ul, :class=>[:ul_class]) do list.slice([:limit]..list.length-1).enum_for(:each_with_index).each do |item, index| yield(item, index + [:limit]) end.join(" \n ").html_safe end end end return content end |
#partial_html_sections ⇒ Object
Called by partial_html_sections action to get a list of all sections that should be included in the partial_html_sections api response.
216 217 218 219 220 221 222 223 |
# File 'app/helpers/resolve_helper.rb', line 216 def partial_html_sections unless (@@partial_update_sections) @@partial_update_sections = umlaut_config.lookup!("resolve_sections", []).find_all do |section| section[:partial_html_api] != false end end @@partial_update_sections end |
#render_section(arguments = {}) ⇒ Object
Will render an Umlaut HTML section. See SectionRenderer. Argument can be:
-
An already initialized SectionRenderer
-
:id => X, will load Section description hash from the resolve_sections configuration, finding description hash with :div_id == X.
-
A complete section description hash. Ordinarily only used when that complete hash was previously looked up from resolve_sections config.
For documentation of possible values in the section descripton hash, see SectionRenderer.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/resolve_helper.rb', line 26 def render_section(arguments = {}) if arguments.kind_of?( SectionRenderer ) presenter = arguments else presenter = SectionRenderer.new(@user_request, arguments ) end render(:partial => "section_display", :locals => {:presenter => presenter } ) end |
#response_content(service_response) ⇒ Object
If response has a :content key returns it – and marks it html_safe if response has a :content_html_safe == true key. returns false if no :content.
124 125 126 127 128 129 130 131 |
# File 'app/helpers/resolve_helper.rb', line 124 def response_content(service_response) content = service_response[:content] return false unless content content = content.html_safe if service_response[:content_html_safe] == true return content end |
#user_entered_citation?(uml_request) ⇒ Boolean
Did this come from citation linker style entry? We check the referrer.
59 60 61 62 63 64 |
# File 'app/helpers/resolve_helper.rb', line 59 def user_entered_citation?(uml_request) return false unless uml_request && uml_request.referrer_id id = uml_request.referrer_id return id == 'info:sid/sfxit.com:citation' || id == umlaut_config.lookup("rfr_ids.citation") || id == umlaut_config.lookup('rfr_ids.opensearch') end |