blacklight_range_limit 8.4.0 → 9.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +117 -23
  3. data/.gitignore +2 -0
  4. data/.solr_wrapper.yml +8 -0
  5. data/Gemfile +7 -1
  6. data/README.md +77 -86
  7. data/Rakefile +31 -0
  8. data/VERSION +1 -1
  9. data/app/assets/javascripts/blacklight-range-limit/index.js +345 -0
  10. data/app/components/blacklight_range_limit/range_facet_component.html.erb +29 -27
  11. data/app/components/blacklight_range_limit/range_facet_component.rb +15 -9
  12. data/app/components/blacklight_range_limit/range_form_component.html.erb +13 -5
  13. data/app/components/blacklight_range_limit/range_form_component.rb +8 -20
  14. data/app/presenters/blacklight_range_limit/facet_field_presenter.rb +13 -2
  15. data/app/presenters/blacklight_range_limit/facet_item_presenter.rb +6 -11
  16. data/app/presenters/blacklight_range_limit/filter_field.rb +2 -2
  17. data/blacklight_range_limit.gemspec +1 -1
  18. data/config/importmap.rb +9 -0
  19. data/config/locales/blacklight_range_limit.ar.yml +13 -8
  20. data/config/locales/blacklight_range_limit.de.yml +13 -8
  21. data/config/locales/blacklight_range_limit.en.yml +5 -1
  22. data/config/locales/blacklight_range_limit.es.yml +18 -0
  23. data/config/locales/blacklight_range_limit.it.yml +13 -8
  24. data/lib/blacklight_range_limit/controller_override.rb +1 -25
  25. data/lib/blacklight_range_limit/engine.rb +48 -0
  26. data/lib/blacklight_range_limit/range_limit_builder.rb +40 -3
  27. data/lib/blacklight_range_limit.rb +8 -31
  28. data/lib/generators/blacklight_range_limit/assets_generator.rb +82 -18
  29. data/lib/generators/blacklight_range_limit/install_generator.rb +1 -1
  30. data/lib/generators/blacklight_range_limit/jsbundling_bl7_fixup_generator.rb +98 -0
  31. data/package-lock.json +51 -0
  32. data/package.json +10 -11
  33. data/spec/components/range_facet_component_spec.rb +41 -32
  34. data/spec/components/range_form_component_spec.rb +2 -2
  35. data/spec/components/range_segments_component_spec.rb +64 -0
  36. data/spec/features/blacklight_range_limit_spec.rb +21 -13
  37. data/spec/features/run_through_spec.rb +157 -0
  38. data/spec/presenters/facet_field_presenter_spec.rb +72 -0
  39. data/spec/presenters/filter_field_spec.rb +36 -1
  40. data/spec/spec_helper.rb +10 -0
  41. data/spec/test_app_templates/Gemfile.extra +11 -1
  42. data/spec/test_app_templates/lib/generators/test_app_generator.rb +37 -6
  43. metadata +26 -44
  44. data/app/assets/javascripts/blacklight_range_limit/range_limit_distro_facets.js +0 -77
  45. data/app/assets/javascripts/blacklight_range_limit/range_limit_plotting.js +0 -185
  46. data/app/assets/javascripts/blacklight_range_limit/range_limit_shared.js +0 -73
  47. data/app/assets/javascripts/blacklight_range_limit/range_limit_slider.js +0 -161
  48. data/app/assets/javascripts/blacklight_range_limit.js +0 -25
  49. data/app/assets/stylesheets/blacklight_range_limit/blacklight_range_limit.css +0 -60
  50. data/app/assets/stylesheets/blacklight_range_limit.css +0 -7
  51. data/app/helpers/range_limit_helper.rb +0 -130
  52. data/app/views/blacklight_range_limit/_range_segments.html.erb +0 -8
  53. data/app/views/blacklight_range_limit/range_segments.html.erb +0 -1
  54. data/app/views/catalog/range_limit_panel.html.erb +0 -1
  55. data/spec/features/a_javascript_spec.rb +0 -70
  56. data/spec/helpers/blacklight_range_limit_helper_spec.rb +0 -37
  57. data/vendor/assets/javascripts/bootstrap-slider.js +0 -388
  58. data/vendor/assets/javascripts/flot/jquery.canvaswrapper.js +0 -549
  59. data/vendor/assets/javascripts/flot/jquery.colorhelpers.js +0 -199
  60. data/vendor/assets/javascripts/flot/jquery.event.drag.js +0 -145
  61. data/vendor/assets/javascripts/flot/jquery.flot.browser.js +0 -98
  62. data/vendor/assets/javascripts/flot/jquery.flot.drawSeries.js +0 -662
  63. data/vendor/assets/javascripts/flot/jquery.flot.hover.js +0 -359
  64. data/vendor/assets/javascripts/flot/jquery.flot.js +0 -2818
  65. data/vendor/assets/javascripts/flot/jquery.flot.saturated.js +0 -43
  66. data/vendor/assets/javascripts/flot/jquery.flot.selection.js +0 -527
  67. data/vendor/assets/javascripts/flot/jquery.flot.uiConstants.js +0 -10
  68. data/vendor/assets/stylesheets/slider.css +0 -138
