• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / orangelight / 00dbc10b-d747-4ad7-b211-7b26d753abbb

14 Aug 2025 01:25PM UTC coverage: 0.483% (-94.9%) from 95.343%
00dbc10b-d747-4ad7-b211-7b26d753abbb

push

circleci

web-flow
Merge pull request #5181 from pulibrary/dependabot/bundler/activestorage-7.2.2.2

Bump activestorage from 7.2.2.1 to 7.2.2.2

47 of 9721 relevant lines covered (0.48%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/services/online_holdings_markup_builder.rb
1
# frozen_string_literal: false
2

3
class OnlineHoldingsMarkupBuilder < HoldingRequestsBuilder
×
4
  # Generate a block of markup for an online holding
5
  # @param bib_id [String] the ID for the SolrDocument
6
  # @param holding_id [String] the ID for the holding
7
  # @return [String] the markup
8
  def self.online_link(bib_id, holding_id)
×
9
    children = content_tag(
×
10
      :span, 'Link Missing',
×
11
      class: 'lux-text-style gray strong'
×
12
    )
×
13
    # AJAX requests are made using availability.js here
14
    content_tag(:div, children.html_safe,
×
15
                class: 'holding-block',
×
16
                data: {
×
17
                  availability_record: true,
×
18
                  record_id: bib_id,
×
19
                  holding_id:
×
20
                })
×
21
  end
×
22

23
  # Generate the link for electronic access information within a record
24
  # @param url [String] the URL to the service endpoint
25
  # @param text [String] the label for the link
26
  def self.electronic_access_link(url, texts)
×
27
    markup = if /Open access/.match? texts.first
×
28
               link_to(texts.first, url.to_s, target: '_blank', rel: 'noopener', class: 'electronic-access-link')
×
29
             elsif %r{(\/catalog\/.+?#view)} =~ url.to_s
×
30
               if texts.first == "arks.princeton.edu"
×
31
                 link_to('Digital content', ::Regexp.last_match(0), class: 'electronic-access-link')
×
32
               else
×
33
                 link_to(texts.first, ::Regexp.last_match(0), class: 'electronic-access-link')
×
34
               end
×
35
             else
×
36
               link_text = new_tab_icon(texts.first)
×
37
               link_to(link_text, EzProxyService.ez_proxy_url(url), target: '_blank', rel: 'noopener', class: 'electronic-access-link')
×
38
             end
×
39
    markup
×
40
  end
×
41

42
  # Method for cleaning URLs
43
  # @param url [String] the URL for an online holding
44
  # @return [String] the cleaned URL
45
  def self.clean_url(url)
×
46
    if /go\.galegroup\.com.+?%257C/.match? url
×
47
      URI.decode_www_form_component(url)
×
48
    else
×
49
      url
×
50
    end
×
51
  end
×
52

53
  # Generate the markup for the electronic access block
54
  # First argument of link_to is optional display text. If null, the second argument
55
  # (URL) is the display text for the link.
56
  # Proxy Base is added to force remote access when appropriate
57
  # @param adapter [HoldingRequestsAdapter] the adapter for Solr and Bibdata
58
  # @return [String] the markup
59
  def self.urlify(adapter)
×
60
    markup = ''
×
61

62
    electronic_access = adapter.doc_electronic_access
×
63
    electronic_access.each do |url, electronic_texts|
×
64
      texts = electronic_texts.flatten
×
65
      url = clean_url(url)
×
66

67
      link = electronic_access_link(url, texts)
×
68
      link = "#{texts[1]}: " + link if texts[1]
×
69
      link = "<li>#{link}</li>" if electronic_access.many?
×
70
      markup << content_tag(:li, link.html_safe, class: 'electronic-access')
×
71
    end
×
72

73
    return content_tag(:ul, markup.html_safe) if electronic_access.many?
×
74
    markup
×
75
  end
×
76

77
  # Returns electronic portforlio link markup.
78
  # Replaces Umlaut AJAX data when using Alma.
79
  # @param adapter [HoldingRequestsAdapter] the adapter for Solr and Bibdata
80
  # @return [String] the markup
81
  def self.electronic_portfolio_markup(adapter)
×
82
    markup = ''
×
83

84
    portfolios = adapter.electronic_portfolios + adapter.sibling_electronic_portfolios
×
85
    return '' if portfolios.present? && portfolios[0].key?('thesis')
×
86
    portfolios.each do |portfolio|
×
87
      start_date = portfolio['start']
×
88
      end_date = portfolio['end']
×
89
      date_range = "#{start_date} - #{end_date}: " if start_date && end_date
×
90
      label = new_tab_icon("#{date_range}#{portfolio['title']}")
×
91
      link = link_to(label, portfolio["url"], target: '_blank', rel: 'noopener', class: 'electronic-access-link')
×
92
      link += "<br/><lux-show-more v-bind:character-limit=150 show-label='See more' hide-label='See less'>#{portfolio['desc']}</lux-show-more>".html_safe
×
93

94
      link = "#{link} (#{portfolio['notes'].join(', ')})" if portfolio['notes']&.any?
×
95
      markup << content_tag(:li, link.html_safe, class: 'electronic-access lux')
×
96
    end
×
97

98
    markup
×
99
  end
×
100

101
  def self.new_tab_icon(text)
×
102
    text = text.html_safe
×
103
    text + content_tag(:i, "", class: "fa fa-external-link new-tab-icon-padding", "aria-label": "opens in new tab", role: "img")
×
104
  end
×
105

106
  # Constructor
107
  # @param adapter [HoldingRequestsAdapter] adapter for the SolrDocument and Bibdata API
108
  def initialize(adapter)
×
109
    @adapter = adapter
×
110
  end
×
111

112
  # Builds the markup for online and physical holdings for a given record
113
  # @return [Array<String>] the markup for the online and physical holdings
114
  def build
×
115
    online_holdings_block
×
116
  end
×
117

118
  private
×
119

120
    # Generate the markup for the online holdings
121
    # @return [String] the markup
122
    def online_holdings
×
123
      markup = ''
×
124

125
      electronic_access_links = self.class.urlify(@adapter)
×
126
      markup << electronic_access_links
×
127
      elf_holdings = @adapter.doc_holdings_elf
×
128

129
      if electronic_access_links.empty?
×
130
        elf_holdings.each_key do |holding_id|
×
131
          markup << self.class.online_link(@adapter.doc_id, holding_id)
×
132
        end
×
133
      end
×
134

135
      # For Alma records, add links from the electronic portfolio field
136
      markup << self.class.electronic_portfolio_markup(@adapter)
×
137

138
      markup
×
139
    end
×
140

141
    # Generate the markup for the online holdings block
142
    # @return [String] the markup
143
    def online_holdings_block
×
144
      markup = ''
×
145
      children = online_holdings
×
146
      markup = self.class.content_tag(:ul, children.html_safe) unless children.empty?
×
147
      markup
×
148
    end
×
149
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc