Skip to content

Commit

Permalink
Merge pull request #941 from mlibrary/BLUEDOC-1070-format-update-to-m…
Browse files Browse the repository at this point in the history
…la-formatter-3

BLUEDOC-1070 - Formatting tweak to dataset citations - 3
  • Loading branch information
blancoj authored Mar 10, 2021
2 parents 488cd0f + 1797419 commit 880dcf7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
7 changes: 7 additions & 0 deletions app/assets/stylesheets/custom_layout/tweaks.css
Original file line number Diff line number Diff line change
Expand Up @@ -665,3 +665,10 @@ table.datatable thead th.no-sort {
.submit-button-list li {
padding: 2px
}

.citation-author {
}

.citation-title {
font-style: italic;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ def format_year(work)
end
return '' unless timestamp.present?
timestamp = to_timestamp( timestamp )
timestamp = Array(timestamp).first if timestamp.respond_to? :first
year = ''
year = timestamp.to_date.year if timestamp.present?
return year
end


def to_timestamp( arg, timestamp_format: nil )
timestamp = arg
return nil if arg.blank?
timestamp = Array( arg ).first
return timestamp if timestamp.is_a? DateTime
return timestamp.to_datetime if timestamp.is_a? Date
if timestamp_format.blank? && arg.is_a?( String )
Expand Down Expand Up @@ -125,7 +127,7 @@ def format_title(title_info)
title.strip!
# title = whitewash(title)
return '' if title.blank?
"<i class='citation-title'>#{title}</i> "
"<span class='citation-title'>#{title}</span> "
end

# def whitewash(text)
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/base/_citations.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if Hyrax.config.citations? %>
To Cite this Work:<br/>
<%= export_as_mla_citation(@presenter) %>
<%= raw export_as_mla_citation(@presenter) %>
<br/><br/>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,28 @@
describe '.format_title' do

context 'title is unmodified' do
it { expect(subject.format_title( 'Title') ).to eq "<i class='citation-title'>Title</i> " }
it { expect(subject.format_title( 'title') ).to eq "<i class='citation-title'>title</i> " }
it { expect(subject.format_title( 'A Longer Title') ).to eq "<i class='citation-title'>A Longer Title</i> " }
it { expect(subject.format_title( 'Title') ).to eq "<span class='citation-title'>Title</span> " }
it { expect(subject.format_title( 'title') ).to eq "<span class='citation-title'>title</span> " }
it { expect(subject.format_title( 'A Longer Title') ).to eq "<span class='citation-title'>A Longer Title</span> " }
end

context 'title has colons' do
it { expect(subject.format_title( 'Title: Subtitle') ).to eq "<i class='citation-title'>Title&#58; Subtitle</i> " }
it { expect(subject.format_title( 'Title: Subtitle') ).to eq "<span class='citation-title'>Title&#58; Subtitle</span> " }
end

context 'title has trailing period' do
it { expect(subject.format_title( 'Title.') ).to eq "<i class='citation-title'>Title</i> " }
it { expect(subject.format_title( 'title.') ).to eq "<i class='citation-title'>title</i> " }
it { expect(subject.format_title( 'A Longer Title.') ).to eq "<i class='citation-title'>A Longer Title</i> " }
it { expect(subject.format_title( 'Title.') ).to eq "<span class='citation-title'>Title</span> " }
it { expect(subject.format_title( 'title.') ).to eq "<span class='citation-title'>title</span> " }
it { expect(subject.format_title( 'A Longer Title.') ).to eq "<span class='citation-title'>A Longer Title</span> " }
end

context 'title is an array' do
it { expect(subject.format_title( ['Title']) ).to eq "<i class='citation-title'>Title</i> " }
it { expect(subject.format_title( ['Title', 'title part two']) ).to eq "<i class='citation-title'>Title title part two</i> " }
it { expect(subject.format_title( ['Title']) ).to eq "<span class='citation-title'>Title</span> " }
it { expect(subject.format_title( ['Title', 'title part two']) ).to eq "<span class='citation-title'>Title title part two</span> " }
end

context 'combined' do
it { expect(subject.format_title( 'Title: Subtitle.') ).to eq "<i class='citation-title'>Title&#58; Subtitle</i> " }
it { expect(subject.format_title( 'Title: Subtitle.') ).to eq "<span class='citation-title'>Title&#58; Subtitle</span> " }
end

end
Expand All @@ -85,19 +85,24 @@
let(:date_published) { DateTime.new(2020,1,1) }
it { expect(subject.to_timestamp(date_published)).to eq date_published }
it { expect(subject.to_timestamp(date_published.to_s)).to eq date_published.to_s }
it { expect(subject.to_timestamp(Array(date_published))).to eq date_published.to_s }
end

describe '.format_year' do
let(:date_published) { DateTime.new(2020,1,1) }
let(:work) { build(:work, creator: ["Doctor Creator"], title: ['The Title'], date_published: date_published )}
it { expect(subject.format_year(work)).to eq 2020 }

context 'normal year' do
let(:date_published) { DateTime.new(2020,1,1) }
let(:work) { build(:work, creator: ["Doctor Creator"], title: ['The Title'], date_published: date_published )}
it { expect(subject.format_year(work)).to eq 2020 }
end

end

describe '.format' do

context 'work with creator and title' do
let(:work) { build(:work, creator: ["Doctor Creator"], title: ['The Title'] )}
it { expect(subject.format(work) ).to eq "<span class='citation-author'>Doctor Creator.</span> <i class='citation-title'>The Title</i> [Data set]. University of Michigan - Deep Blue. " }
it { expect(subject.format(work) ).to eq "<span class='citation-author'>Doctor Creator.</span> <span class='citation-title'>The Title</span> [Data set]. University of Michigan - Deep Blue. " }
end

context 'work with creator and title and date published' do
Expand All @@ -106,7 +111,16 @@
before do
expect(work.date_published.is_a?(DateTime)).to eq true
end
it { expect(subject.format(work) ).to eq "<span class='citation-author'>Doctor Creator.</span> <i class='citation-title'>The Title</i> [Data set], (2020). University of Michigan - Deep Blue. " }
it { expect(subject.format(work) ).to eq "<span class='citation-author'>Doctor Creator.</span> <span class='citation-title'>The Title</span> [Data set], (2020). University of Michigan - Deep Blue. " }
end

context 'work with creator and title and date published' do
let(:date_published) { DateTime.new(2020,1,1) }
let(:work) { build(:work, creator: ["Doctor Creator"], title: ['The Title'] )}
before do
allow(work).to receive(:date_published).and_return [date_published]
end
it { expect(subject.format(work) ).to eq "<span class='citation-author'>Doctor Creator.</span> <span class='citation-title'>The Title</span> [Data set], (2020). University of Michigan - Deep Blue. " }
end

end
Expand Down

0 comments on commit 880dcf7

Please sign in to comment.