@@ -1,13 +1,18 @@
1
+ ---
1
2
  ar:
2
3
  blacklight:
3
4
  range_limit:
5
+ loading_html: تحميل
6
+ missing: غير معروف
4
7
  range_begin: "%{field_label} بداية المدة"
8
+ range_begin_short: يبدأ
5
9
  range_end: "%{field_label} نهاية المدة"
6
- submit_limit: 'تطبيق'
7
- remove_limit: 'حذف'
8
- missing: 'غير معروف'
9
- view_distribution: 'عرض التوزيع'
10
- view_larger: 'عرض بحجم أكبر »'
11
- results_range_html: 'تمتد النتائج الحالية من <span class="min">%{min}</span> إلى<span class="max">%{max}</span>'
12
- single_html: '<span class="single" data-blrl-single="%{begin_value}">%{begin}</span>'
13
- range_html: '<span class="from" data-blrl-begin="%{begin_value}">%{begin}</span> الى <span class="to" data-blrl-end="%{end_value}">%{end}</span>'
10
+ range_end_short: نهاية
11
+ range_html: <span class="from" data-blrl-begin="%{begin_value}">%{begin}</span> الى <span class="to" data-blrl-end="%{end_value}">%{end}</span>
12
+ range_list_heading: قائمة النطاق
13
+ remove_limit: حذف
14
+ results_range_html: تمتد النتائج الحالية من <span class="min">%{min}</span> إلى<span class="max">%{max}</span>
15
+ single_html: <span class="single" data-blrl-single="%{begin_value}">%{begin}</span>
16
+ submit_limit: تطبيق
17
+ view_distribution: عرض التوزيع
18
+ view_larger: عرض بحجم أكبر »
@@ -1,13 +1,18 @@
1
+ ---
1
2
  de:
2
3
  blacklight:
3
4
  range_limit:
5
+ loading_html: Laden...
6
+ missing: Unbekannt
4
7
  range_begin: "%{field_label} Bereichsanfang"
8
+ range_begin_short: Beginnen
5
9
  range_end: "%{field_label} Bereichsende"
6
- submit_limit: 'Anwenden'
7
- remove_limit: 'Entfernen'
8
- missing: 'Unbekannt'
9
- view_distribution: 'Verteilung Anzeigen'
10
- view_larger: 'Größer anzeigen »'
11
- results_range_html: 'Aktuelle Ergebnisse reichen von <span class="min">%{min}</span> bis <span class="max">%{max}</span>'
12
- single_html: '<span class="single" data-blrl-single="%{begin_value}">%{begin}</span>'
13
- range_html: '<span class="from" data-blrl-begin="%{begin_value}">%{begin}</span> bis <span class="to" data-blrl-end="%{end_value}">%{end}</span>'
10
+ range_end_short: Ende
11
+ range_html: <span class="from" data-blrl-begin="%{begin_value}">%{begin}</span> bis <span class="to" data-blrl-end="%{end_value}">%{end}</span>
12
+ range_list_heading: Bereichsliste
13
+ remove_limit: Entfernen
14
+ results_range_html: Aktuelle Ergebnisse reichen von <span class="min">%{min}</span> bis <span class="max">%{max}</span>
15
+ single_html: <span class="single" data-blrl-single="%{begin_value}">%{begin}</span>
16
+ submit_limit: Anwenden
17
+ view_distribution: Verteilung Anzeigen
18
+ view_larger: Größer anzeigen »
@@ -2,8 +2,10 @@ en:
2
2
  blacklight:
3
3
  range_limit:
4
4
  range_begin: "%{field_label} range begin"
5
+ range_begin_short: "Begin"
5
6
  range_end: "%{field_label} range end"
