blacklight_range_limit 1.0.0pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +141 -0
- data/Rakefile +5 -0
- data/VERSION +1 -0
- data/app/helpers/range_limit_helper.rb +89 -0
- data/app/views/blacklight_range_limit/_range_limit_panel.html.erb +74 -0
- data/app/views/blacklight_range_limit/_range_segments.html.erb +14 -0
- data/blacklight_range_limit.gemspec +23 -0
- data/config/routes.rb +6 -0
- data/lib/blacklight_range_limit.rb +55 -0
- data/lib/blacklight_range_limit/controller_override.rb +139 -0
- data/lib/blacklight_range_limit/engine.rb +17 -0
- data/lib/blacklight_range_limit/route_sets.rb +12 -0
- data/lib/blacklight_range_limit/segment_calculation.rb +103 -0
- data/lib/blacklight_range_limit/version.rb +10 -0
- data/lib/blacklight_range_limit/view_helper_override.rb +82 -0
- data/lib/generators/blacklight_range_limit/assets_generator.rb +25 -0
- data/lib/generators/blacklight_range_limit/blacklight_range_limit_generator.rb +11 -0
- data/lib/generators/blacklight_range_limit/templates/public/javascripts/flot/excanvas.min.js +1 -0
- data/lib/generators/blacklight_range_limit/templates/public/javascripts/flot/jquery.flot.js +2513 -0
- data/lib/generators/blacklight_range_limit/templates/public/javascripts/flot/jquery.flot.selection.js +328 -0
- data/lib/generators/blacklight_range_limit/templates/public/javascripts/range_limit_distro_facets.js +211 -0
- data/lib/generators/blacklight_range_limit/templates/public/javascripts/range_limit_slider.js +83 -0
- data/lib/generators/blacklight_range_limit/templates/public/stylesheets/blacklight_range_limit.css +13 -0
- metadata +122 -0
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
BlacklightRangeLimit: integer range limiting and profiling for Blacklight applications
|
2
|
+
|
3
|
+
= Description
|
4
|
+
|
5
|
+
The BlacklightRangeLimit plugin provides a 'facet' or limit for integer fields, that lets the user enter range limits with a text box or a slider, and also provides area charts giving a sense of the distribution of values (with drill down).
|
6
|
+
|
7
|
+
The primary use case of this plugin is for 'year' data, but it should work for any integer field. It may not work right for negative numbers, however.
|
8
|
+
|
9
|
+
Decimal numbers and Dates are NOT supported; they theoretically could be in the future, although it gets tricky.
|
10
|
+
|
11
|
+
|
12
|
+
= Requirements
|
13
|
+
|
14
|
+
A Rails app using the Blacklight plugin (post version 2.5. Either git checkout from master, or wait until whatever version comes after 2.5). If you've modified and over-ridden Blacklight a lot, things might get tricky.
|
15
|
+
|
16
|
+
A Solr integer field. Depending on your data, it may or may not be advantageous to use a tint (trie with non-zero precision) type field.
|
17
|
+
|
18
|
+
==Note on solr field types==
|
19
|
+
|
20
|
+
If all your integers are the same number of digits, you can use just about any solr type, including string/type, and all will be well. But if your integers vary in digits, strings won't sort correctly, making your numbers behave oddly in partitions and limits. This is also true if you use a pre-1.4 "integer"/pint/solr.IntField field -- these are not "sortable".
|
21
|
+
|
22
|
+
You need to use a "sortable" numeric-type field. In Solr 1.4, the standard "int"/solr.TrieIntField should work fine and is probably prefered. For some distributions of data, it may be more efficient to use "tint" (solr.TrieIntField with non-zero precision).
|
23
|
+
|
24
|
+
The pre Solr 1.4 now deprecated sint or slong types should work fine too.
|
25
|
+
|
26
|
+
= Installation
|
27
|
+
|
28
|
+
This is a plugin, not a gem. Sadly, I was not able to make this a gem, Rails2 engines plugins don't work as gems, particularly the assets. A couple different ways to get the source into your vendor/plugins directory.
|
29
|
+
|
30
|
+
Go into your application directory, and run:
|
31
|
+
|
32
|
+
./script/plugin install git://github.com/projectblacklight/blacklight_range_limit.git
|
33
|
+
|
34
|
+
Later you can run ./script/plugin update blacklight_range_limit if you like.
|
35
|
+
|
36
|
+
Requires git installed on your system. There are other ways to get the plugin in there too.
|
37
|
+
|
38
|
+
OR
|
39
|
+
cd $your_app/vendor/plugins
|
40
|
+
git clone git://github.com/projectblacklight/blacklight_range_limit.git
|
41
|
+
|
42
|
+
= Configuration
|
43
|
+
|
44
|
+
You have at least one solr field you want to display as a range limit, that's why you've installed this plugin. In your config/initializers/blacklight_config.rb, that field needs to be listed in config[:facet][:field_names], and you also need to create a config[:facet][:range]["your_field] => true key.
|
45
|
+
|
46
|
+
config[:facet][:field_names] << "my_field"
|
47
|
+
config[:facet][:range]["my_field"] = true.
|
48
|
+
|
49
|
+
You should now get range limit display. More complicated configuration is available if desired, see Range Facet Configuration below.
|
50
|
+
|
51
|
+
Note that the plugin will be default inject links to the Flot JQuery plugin, and a couple dependencies. The weird way it has to do this may fail in weird configurations. You can turn this off and instead include Flot and its dependencies manually in your application, see Injection below.
|
52
|
+
|
53
|
+
You can also configure the look and feel of the Flot chart using the jQuery .data() method. On the `.facet_limit` container you want to configure, add a Flot options associative array (documented at http://people.iola.dk/olau/flot/API.txt) as the `plot-config` key. The `plot-config` key to set the `plot-config` key on the appropriate `.facet_limit` container. In order to customize the plot colors, for example, you could use this code:
|
54
|
+
|
55
|
+
$('.blacklight-year_i').data('plot-config', {
|
56
|
+
selection: { color: '#C0FF83' },
|
57
|
+
colors: ['#ffffff'],
|
58
|
+
series: { lines: { fillColor: 'rgba(255,255,255, 0.5)' }},
|
59
|
+
grid: { color: '#aaaaaa', tickColor: '#aaaaaa', borderWidth: 0 }
|
60
|
+
});
|
61
|
+
|
62
|
+
You can add this configuration in public/javascripts/application.js, or anywhere else loaded before the blacklight range limit javascript.
|
63
|
+
|
64
|
+
== A note on AJAX use
|
65
|
+
|
66
|
+
In order to calculate distribution segment ranges, we need to first know the min and max boundaries. But we don't really know that until we've fetched the result set (we use the Solr Stats component to get min and max with a result set).
|
67
|
+
|
68
|
+
So, ordinarily, after we've gotten the result set, only then can we calculate the segment ranges, and then we need to do another Solr request to actually fetch the segment range counts.
|
69
|
+
|
70
|
+
The plugin uses an AJAX request on the result page to do this. This means that for every application results display that includes any values at all in your range field, your application will get a second AJAX http request, and make a second solr request.
|
71
|
+
|
72
|
+
If you'd like to avoid this, you can turn off segment display altogether with the :segment option below; or you can set :assumed_boundaries below to use fixed boundaries for not-yet-limited segments instead of taking boundaries from the result set.
|
73
|
+
|
74
|
+
Note that a drill-down will never require the second request, because boundaries on a drill-down are always taken from the specified limits.
|
75
|
+
|
76
|
+
|
77
|
+
== Range Facet Configuration
|
78
|
+
|
79
|
+
Instead of simply passing "true", you can pass a hash with additional configuration. Here's an example with all the available keys, you don't need to use them all, just the ones you want to set to non-default values.
|
80
|
+
|
81
|
+
config[:facet][:range]["my_field"] = {
|
82
|
+
:num_segments => 6,
|
83
|
+
:assumed_boundaries => [1100, Time.now.year + 2],
|
84
|
+
:slider_js => false,
|
85
|
+
:chart_js => false,
|
86
|
+
:segments => false
|
87
|
+
}
|
88
|
+
|
89
|
+
[num_segments]
|
90
|
+
Default 10. Approximately how many segments to divide the range into for segment facets, which become segments on the chart. Actual segments are calculated to be 'nice' values, so may not exactly match your setting.
|
91
|
+
[assumed_boundaries]
|
92
|
+
Default null. For a result set that has not yet been limited, instead of taking boundaries from results and making a second AJAX request to fetch segments, just assume these given boundaries. If you'd like to avoid this second AJAX Solr call, you can set :assumed_boundaries to a two-element array of integers instead, and the assumed boundaries will always be used. Note this is live ruby code, you can put calculations in there like Time.now.year + 2.
|
93
|
+
[:slider_js]
|
94
|
+
Default true. If set to false, then the slider javascript behavior will not be loaded. Without this behavior, you will see a div with textual min and max values. You can hide that with CSS if you like.
|
95
|
+
[:chart_js]
|
96
|
+
Default true. If set to false, then the Flot area-chart is not loaded. You will instead get textual facet values for each of the segment ranges. Note that this still often will result in a second AJAX request to fetch ranges, you haven't disabled AJAX by setting :chart_js=>true. If you'd like to turn off segment ranges altogether, see :segments. If you'd like to prevent the ajax but keep segments, see :assumed_boundaries.
|
97
|
+
[:segments]
|
98
|
+
Default true. If set to false, then distribution segment facets will not be loaded at all.
|
99
|
+
|
100
|
+
== Injection
|
101
|
+
|
102
|
+
The plugin assumes it is in a Blacklight Rails app, and uses Blacklight methods, Rails methods, and standard ruby module includes to inject it's behaviors into the app.
|
103
|
+
|
104
|
+
You can turn off this injection if you like, although it will make the plugin less (or non-) functional unless you manually do similar injection. See lib/blacklight_range_limit.rb#inject! to see exactly what's going on.
|
105
|
+
|
106
|
+
In any initializer, you can set:
|
107
|
+
|
108
|
+
BlacklightRangeLimit.omit_inject = true
|
109
|
+
|
110
|
+
to turn off all injection. The plugin will be completely non-functional if you do this, of course. But perhaps you could try to re-use some of it's classes in a non-Blacklight, highly hacked Blacklight, or even non-Rails application this way.
|
111
|
+
|
112
|
+
You can also turn off injection of individual components, which could be more useful:
|
113
|
+
|
114
|
+
BlacklightRangeLimit.omit_inject = {
|
115
|
+
:css => false,
|
116
|
+
:js => false,
|
117
|
+
:flot => false,
|
118
|
+
:view_helpers => false,
|
119
|
+
:controller_mixin => false
|
120
|
+
}
|
121
|
+
|
122
|
+
[:css]
|
123
|
+
set to false and the plugin will not insert it's own CSS.
|
124
|
+
[:js]
|
125
|
+
set to false and the plugin will not insert it's own JS, which means none of your range limits will get sliders or charts. Perhaps you don't like JS, or don't like ours.
|
126
|
+
[:flot]
|
127
|
+
Normally the plugin will insert <script> links to the Flot plugin, the Flot Selection plugin, and the IE canvas emulator Flot needs on IE. Perhaps you are already including these files, or would like to include them yourself. Set to false.
|
128
|
+
[:view_helpers]
|
129
|
+
Set to false and the plugin will not insert it's own rails view helpers into the app. It will raise lots of errors if you do this, you probably don't want to.
|
130
|
+
[:controller_mixin]
|
131
|
+
The plugin mixes some methods into CatalogController, both over-riding Blacklight methods, and providing a new action of it's own. Set to false, and the plugin won't. You've basically disabled the plugin if you do this.
|
132
|
+
|
133
|
+
= Tests
|
134
|
+
|
135
|
+
There are none. This is bad I know, sorry.
|
136
|
+
|
137
|
+
= Possible future To Do
|
138
|
+
* StatsComponent replacement. We use StatsComponent to get min/max of result set, as well as missing count. StatsComponent is included on every non-drilldown request, so ranges and slider can be displayed. However, StatsComponent really can slow down the solr response with a large result set. So replace StatsComponent with other strategies. No ideal ones, we can use facet.missing to get missing count instead, but RSolr makes it harder than it should be to grab this info. We can use seperate solr queries to get min/max (sort on our field, asc and desc), but this is more complicated, more solr queries, and possibly requires redesign of AJAXy stuff, so even a lone slider can have min/max.
|
139
|
+
* tests
|
140
|
+
* In cases where an AJAX request is needed to fetch more results, don't trigger the AJAX until the range facet has actually been opened/shown. Currently it's done on page load.
|
141
|
+
* If :assumed_boundaries ends up popular, we could provide a method to fetch min and max values from entire corpus on app startup or in a rake task, and automatically use these as :assumed_boundaries.
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0pre1
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# Additional helper methods used by view templates inside this plugin.
|
2
|
+
module RangeLimitHelper
|
3
|
+
|
4
|
+
# type is 'begin' or 'end'
|
5
|
+
def render_range_input(solr_field, type)
|
6
|
+
type = type.to_s
|
7
|
+
|
8
|
+
default = params["range"][solr_field][type] if params["range"] && params["range"][solr_field] && params["range"][solr_field][type]
|
9
|
+
|
10
|
+
text_field_tag("range[#{solr_field}][#{type}]", default, :maxlength=>4, :class => "range_#{type}")
|
11
|
+
end
|
12
|
+
|
13
|
+
# type is 'min' or 'max'
|
14
|
+
# Returns smallest and largest value in current result set, if available
|
15
|
+
# from stats component response.
|
16
|
+
def range_results_endpoint(solr_field, type)
|
17
|
+
stats = stats_for_field(solr_field)
|
18
|
+
|
19
|
+
return nil unless stats
|
20
|
+
# StatsComponent returns weird min/max when there are in
|
21
|
+
# fact no values
|
22
|
+
return nil if @response.total == stats["missing"]
|
23
|
+
|
24
|
+
return stats[type].to_s.gsub(/\.0+/, '')
|
25
|
+
end
|
26
|
+
|
27
|
+
def range_display(solr_field, my_params = params)
|
28
|
+
return "" unless my_params[:range] && my_params[:range][solr_field]
|
29
|
+
|
30
|
+
hash = my_params[:range][solr_field]
|
31
|
+
|
32
|
+
if hash["missing"]
|
33
|
+
return BlacklightRangeLimit.labels[:missing]
|
34
|
+
elsif hash["begin"] || hash["end"]
|
35
|
+
if hash["begin"] == hash["end"]
|
36
|
+
return "<span class='single'>#{h(hash["begin"])}</span>".html_safe
|
37
|
+
else
|
38
|
+
return "<span class='from'>#{h(hash['begin'])}</span> to <span class='to'>#{h(hash['end'])}</span>".html_safe
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
return ""
|
43
|
+
end
|
44
|
+
|
45
|
+
# Show the limit area if:
|
46
|
+
# 1) we have a limit already set
|
47
|
+
# OR
|
48
|
+
# 2) stats show max > min, OR
|
49
|
+
# 3) count > 0 if no stats available.
|
50
|
+
def should_show_limit(solr_field)
|
51
|
+
stats = stats_for_field(solr_field)
|
52
|
+
|
53
|
+
(params["range"] && params["range"][solr_field]) ||
|
54
|
+
( stats &&
|
55
|
+
stats["max"] > stats["min"]) ||
|
56
|
+
( !stats && @response.total > 0 )
|
57
|
+
end
|
58
|
+
|
59
|
+
def stats_for_field(solr_field)
|
60
|
+
@response["stats"]["stats_fields"][solr_field] if @response["stats"] && @response["stats"]["stats_fields"]
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_range_missing(solr_field, my_params = params)
|
64
|
+
my_params = my_params.dup
|
65
|
+
my_params["range"] ||= {}
|
66
|
+
my_params["range"][solr_field] ||= {}
|
67
|
+
my_params["range"][solr_field]["missing"] = "true"
|
68
|
+
|
69
|
+
# Need to ensure there's a search_field to trick Blacklight
|
70
|
+
# into displaying results, not placeholder page. Kind of hacky,
|
71
|
+
# but works for now.
|
72
|
+
my_params["search_field"] ||= "dummy_range"
|
73
|
+
|
74
|
+
my_params
|
75
|
+
end
|
76
|
+
|
77
|
+
def add_range(solr_field, from, to, my_params = params)
|
78
|
+
my_params = my_params.dup
|
79
|
+
my_params["range"] ||= {}
|
80
|
+
my_params["range"][solr_field] ||= {}
|
81
|
+
|
82
|
+
my_params["range"][solr_field]["begin"] = from
|
83
|
+
my_params["range"][solr_field]["end"] = to
|
84
|
+
my_params["range"][solr_field].delete("missing")
|
85
|
+
|
86
|
+
return my_params
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
<%- # requires solr_config local passed in
|
2
|
+
|
3
|
+
field_config = range_config(solr_field)
|
4
|
+
-%>
|
5
|
+
|
6
|
+
<h3><%= facet_field_labels[solr_field] -%></h3>
|
7
|
+
<div class="limit_content range_limit">
|
8
|
+
<% if params["range"] &&
|
9
|
+
params["range"][solr_field] &&
|
10
|
+
( params["range"][solr_field]["begin"] ||
|
11
|
+
params["range"][solr_field]["end"] ||
|
12
|
+
params["range"][solr_field]["missing"]) %>
|
13
|
+
<div class="current">
|
14
|
+
<span class="selected"><%= range_display(solr_field) %></span> <span class="count">(<%= format_num(@response.total) %>)</span> <%= link_to "[remove]", remove_range_param(solr_field), :class=>"remove" %>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<% unless params["range"] && params["range"][solr_field] && params["range"][solr_field]["missing"] %>
|
20
|
+
<% form_tag catalog_index_path, :method => :get, :class=>"range_limit subsection range_#{solr_field}" do %>
|
21
|
+
<%= search_as_hidden_fields %>
|
22
|
+
|
23
|
+
<!-- we need to include a dummy search_field parameter if none exists,
|
24
|
+
to trick blacklight into displaying actual search results instead
|
25
|
+
of home page. Not a great solution, but easiest for now. -->
|
26
|
+
<% unless params.has_key?(:search_field) %>
|
27
|
+
<%= hidden_field_tag("search_field", "dummy_range") %>
|
28
|
+
<% end %>
|
29
|
+
|
30
|
+
<%= render_range_input(solr_field, :begin) %> - <%= render_range_input(solr_field, :end) %>
|
31
|
+
<%= submit_tag 'Limit', :class=>'submit ui-state-default ui-corner-all' %>
|
32
|
+
|
33
|
+
<% end %>
|
34
|
+
<% end %>
|
35
|
+
|
36
|
+
<!-- no results profile if missing is selected -->
|
37
|
+
<% unless params["range"] && params["range"][solr_field] && params["range"][solr_field]["missing"] %>
|
38
|
+
<!-- you can hide this if you want, but it has to be on page if you want
|
39
|
+
JS slider and calculated facets to show up, JS sniffs it. -->
|
40
|
+
<div class="profile">
|
41
|
+
|
42
|
+
<% if (min = range_results_endpoint(solr_field, :min)) &&
|
43
|
+
(max = range_results_endpoint(solr_field, :max)) %>
|
44
|
+
<div class="range subsection <%= "slider_js" unless field_config[:slider_js] == false %>">
|
45
|
+
Current results range from <span class="min"><%= range_results_endpoint(solr_field, :min) %></span> to <span class="max"><%= range_results_endpoint(solr_field, :max) %></span>
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<% if field_config[:segments] != false %>
|
49
|
+
<div class="distribution subsection <%= 'chart_js' unless field_config[:chart_js] == false %>">
|
50
|
+
<!-- if we already fetched segments from solr, display them
|
51
|
+
here. Otherwise, display a link to fetch them, which JS
|
52
|
+
will AJAX fetch. -->
|
53
|
+
<% if solr_range_queries_to_a(solr_field).length > 0 %>
|
54
|
+
|
55
|
+
<%= render(:partial => "blacklight_range_limit/range_segments", :locals => {:solr_field => solr_field}) %>
|
56
|
+
|
57
|
+
<% else %>
|
58
|
+
<%= link_to('View distribution', params.merge(:action => 'range_limit', :range_field => solr_field, :range_start => min, :range_end => max), :class => "load_distribution") %>
|
59
|
+
<% end %>
|
60
|
+
</div>
|
61
|
+
<% end %>
|
62
|
+
<% end %>
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
<% if (stats = stats_for_field(solr_field)) && stats["missing"] > 0 %>
|
67
|
+
<div class="missing subsection">
|
68
|
+
<%= link_to BlacklightRangeLimit.labels[:missing], add_range_missing(solr_field) %> <%= render_facet_count(stats["missing"]) %>
|
69
|
+
</div>
|
70
|
+
<% end %>
|
71
|
+
</div>
|
72
|
+
<% end %>
|
73
|
+
</div>
|
74
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<% # must pass in local variable :solr_field
|
2
|
+
%>
|
3
|
+
|
4
|
+
<ul>
|
5
|
+
<% solr_range_queries_to_a(solr_field).each do |hash| %>
|
6
|
+
<li><%= link_to(
|
7
|
+
content_tag("span", hash[:from], :class => "from") +
|
8
|
+
" to " +
|
9
|
+
content_tag("span", hash[:to], :class => "to"),
|
10
|
+
add_range(solr_field, hash[:from], hash[:to]).merge(:action => "index"),
|
11
|
+
:class => "facet_select"
|
12
|
+
) %> (<%= content_tag("span", hash[:count], :class=>"count")%>)</li>
|
13
|
+
<% end %>
|
14
|
+
</ul>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "lib/blacklight_range_limit/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "blacklight_range_limit"
|
6
|
+
s.version = BlacklightRangeLimit::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Jonathan Rochkind"]
|
9
|
+
s.email = ["blacklight-development@googlegroups.com"]
|
10
|
+
s.homepage = "http://projectblacklight.org/"
|
11
|
+
s.summary = "Blacklight Range Limit plugin"
|
12
|
+
|
13
|
+
s.rubyforge_project = "blacklight"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
|
21
|
+
s.add_dependency "rails", "~> 3.0"
|
22
|
+
s.add_dependency "blacklight"
|
23
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# BlacklightRangeLimit
|
2
|
+
|
3
|
+
module BlacklightRangeLimit
|
4
|
+
autoload :ControllerOverride, 'blacklight_range_limit/controller_override'
|
5
|
+
autoload :ViewHelperOverride, 'blacklight_range_limit/view_helper_override'
|
6
|
+
autoload :RouteSets, 'blacklight_range_limit/route_sets'
|
7
|
+
|
8
|
+
require 'blacklight_range_limit/version'
|
9
|
+
require 'blacklight_range_limit/engine'
|
10
|
+
|
11
|
+
mattr_accessor :labels
|
12
|
+
self.labels = {
|
13
|
+
:missing => "Unknown"
|
14
|
+
}
|
15
|
+
|
16
|
+
|
17
|
+
@omit_inject = {}
|
18
|
+
def self.omit_inject=(value)
|
19
|
+
value = Hash.new(true) if value == true
|
20
|
+
@omit_inject = value
|
21
|
+
end
|
22
|
+
def self.omit_inject ; @omit_inject ; end
|
23
|
+
|
24
|
+
def self.inject!
|
25
|
+
unless omit_inject[:controller_mixin]
|
26
|
+
CatalogController.send(:include, BlacklightRangeLimit::ControllerOverride) unless Blacklight::Catalog.include?(BlacklightRangeLimit::ControllerOverride)
|
27
|
+
end
|
28
|
+
|
29
|
+
unless omit_inject[:view_helpers]
|
30
|
+
SearchHistoryController.send(:helper,
|
31
|
+
BlacklightRangeLimit::ViewHelperOverride
|
32
|
+
) unless
|
33
|
+
SearchHistoryController.helpers.is_a?(
|
34
|
+
BlacklightRangeLimit::ViewHelperOverride
|
35
|
+
)
|
36
|
+
|
37
|
+
SearchHistoryController.send(:helper,
|
38
|
+
RangeLimitHelper
|
39
|
+
) unless
|
40
|
+
SearchHistoryController.helpers.is_a?(
|
41
|
+
RangeLimitHelper
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
unless BlacklightRangeLimit.omit_inject[:routes]
|
46
|
+
Blacklight::Routes.send(:include, BlacklightRangeLimit::RouteSets)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Add element to array only if it's not already there
|
51
|
+
def self.safe_arr_add(array, element)
|
52
|
+
array << element unless array.include?(element)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|