Spotlight

repository·main·Indexed 41 days ago

https://github.com/projectblacklight/spotlight

A Ruby on Rails engine that extends Blacklight to enable librarians and curators to build feature-rich exhibit websites for showcasing digital collections and objects. Version 5.2.4 includes support for custom fields, sidecars, and a frontend architecture utilizing Tiny Slider (tns) for carousels.

Tokens
10.4K
Snippets
29
Records
51
Agent score
51%

What's inside Spotlight

  1. Core Spotlight Concepts and Models

    main

    Understanding the primary abstractions in Spotlight:

    • Exhibits (Spotlight::Exhibit): The main organizational container for content.
    • Pages (Spotlight::Page / Spotlight::HomePage): Curated pages within an exhibit, using Sir Trevor for rich text editing.
    • Custom Fields (Spotlight::CustomField): Admin-defined fields (e.g., multivalued text, read-only metadata) added to exhibit items.
    • Sidecars (Spotlight::SolrDocumentSidecar): Database-backed extensions to Solr documents that allow exhibit-specific metadata to persist locally.
    • Resources (Spotlight::Resource): External or uploaded content that is converted into Solr documents.

    Frontend Architecture:

    • Source JavaScript is located in app/javascript/spotlight/.
    • Core orchestration happens in app/javascript/spotlight/index.js, which listens for page loads and instantiates class components (e.g., new AddAnother().connect()).
  2. Develop Spotlight locally

    main

    To develop on Spotlight, you must work within the context of a Rails application. The project uses engine_cart to manage an internal test application and solr_wrapper to manage Solr.

    Prerequisites

    • Ruby 3.2+
    • Ruby on Rails 7.1+
    • Java 11+ (unless using Solr in Docker)
    • ImageMagick (for riiif service or custom Carrierwave uploaders)

    Quick Start with solr_wrapper

    1. Clone the repository and cd into it.
    2. Run bundle install.
    3. Run the following command to build the app, start Solr, and launch the Rails server:
      rake spotlight:server
      You will be prompted to create an admin user.

    Quick Start with Docker

    1. Run Solr in Docker:
      docker compose up -d
    2. Set up the test app and seed an admin user:
      rake engine_cart:generate
      rake spotlight:fixtures
      cd .internal_test_app
      rake spotlight:seed_admin_user
      bin/dev
    rake spotlight:server
  3. Update the Spotlight JavaScript bundle

    main

    The JavaScript is built from sources in app/javascript into app/assets/javascripts/spotlight/spotlight.js. Do not edit this file manually, as changes will be overwritten. If the gem's JavaScript components change, rebuild the bundle using these steps:

    1. Install npm.
    2. Run npm install to download dependencies.
    3. Run npm run prepare to build the bundle.

    If you are releasing a new version of the gem, follow the release instructions to update package.json and publish the package to npm.

    npm install
    npm run prepare
  4. Install Spotlight in a new Rails application

    main

    To bootstrap a new Spotlight instance, use the provided Rails template. You can choose between importmap-rails (default) or jsbundling-rails with esbuild.

    Note: During installation, you will be prompted to create an initial administrator email and password. This super-admin can manage any exhibit in the installation. If you skip this, the first user created will be granted administrative privileges.

    Using importmap-rails:

    $ SKIP_TRANSLATION=1 rails new app-name -m https://raw.githubusercontent.com/projectblacklight/spotlight/main/template.rb -a propshaft --css bootstrap

    Using jsbundling-rails with esbuild:

    $ SKIP_TRANSLATION=1 rails new app-name -m https://raw.githubusercontent.com/projectblacklight/spotlight/main/template.rb -a propshaft -j esbuild --css bootstrap

    From an existing Rails application:

    $ SKIP_TRANSLATION=1 rails app:template LOCATION=https://raw.githubusercontent.com/projectblacklight/spotlight/main/template.rb
  5. Join the Spotlight community

    main

    The Spotlight community is active on Slack and Google Groups. Use these channels for development, implementation discussions, or service support:

    Slack (code4lib):

    • #spotlight-development: For Spotlight-specific development.
    • #blacklight: For discussing implementation, customization, and broader Blacklight concerns.
    • #spotlight-service: For service-focused support for institutions using Spotlight.

    Google Groups:

    • Blacklight Development Google group
    • Spotlight Community Group (equivalent to #spotlight-service)
  6. Run Spotlight tests

    main

    Using solr_wrapper

    If Solr is not already running, use the following task to build the app, start Solr, run tests, and shut down Solr:

    rake

    Using Docker

    If Solr is running in Docker, use these commands:

    rake engine_cart:generate
    rake spotlight:fixtures
    cd .internal_test_app && rake spec:prepare && cd -
    rspec

    Note: rake spec:prepare generates CSS assets for tests. You can clear them with rake assets:clobber.

  7. Use SirTrevor.Blocks.SolrDocumentsBase for Solr-backed blocks

    main

    For blocks that primarily interact with Solr documents (like carousels, grids, or embeds), extend SirTrevor.Blocks.SolrDocumentsBase. This class simplifies autocomplete and captioning for Solr results.

    Key features provided by the base class:

    • Autocomplete: Automatically handles Solr-based autocomplete using autocomplete_url() and transform_autocomplete_results().
    • Captioning: Provides caption_options() which generates UI for selecting primary and secondary Solr fields to display as captions.
    • Field Mapping: Uses caption_option_values() to populate dropdowns based on configured index fields.

    Common implementations include:

    • SirTrevor.Blocks.SolrDocuments: Standard Solr document list.
    • SirTrevor.Blocks.SolrDocumentsCarousel: A carousel of Solr documents with configurable auto-play intervals and heights.
    • SirTrevor.Blocks.SolrDocumentsGrid: A grid layout of Solr documents.
    • SirTrevor.Blocks.SolrDocumentsEmbed: An embedded view of Solr documents.
  8. Extend Spotlight.Block.Resources to create custom resource blocks

    main

    To create a block that manages a collection of resources (like Solr documents or uploaded files), extend Spotlight$1.Block.Resources. This base class provides methods for managing item panels, autocomplete functionality, and item options.

    Key methods to implement or override:

    • type: A unique string identifier for the block.
    • icon_name: The icon used in the editor.
    • autocomplete_url(): Returns the URL used for fetching autocomplete suggestions.
    • autocomplete_template(obj): Returns the HTML string for an individual autocomplete result item.
    • _itemPanel(data): Generates the HTML markup for an individual item within the resource list.
    • item_options(): Returns HTML for additional configuration settings for the entire block.
    • afterPanelRender(data, panel): A lifecycle hook called after an item panel is added to the DOM. Useful for initializing third-party libraries (like IIIF or carousels) on the new panel.
    • afterPanelDelete(): A lifecycle hook called after an item is removed from the list.
    SirTrevor.Blocks.MyCustomResource = (function () {
      return Spotlight$1.Block.Resources.extend({
        type: "my_custom_resource",
        icon_name: "my_icon",
        autocomplete_url: function () { /* ... */ },
        autocomplete_template: function (obj) { /* ... */ },
        _itemPanel: function (data) { /* ... */ },
        item_options: function () { /* ... */ }
      });
    })();
  9. How Tiny Slider handles Content Security Policy (CSP)

    main
    Tiny Slider dynamically creates and injects a <style> element into the document <head> to manage its layout and animations. To support strict Content Security Policy (CSP) environments, you can pass a nonce value in the initialization options. This nonce will be applied to the generated <style> tag, allowing the browser to authorize the inline styles.
  10. Access slider visibility and range via Live Regions

    main

    For accessibility, the slider maintains a live region (tns-liveregion) that communicates the current visible slide range to screen readers.

    The text format is typically: slide X to Y (e.g., slide 1 to 3).

    If you need to programmatically determine which slides are currently visible, you can use the logic derived from getVisibleSlideRange(), which calculates the start and end indices based on the current index, viewport, edgePadding, and gutter settings.

  11. Handle slider resize events and responsive breakpoints

    main

    The slider automatically responds to window resizing if responsive, fixedWidth, autoWidth, or !horizontal options are set.

    When a resize occurs, the slider:

    1. Calculates the new breakpointZone based on the responsive configuration.
    2. Updates internal variables like viewport, items, and slideBy if breakpoints changed.
    3. Re-calculates slide positions and container transforms.
    4. Emits newBreakpointStart and newBreakpointEnd events when crossing a breakpoint boundary.
    5. Emits outerResized if the nested option is set to 'outer'.