6
- submit_limit: 'Apply'
7
+ range_end_short: "End"
8
+ submit_limit: 'Apply limit'
7
9
  remove_limit: 'remove'
8
10
  missing: 'Unknown'
9
11
  view_distribution: 'View distribution'
@@ -11,3 +13,5 @@ en:
11
13
  results_range_html: 'Current results range from <span class="min">%{min}</span> to <span class="max">%{max}</span>'
12
14
  single_html: '<span class="single" data-blrl-single="%{begin_value}">%{begin}</span>'
13
15
  range_html: '<span class="from" data-blrl-begin="%{begin_value}">%{begin}</span> to <span class="to" data-blrl-end="%{end_value}">%{end}</span>'
16
+ loading_html: "Loading..."
17
+ range_list_heading: "Range List"
@@ -0,0 +1,18 @@
1
+ ---
2
+ es:
3
+ blacklight:
4
+ range_limit:
5
+ loading_html: Cargando...
6
+ missing: Desconocido
7
+ range_begin: Rango %{field_label} inicio
8
+ range_begin_short: Comenzar
9
+ range_end: Fin del rango %{field_label}
10
+ range_end_short: Fin
11
+ range_html: <span class="from" data-blrl-begin="%{begin_value}">%{begin}</span> a <span class="to" data-blrl-end="%{end_value}">%{end}</span>
12
+ range_list_heading: Lista de rangos
13
+ remove_limit: eliminar
14
+ results_range_html: Los resultados actuales varían de <span class="min">%{min}</span> a <span class="max">%{max}</span>
15
+ single_html: <span class="single" data-blrl-single="%{begin_value}">%{begin}</span>
16
+ submit_limit: Aplicar
17
+ view_distribution: Ver distribución
18
+ view_larger: Ver más grande »
@@ -1,13 +1,18 @@
1
+ ---
1
2
  it:
2
3
  blacklight:
3
4
  range_limit:
5
+ loading_html: Caricamento...
6
+ missing: Data sconosciuta
4
7
  range_begin: "%{field_label} da"
8
+ range_begin_short: Inizio
5
9
  range_end: "%{field_label} a"
6
- submit_limit: 'Invia'
7
- remove_limit: 'cancella'
8
- missing: 'Data sconosciuta'
9
- view_distribution: 'Visualizzazione della distribuzione'
10
- view_larger: 'Visualizza più grande »'
11
- results_range_html: 'Risultati attuali vanno da <span class="min">%{min}</span> a <span class="max">%{max}</span>'
12
- single_html: '<span class="single" data-blrl-single="%{begin_value}">%{begin}</span>'
13
- range_html: '<span class="from" data-blrl-begin="%{begin_value}">%{begin}</span> a <span class="to" data-blrl-end="%{end_value}">%{end}</span>'
10
+ range_end_short: Fine
11
+ range_html: <span class="from" data-blrl-begin="%{begin_value}">%{begin}</span> a <span class="to" data-blrl-end="%{end_value}">%{end}</span>
12
+ range_list_heading: Elenco intervalli
13
+ remove_limit: cancella
14
+ results_range_html: Risultati attuali vanno da <span class="min">%{min}</span> a <span class="max">%{max}</span>
15
+ single_html: <span class="single" data-blrl-single="%{begin_value}">%{begin}</span>
16
+ submit_limit: Invia
17
+ view_distribution: Visualizzazione della distribuzione
18
+ view_larger: Visualizza più grande »
@@ -4,31 +4,12 @@
4
4
  require 'blacklight_range_limit/segment_calculation'
5
5
  module BlacklightRangeLimit
6
6
  module ControllerOverride
7
- extend Deprecation
8
7
  extend ActiveSupport::Concern
9
8
 
10
9
  RANGE_LIMIT_FIELDS = [:range_end, :range_field, :range_start].freeze
11
10
 
12
11
  included do
13
12
  before_action do
14
- template = lookup_context.find_all('blacklight_range_limit/range_limit_panel', lookup_context.prefixes + [""], true, [:field_name], {}).first
15
-
16
- if template
17
- fields = blacklight_config.facet_fields.select { |_k, v| v.range && !v.had_existing_component_configuration }
18
-
19
- fields.each_value do |facet_config|
20
- Deprecation.warn(BlacklightRangeLimit, 'Found partial blacklight_range_limit/range_limit_panel, so falling back to legacy behavior.') unless facet_config.partial
21
- facet_config.partial ||= 'blacklight_range_limit/range_limit_panel'
22
- facet_config.component = nil
23
- end
24
- else
25
- fields = blacklight_config.facet_fields.select { |_k, v| v.partial == 'blacklight_range_limit/range_limit_panel' }
26
- fields.each_value do |facet_config|
27
- Deprecation.warn(BlacklightRangeLimit, 'Ignoring partial configuration for missing blacklight_range_limit/range_limit_panel partial')
28
- facet_config.partial = nil
29
- end
30
- end
31
-
32
13
  # Blacklight 7.25+: Allow range limit params if necessary
