Skip to content

Commit

Permalink
AR-995 allow ref tag rewrites in resources too
Browse files Browse the repository at this point in the history
  • Loading branch information
jambun authored and marktriggs committed Jun 19, 2017
1 parent a0f6311 commit 8248348
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
20 changes: 1 addition & 19 deletions public-new/app/models/archival_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,11 @@ class ArchivalObject < Record
include TreeNodes

def parse_notes
rewrite_refs(json['notes']) if resource_uri
rewrite_refs(json['notes'], resource_uri) if resource_uri

super
end

def rewrite_refs(notes)
if notes.is_a?(Hash)
notes.each do |k, v|
if k == 'content'
ASUtils.wrap(v).each do |s|
s.gsub!(/<ref .*?target="(.+?)".*?>(.+?)<\/ref>/m, "<a href='#{resource_uri}/resolve/\\1'>\\2</a>")
end
else
rewrite_refs(v)
end
end
elsif notes.is_a?(Array)
notes.each do |note|
rewrite_refs(note)
end
end
end

def resource_uri
resolved_resource && resolved_resource['uri']
end
Expand Down
18 changes: 18 additions & 0 deletions public-new/app/models/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ def parse_container_display
containers
end

def rewrite_refs(notes, base_uri)
if notes.is_a?(Hash)
notes.each do |k, v|
if k == 'content'
ASUtils.wrap(v).each do |s|
s.gsub!(/<ref .*?target="(.+?)".*?>(.+?)<\/ref>/m, "<a href='#{base_uri}/resolve/\\1'>\\2</a>")
end
else
rewrite_refs(v, base_uri)
end
end
elsif notes.is_a?(Array)
notes.each do |note|
rewrite_refs(note, base_uri)
end
end
end

def parse_notes
notes = {}

Expand Down
8 changes: 7 additions & 1 deletion public-new/app/models/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,10 @@ def parse_cite_string
end
"#{cite} #{cite_url_and_timestamp}."
end
end

def parse_notes
rewrite_refs(json['notes'], uri)

super
end
end

0 comments on commit 8248348

Please sign in to comment.