bento_search 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -158,30 +158,7 @@ module BentoSearchHelper
|
|
158
158
|
return counter + results.start + 1
|
159
159
|
end
|
160
160
|
|
161
|
-
|
162
|
-
# first 3 authors, each in a <span>, using item.author_display, seperated by
|
163
|
-
# semi-colons.
|
164
|
-
def bento_item_authors(item)
|
165
|
-
parts = []
|
166
|
-
|
167
|
-
first_three = item.authors.slice(0,3)
|
168
|
-
|
169
|
-
first_three.each_with_index do |author, index|
|
170
|
-
parts << content_tag("span", :class => "authors") do
|
171
|
-
item.author_display(author)
|
172
|
-
end
|
173
|
-
if (index + 1) < first_three.length
|
174
|
-
parts << "; "
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
if item.authors.length > 3
|
179
|
-
parts << I18n.t("bento_search.authors_et_al")
|
180
|
-
end
|
181
|
-
|
182
|
-
return safe_join(parts, "")
|
183
|
-
end
|
184
|
-
|
161
|
+
|
185
162
|
# returns a hash of label => key suitable for passing to rails
|
186
163
|
# options_for_select. (Yes, it works backwards from how you'd expect).
|
187
164
|
# Label is looked up using I18n, at bento_search.sort_keys.*
|
@@ -2,7 +2,19 @@ module BentoSearch
|
|
2
2
|
class StandardDecorator < DecoratorBase
|
3
3
|
|
4
4
|
|
5
|
-
#
|
5
|
+
# convenience method that returns true if any of the keys
|
6
|
+
# are #present? eg
|
7
|
+
# item.any_present?(:source_title, :authors) === item.source_title.present? || item.authors.present?
|
8
|
+
#
|
9
|
+
# note present? is false for nil, empty strings, and empty arrays.
|
10
|
+
def any_present?(*keys)
|
11
|
+
keys.each do |key|
|
12
|
+
return true if self.send(key).present?
|
13
|
+
end
|
14
|
+
return false
|
15
|
+
end
|
16
|
+
|
17
|
+
# How to display a BentoSearch::Author object as a name
|
6
18
|
def author_display(author)
|
7
19
|
if (author.first && author.last)
|
8
20
|
"#{author.last}, #{author.first.slice(0,1)}"
|
@@ -15,6 +27,66 @@ module BentoSearch
|
|
15
27
|
end
|
16
28
|
end
|
17
29
|
|
30
|
+
# display multiple authors, with HTML markup, returns html_safe string.
|
31
|
+
# experimentally trying this as a decorator helper method rather
|
32
|
+
# than a view partial, not sure which is best.
|
33
|
+
#
|
34
|
+
# Will limit to first three authors, with elipsis if there are more.
|
35
|
+
#
|
36
|
+
# Over-ride if you want to format authors names differently, or
|
37
|
+
# show more or less than first 3, etc.
|
38
|
+
def render_authors_list
|
39
|
+
parts = []
|
40
|
+
|
41
|
+
first_three = self.authors.slice(0,3)
|
42
|
+
|
43
|
+
first_three.each_with_index do |author, index|
|
44
|
+
parts << _h.content_tag("span", :class => "author") do
|
45
|
+
self.author_display(author)
|
46
|
+
end
|
47
|
+
if (index + 1) < first_three.length
|
48
|
+
parts << "; "
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if self.authors.length > 3
|
53
|
+
parts << I18n.t("bento_search.authors_et_al")
|
54
|
+
end
|
55
|
+
|
56
|
+
return _h.safe_join(parts, "")
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns source publication name OR publisher, along with volume/issue/pages
|
60
|
+
# if present, all wrapped in various tags and labels. Returns html_safe
|
61
|
+
# with tags.
|
62
|
+
#
|
63
|
+
# Experiment to do this in a decorator helper instead of a partial template,
|
64
|
+
# might be more convenient we think.
|
65
|
+
def render_source_info
|
66
|
+
parts = []
|
67
|
+
|
68
|
+
if self.source_title.present?
|
69
|
+
parts << _h.content_tag("span", I18n.t("bento_search.published_in"), :class=> "source_label")
|
70
|
+
parts << _h.content_tag("span", self.source_title, :class => "source_title")
|
71
|
+
parts << ". "
|
72
|
+
elsif self.publisher.present?
|
73
|
+
parts << _h.content_tag("span", self.publisher, :class => "publisher")
|
74
|
+
parts << ". "
|
75
|
+
end
|
76
|
+
|
77
|
+
if text = self.render_citation_details
|
78
|
+
parts << text << "."
|
79
|
+
end
|
80
|
+
|
81
|
+
return _h.safe_join(parts, "")
|
82
|
+
end
|
83
|
+
|
84
|
+
# if enough info is present that there will be non-empty render_source_info
|
85
|
+
# should be over-ridden to match display_source_info
|
86
|
+
def has_source_info?
|
87
|
+
self.any_present?(:source_title, :publisher, :start_page)
|
88
|
+
end
|
89
|
+
|
18
90
|
# Put together title and subtitle if neccesary.
|
19
91
|
def complete_title
|
20
92
|
t = self.title
|
@@ -31,33 +103,23 @@ module BentoSearch
|
|
31
103
|
|
32
104
|
|
33
105
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
# just a rough and ready display.
|
40
|
-
#
|
41
|
-
# TODO: Should this be moved to a rails helper method? Not sure.
|
42
|
-
def published_in
|
106
|
+
# volume, issue, and page numbers. With prefixed labels from I18n.
|
107
|
+
# That's it.
|
108
|
+
def render_citation_details
|
109
|
+
# \u00A0 is unicode non-breaking space to keep labels and values from
|
110
|
+
# getting separated.
|
43
111
|
result_elements = []
|
44
112
|
|
45
|
-
result_elements.push("
|
113
|
+
result_elements.push("#{I18n.t('bento_search.volume')}\u00A0#{volume}") if volume.present?
|
46
114
|
|
47
|
-
|
48
|
-
result_elements.push html_escape publisher
|
49
|
-
end
|
50
|
-
|
51
|
-
result_elements.push("#{I18n.t('bento_search.volume')} #{volume}") if volume.present?
|
52
|
-
|
53
|
-
result_elements.push("#{I18n.t('bento_search.issue')} #{issue}") if issue.present?
|
115
|
+
result_elements.push("#{I18n.t('bento_search.issue')}\u00A0#{issue}") if issue.present?
|
54
116
|
|
55
117
|
if (! start_page.blank?) && (! end_page.blank?)
|
56
|
-
result_elements.push html_escape "#{I18n.t('bento_search.pages')}
|
118
|
+
result_elements.push html_escape "#{I18n.t('bento_search.pages')}\u00A0#{start_page}-#{end_page}"
|
57
119
|
elsif ! start_page.blank?
|
58
|
-
result_elements.push html_escape "#{I18n.t('bento_search.page')}
|
120
|
+
result_elements.push html_escape "#{I18n.t('bento_search.page')}\u00A0#{start_page}"
|
59
121
|
end
|
60
|
-
|
122
|
+
|
61
123
|
return nil if result_elements.empty?
|
62
124
|
|
63
125
|
return result_elements.join(", ").html_safe
|
@@ -26,11 +26,13 @@
|
|
26
26
|
<div class="bento_item_body">
|
27
27
|
|
28
28
|
|
29
|
-
<% if item.authors
|
29
|
+
<% if item.any_present?(:authors, :year) %>
|
30
30
|
<p class="bento_item_row first_about">
|
31
31
|
|
32
32
|
<% if item.authors.length > 0 %>
|
33
|
-
|
33
|
+
<span class="authors">
|
34
|
+
<%= item.render_authors_list %>
|
35
|
+
</span>
|
34
36
|
<% end %>
|
35
37
|
|
36
38
|
<% if item.year.present? %>
|
@@ -46,12 +48,12 @@
|
|
46
48
|
</p>
|
47
49
|
<% end %>
|
48
50
|
|
49
|
-
<% if item.
|
51
|
+
<% if item.has_source_info? %>
|
50
52
|
<p class="bento_item_row second_about">
|
51
|
-
<%= item.
|
53
|
+
<%= item.render_source_info %>
|
52
54
|
</p>
|
53
55
|
<% end %>
|
54
|
-
|
56
|
+
|
55
57
|
<% if item.other_links.present? %>
|
56
58
|
<p class="bento_item_other_links">
|
57
59
|
<%= render :partial => "bento_search/link", :collection => item.other_links %>
|
data/lib/bento_search/version.rb
CHANGED