33
14
  if blacklight_config.search_state_fields
34
15
  missing_keys = RANGE_LIMIT_FIELDS - blacklight_config.search_state_fields
@@ -59,12 +40,7 @@ module BlacklightRangeLimit
59
40
 
60
41
  @presenter = (@facet.presenter || BlacklightRangeLimit::FacetFieldPresenter).new(@facet, display_facet, view_context)
61
42
 
62
- render 'blacklight_range_limit/range_segments', locals: { facet_field: @presenter }, layout: !request.xhr?
63
- end
64
-
65
- def range_limit_panel
66
- Deprecation.warn(BlacklightRangeLimit::ControllerOverride, 'range_limit_panel is deprecated; use the normal facet modal route instead')
67
- facet
43
+ render BlacklightRangeLimit::RangeSegmentsComponent.new(facet_field: @presenter), layout: !request.xhr?
68
44
  end
69
45
 
70
46
  class_methods do
@@ -3,11 +3,59 @@ require 'blacklight_range_limit'
3
3
  require 'rails'
4
4
 
5
5
  module BlacklightRangeLimit
6
+ # delegate for easier configability
7
+ def self.config
8
+ Engine.config
9
+ end
10
+
6
11
  class Engine < Rails::Engine
7
12
  config.action_dispatch.rescue_responses.merge!(
8
13
  "BlacklightRangeLimit::InvalidRange" => :not_acceptable
9
14
  )
10
15
 
16
+
17
+ config.using_importmaps = nil
18
+ config.using_importmaps_sprockets = nil
19
+
20
+ initializer "blacklight_range_limit.asset_mode_config" do |app|
21
+ # We guess based on what's in the app which is normally good enough,
22
+ # but you can set eg BlacklightRangeLimit.config.using_importmaps directly
23
+ # in your config/application.rb if the guess was not right for your environment.
24
+
25
+ if config.using_importmaps.nil?
26
+ config.using_importmaps = begin
27
+ Pathname(Rails.application.root).join("config/importmap.rb").exist? && app.config.respond_to?(:importmap)
28
+ end
29
+ end
30
+
31
+ if config.using_importmaps_sprockets.nil?
32
+ config.using_importmaps_sprockets ||= begin
33
+ config.using_importmaps && defined?(Sprockets) && !defined?(Propshaft)
34
+ end
35
+ end
36
+ end
37
+
38
+ # TODO: Config for using_importmaps and
39
+ # move source elsewhere so it's not in asset path with propshaft putting
40
+ # it in public, unless you actually want that? Only want that if we have propshaft and importmaps?
41
+
42
+ # TODO only turn this on if we're supporting sprockets-direct-importmaps combo
43
+ initializer "blacklight_range_limit.assets.precompile" do |app|
44
+ # IF they are using SPROCKETS *and* importmaps directly to engine files, then we
45
+ # need to tell sprockets all our JS files need to be available via HTTP, like
46
+ # so
47
+ if BlacklightRangeLimit.config.using_importmaps_sprockets
48
+ app.config.assets.precompile += ["blacklight-range-limit/index.js"]
49
+ end
50
+ end
51
+
52
+ initializer "blacklight_range_limit.importmap", before: "importmap" do |app|
53
+ if BlacklightRangeLimit.config.using_importmaps
54
+ app.config.importmap.paths << Engine.root.join("config/importmap.rb")
55
+ app.config.importmap.cache_sweepers << Engine.root.join("app/assets/javascripts/blacklight-range-limit")
56
+ end
57
+ end
58
+
11
59
  config.before_configuration do
12
60
  Blacklight::Configuration::FacetField.prepend BlacklightRangeLimit::FacetFieldConfigOverride
13
61
  end
@@ -22,12 +22,20 @@ module BlacklightRangeLimit
22
22
  solr_params["stats.field"] << config.field
23
23
 
24
24
  range_config = config.range_config
25
- next if range_config[:segments] == false
25
+ next unless range_config[:chart_js] || range_config[:textual_facets]
26
26
 
27
27
  selected_value = search_state.filter(config.key).values.first
28
- range = (selected_value if selected_value.is_a? Range) || range_config[:assumed_boundaries]
29
28
 
30
- add_range_segments_to_solr!(solr_params, field_key, range.first, range.last) if range.present?
29
+ range = if selected_value.is_a? Range
30
+ selected_value
31
+ elsif range_config[:assumed_boundaries]
32
+ Range.new(*range_config[:assumed_boundaries])
33
+ else
34
+ nil
35
+ end
36
+
37
+ # If we have both ends of a range
38
+ add_range_segments_to_solr!(solr_params, field_key, range.begin, range.end) if range && range.count != Float::INFINITY
31
39
  end
32
40
 
33
41
  solr_params
@@ -61,5 +69,34 @@ module BlacklightRangeLimit
61
69
  return solr_params
62
70
  end
63
71
 
72
+ # hacky polyfill for new Blacklight behavior we need, if we don't have it yet
73
+ #
74
+ # https://github.com/projectblacklight/blacklight/pull/3213
75
+ # https://github.com/projectblacklight/blacklight/pull/3443
76
+ bl_version = Gem.loaded_specs["blacklight"]&.version
77
+ if bl_version && (bl_version <= Gem::Version.new("8.6.1"))
78
+ def facet_value_to_fq_string(facet_field, value, use_local_params: true)
79
+ facet_config = blacklight_config.facet_fields[facet_field]
80
+
81
+ # if it's an one-end range, and condition from original that would use query instead isn't met
82
+ if value.is_a?(Range) && (value.count == Float::INFINITY) && !facet_config&.query
83
+ # Adapted from
84
+ # https://github.com/projectblacklight/blacklight/blob/1494bd0884efe7a48623e9b37abe558fa6348e2a/lib/blacklight/solr/search_builder_behavior.rb#L362-L366
85
+
86
+ solr_field = facet_config.field if facet_config && !facet_config.query
87
+ solr_field ||= facet_field
88
+
89
+ local_params = []
90
+ local_params << "tag=#{facet_config.tag}" if use_local_params && facet_config && facet_config.tag
91
+
92
+ prefix = "{!#{local_params.join(' ')}}" unless local_params.empty?
93
+
94
+ "#{prefix}#{solr_field}:[#{value.begin || "*"} TO #{value.end || "*"}]"
95
+ else
96
+ super
97
+ end
98
+ end
99
+ end
100
+
64
101
  end
65
102
  end
@@ -1,9 +1,5 @@
1
1
  # BlacklightRangeLimit
2
- require 'deprecation'
3
-
4
2
  module BlacklightRangeLimit
5
- extend Deprecation
6
-
7
3
  require 'blacklight_range_limit/facet_field_config_override'
8
4
  require 'blacklight_range_limit/range_limit_builder'
9
5
  require 'blacklight_range_limit/controller_override'
@@ -19,41 +15,22 @@ module BlacklightRangeLimit
19
15
  mattr_accessor :classes
20
16
 
21
17
  self.classes = {
22
- form: 'range_limit subsection form-inline',
23
- submit: 'submit btn btn-secondary'
18
+ form: 'range_limit_form',
19
+ submit: 'submit btn btn-sm btn-secondary'
24
20
  }
25
21
 
26
- # Add element to array only if it's not already there
27
- def self.safe_arr_add(array, element)
28
- Deprecation.warn(BlacklightRangeLimit, 'BlacklightRangeLimit.safe_arr_add is deprecated without replacement')
29
- array << element unless array.include?(element)
30
- end
31
-
32
- def self.range_config(blacklight_config, solr_field)
33
- Deprecation.warn(BlacklightRangeLimit, 'BlacklightRangeLimit.range_config is deprecated without replacement')
34
- field = blacklight_config.facet_fields[solr_field.to_s]
35
-
36
- return false unless field&.range
37
-
38
- if field.range == true
39
- default_range_config
40
- else
41
- field.range.merge(partial: field.partial)
42
- end
43
- end
44
-
45
22
  def self.default_range_config
46
23
  {
47
24
  range: true,
48
25
  range_config: {
49
26
  num_segments: 10,
50
27
  chart_js: true,
51
- slider_js: true,
52
- segments: true,
53
- assumed_boundaries: nil,
54
- maxlength: nil,
55
- input_label_range_begin: nil,
56
- input_label_range_end: nil
28
+ textual_facets: true,
29
+ textual_facets_collapsible: true,
30
+ chart_segment_border_color: 'rgb(54, 162, 235)',
31
+ chart_segment_bg_color: 'rgba(54, 162, 235, 0.5)',
32
+ chart_aspect_ratio: 2,
33
+ assumed_boundaries: nil
57
34
  },
58
35
  filter_class: BlacklightRangeLimit::FilterField,
59
36
  presenter: BlacklightRangeLimit::FacetFieldPresenter,
@@ -11,39 +11,103 @@
11
11
  # as suggested above.
12
12
  require 'rails/generators'
13
13
  require 'rails/generators/base'
14
+
14
15
  module BlacklightRangeLimit
15
16
  class AssetsGenerator < Rails::Generators::Base
16
17
  source_root File.join(BlacklightRangeLimit::Engine.root, 'app', 'assets')
17
18
 
18
- def assets
19
- application_css = Dir["app/assets/stylesheets/application{.css,.scss,.css.scss}"].first
19
+ # for vite-ruby you may set to eg 'app/frontend/entrypoints/application.js'
20
+ class_option :js_file, type: :string, default: "app/javascript/application.js"
21
+ class_option :yarn_local_package, type: :boolean, default: nil
22
+ class_option :asset_delivery_mode, type: :string, default: nil
23
+
24
+ attr_reader :option_js_file, :option_yarn_local_package, :option_asset_delivery_mode
20
25
 
21
- if application_css
26
+ def set_default_options
27
+ @option_js_file = options[:js_file]
22
28
 
23
- insert_into_file application_css, :before => "*/" do
24
- %q{
25
- *
26
- * Used by blacklight_range_limit
27
- *= require 'blacklight_range_limit'
28
- *
29
- }
29
+ @option_asset_delivery_mode = options[:asset_delivery_mode]
30
+ if option_asset_delivery_mode.nil?
31
+ # prefererntially default to importmap
32
+ if defined?(Importmap) && root.join("config/importmap.rb").exist?
33
+ @option_asset_delivery_mode = "importmap-rails"
34
+ elsif root.join("package.json").exist?
35
+ @option_asset_delivery_mode = "yarn-package"
36
+ else
37
+ raise ArgumentError.new("Could not identify asset_delivery_mode, try supplying --asset-delivery-mode=[importmap-rails|yarn-package]")
30
38
  end
31
- else
32
- say_status "warning", "Can not find application.css, did not insert our require", :red
33
39
  end
34
40
 
35
- append_to_file "app/assets/javascripts/application.js" do
36
- %q{
41
+ unless option_asset_delivery_mode.in?(["importmap-rails", "yarn-package"])
42
+ raise ArgumentError.new("Illegal --asset-delivery-mode '#{option_asset_delivery_mode}', must be importmap-rails or yarn-package")
43
+ end
37
44
 
38
- // For blacklight_range_limit built-in JS, if you don't want it you don't need
39
- // this:
40
- //= require 'blacklight_range_limit'
45
+ @option_yarn_local_package = options[:yarn_local_package]
46
+ if option_yarn_local_package.nil?
47
+ # default guess by CI in ENV or app name that we use for test apps
48
+ @option_yarn_local_package = ENV['CI'].present? || Rails.application.class.name == "Internal::Application"
49
+ end
50
+ end
51
+
52
+ def add_to_package_json
53
+ # for apps using jsbundling_rails, vite-ruby, etc.
54
+ if option_asset_delivery_mode == "yarn-package"
55
+ say_status "info", "Adding blacklight-range-limit to package.json", :blue
56
+
57
+ if option_yarn_local_package
58
+ run "yarn add blacklight-range-limit@file:#{BlacklightRangeLimit::Engine.root}", abort_on_failure: true
59
+ else
60
+ # are we actually going to release one-to-one? Maybe just matching major
61
+ # version would be enough?
62
+ run "yarn add blacklight-range-limit@^#{BlacklightRangeLimit::VERSION.split(".").first}.0.0", abort_on_failure: true
63
+ end
64
+ else
65
+ say_status "info", "No package.json, not adding blacklight-range-limit npm package", :blue
66
+ end
67
+ end
41
68
 
42
- }
69
+ def dependencies_to_importmap_rb
70
+ if option_asset_delivery_mode == "importmap-rails"
71
+ # No need to pin "blacklight-range-limit", importmaps can find it when imported
72
+ # already, because our engine put it in importmap.paths
73
+ append_to_file("config/importmap.rb") do
74
+ # We'll want to update these version numbers periodically in source here, no other way to do it?
75
+ # And generated apps will have to manually update them too?
76
+ <<~EOS
77
+ # chart.js is dependency of blacklight-range-limit, currently is not working
78
+ # as vendored importmaps, but instead must be pinned to CDN. You may want to update
79
+ # versions perioidically.
80
+ pin "chart.js", to: "https://ga.jspm.io/npm:chart.js@4.2.0/dist/chart.js"
81
+ # single dependency of chart.js:
82
+ pin "@kurkle/color", to: "https://ga.jspm.io/npm:@kurkle/color@0.3.2/dist/color.esm.js"
83
+ EOS
84
+ end
85
+ else
86
+ say_status(:info, "no config/importmap.rb, so did not pin JS dependencies for blacklight-range-limit there", :yellow)
43
87
  end
44
88
  end
45
89
 
46
90
 
91
+ def import_and_start_in_application_js
92
+ if root.join(option_js_file).exist?
93
+ js_file_path = root.join(option_js_file).to_s
47
94
 
95
+ append_to_file js_file_path do
96
+ <<~EOS
97
+
98
+ import BlacklightRangeLimit from "blacklight-range-limit";
99
+ BlacklightRangeLimit.init({onLoadHandler: Blacklight.onLoad });
100
+ EOS
101
+ end
102
+ else
103
+ say_status(:warn, "No file detected at #{option_js_file} so JS setup not added", :yellow)
104
+ end
105
+ end
106
+
107
+ private
108
+
109
+ def root
110
+ @root ||= Pathname(destination_root)
111
+ end
48
112
  end
49
113
  end
@@ -6,7 +6,7 @@ module BlacklightRangeLimit
6
6
 
7
7
  class_option :'builder-path', type: :string, default: 'app/models/search_builder.rb', aliases: "-b", desc: "Set the path, relative to Rails root, to the Blacklight app's search builder class"
8
8
 
9
- def copy_public_assets
9
+ def generate_assets
10
10
  generate 'blacklight_range_limit:assets'
11
11
  end
12
12
 
@@ -0,0 +1,98 @@
1
+ require 'rails/generators'
2
+
3
+ # FOR CI: NOT INTENDED FOR REAL APP
4
+ #
5
+ # We hackily get a BL7 app into a state jsbundling-rails/esbuild will work with it.
6
+ #
7
+ # May not work with all permutations of real-world apps, may do some hacks that get CI
8
+ # to run but would break a real app!
9
+
10
+ module BlacklightRangeLimit
11
+ class JsbundlingBl7FixupGenerator < Rails::Generators::Base
12
+ source_root File.expand_path("../../../../../spec/test_app_templates", __FILE__)
13
+
14
+ def guard_test_app_only
15
+ unless Rails.application.class.name == "Internal::Application"
16
+ raise "For safety, this generator can only be run in a test app, with app name 'test', not '#{Rails.application.name}'"
17
+ end
18
+ end
19
+
20
+ def add_blacklight_dependencies_to_package_json
21
+ # there is no blacklight 7.39.0 or 7.40.0 makes it hard for us to know what version to
22
+ # generate here, I guess we'll try generating an open range like "^7.0.0"?
23
+
24
+ # while blacklight7 may work with bootstrap 5, we'll test with 4 for now, and popper 1.x that goes with it
25
+ run %{yarn add --non-interactive
26
+ blacklight-frontend@^#{Blacklight::VERSION.split(".").first}.0.0
27
+ bootstrap@^4.1.0
28
+ popper.js@^1.16.0}.squish, abort_on_failure: true
29
+ end
30
+
31
+ # NOTE this is why you don't want to run this in a real app!!!
32
+ def remove_default_stimulus_code
33
+ # Due to a bug or something, import of stimulus will cause a problem with
34
+ # esbuild, in the presence of Blacklight layout's default application.js
35
+ # script tag lacking type=module
36
+ #
37
+ # generated BL app isn't using this stuff, we will just remove the include
38
+ #
39
+ # SEE: https://gist.github.com/pch/fe276b29ba037bdaeaa525932478ca18
40
+
41
+ gsub_file("app/javascript/application.js", %r{^ *import +["']\./controllers.*$}, '')
42
+ end
43
+
44
+ def add_blacklight7_esm_imports
45
+ js_dir = "app/javascript"
46
+ app_js_file = js_dir + "/application.js"
47
+
48
+ unless Pathname(app_js_file).exist?
49
+ raise "Cannot find file to set up at #{app_js_file}"
50
+ end
51
+
52
+ # Need to setup some things BEFORE actual blacklight imports, to work right
53
+ create_file (js_dir + "/blacklight_dependency_setup.js") do
54
+ <<~EOS
55
+ // Making JQuery from ESM available to Blacklight 7 and Bootstrap 4 that want
56
+ // it in window globals.
57
+ import $ from 'jquery'
58
+ window.jQuery = window.$ = $
59
+
60
+ // Bootstrap 4 also needs Popper, and needs it installed in window.Popper
61
+ import Popper from 'popper.js';
62
+ window.Popper = Popper;
63
+ EOS
64
+ end
65
+
66
+ append_to_file app_js_file do
67
+ <<~EOS
68
+ import "bootstrap";
69
+ import "./blacklight_dependency_setup.js"
70
+
71
+ //import 'blacklight-frontend/app/assets/javascripts/blacklight/blacklight';
72
+ // for some reason we need these all like this to work, can we figure out why?
73
+
74
+ import 'blacklight-frontend/app/javascript/blacklight/core';
75
+ import 'blacklight-frontend/app/javascript/blacklight/bookmark_toggle';
76
+ import 'blacklight-frontend/app/javascript/blacklight/button_focus';
77
+ import 'blacklight-frontend/app/javascript/blacklight/checkbox_submit';
78
+ import 'blacklight-frontend/app/javascript/blacklight/facet_load';
79
+ import 'blacklight-frontend/app/javascript/blacklight/modal';
80
+ import 'blacklight-frontend/app/javascript/blacklight/search_context';
81
+ EOS
82
+ end
83
+ end
84
+
85
+ def add_blacklight7_sass_esm_import
86
+ # only if we're using propshaft and not sprockets: We are using cssbundling-rails with
87
+ # sass, and we need to add a sass import from blacklight npm package -- that BL7 geenrator
88
+ # didn't know how to do. (BL8 generator prob does!)
89
+ if !defined?(Sprockets) && defined?(Propshaft)
90
+ append_to_file 'app/assets/stylesheets/application.bootstrap.scss' do
91
+ <<~CONTENT
92
+ @import "blacklight-frontend/app/assets/stylesheets/blacklight/blacklight";
93
+ CONTENT
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
data/package-lock.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "blacklight-range-limit",
3
+ "version": "8.5.0",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "blacklight-range-limit",
9
+ "version": "8.5.0",
10
+ "license": "Apache-2.0",
11
+ "devDependencies": {
12
+ "rollup": "^3.29.5",
13
+ "rollup-plugin-includepaths": "^0.2.4"
14
+ }
15
+ },
16
+ "node_modules/fsevents": {
17
+ "version": "2.3.3",
18
+ "dev": true,
19
+ "license": "MIT",
20
+ "optional": true,
21
+ "os": [
22
+ "darwin"
23
+ ],
24
+ "engines": {
25
+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
26
+ }
27
+ },
28
+ "node_modules/rollup": {
29
+ "version": "3.29.5",
30
+ "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.29.5.tgz",
31
+ "integrity": "sha512-GVsDdsbJzzy4S/v3dqWPJ7EfvZJfCHiDqe80IyrF59LYuP+e6U1LJoUqeuqRbwAWoMNoXivMNeNAOf5E22VA1w==",
32
+ "dev": true,
33
+ "bin": {
34
+ "rollup": "dist/bin/rollup"
35
+ },
36
+ "engines": {
37
+ "node": ">=14.18.0",
38
+ "npm": ">=8.0.0"
39
+ },
40
+ "optionalDependencies": {
41
+ "fsevents": "~2.3.2"
42
+ }
43
+ },
44
+ "node_modules/rollup-plugin-includepaths": {
45
+ "version": "0.2.4",
46
+ "resolved": "https://registry.npmjs.org/rollup-plugin-includepaths/-/rollup-plugin-includepaths-0.2.4.tgz",
47
+ "integrity": "sha512-iZen+XKVExeCzk7jeSZPJKL7B67slZNr8GXSC5ROBXtDGXDBH8wdjMfdNW5hf9kPt+tHyIvWh3wlE9bPrZL24g==",
48
+ "dev": true
49
+ }
50
+ }
51
+ }