Skip to content

Commit

Permalink
Merge pull request #3408 from projectblacklight/refactor_alt_text_sup…
Browse files Browse the repository at this point in the history
…port

Give a more descriptive name to a method
  • Loading branch information
corylown authored Jan 24, 2025
2 parents 280251f + b0ef5c4 commit 03adad6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/controllers/spotlight/accessibility_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AccessibilityController < Spotlight::ApplicationController

def alt_text
# Sort by newest except for the homepage, which is always first
pages_with_alt = @exhibit.pages.order(Arel.sql('id = 1 DESC, created_at DESC')).select { |elem| elem.content.any?(&:alt_text?) }
pages_with_alt = @exhibit.pages.order(Arel.sql('id = 1 DESC, created_at DESC')).select { |elem| elem.content.any?(&:supports_alt_text?) }
@pages = pages_with_alt.map { |page| get_alt_info(page) }
@has_alt_text = @pages.sum { |page| page[:has_alt_text] }
@total_alt_items = @pages.sum { |page| page[:can_have_alt_text] }
Expand All @@ -23,7 +23,7 @@ def get_alt_info(page)
can_have_alt_text = 0
has_alt_text = 0
page.content.each do |content|
next unless content.alt_text?
next unless content.supports_alt_text?

content.item&.each_value do |item|
can_have_alt_text += 1
Expand Down
9 changes: 5 additions & 4 deletions app/models/sir_trevor_rails/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ def format
send(:[], :format).present? ? send(:[], :format).to_sym : DEFAULT_FORMAT
end

def alt_text?
self.class.alt_text?
def supports_alt_text?
self.class.supports_alt_text?
end

def self.alt_text?
# By default we don't support alt text, but some subclasses do
def self.supports_alt_text?
false
end

Expand All @@ -33,7 +34,7 @@ def self.custom_block_types
end

def self.custom_block_type_alt_text_settings
custom_block_types.index_with { |block_type| SirTrevorRails::Block.block_class(block_type).alt_text? }
custom_block_types.index_with { |block_type| SirTrevorRails::Block.block_class(block_type).supports_alt_text? }
end

def initialize(hash, parent)
Expand Down
2 changes: 1 addition & 1 deletion app/models/sir_trevor_rails/blocks/solr_documents_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def with_solr_helper(solr_helper)
@solr_helper = solr_helper
end

def self.alt_text?
def self.supports_alt_text?
true
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Blocks
##
# Embed documents (using a special blacklight view configuration) and text block
class SolrDocumentsEmbedBlock < SirTrevorRails::Blocks::SolrDocumentsBlock
def self.alt_text?
def self.supports_alt_text?
false
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/sir_trevor_rails/blocks/uploaded_items_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def files
(item || {}).map { |_, file| file }.select { |file| file[:display].to_s == 'true' }
end

def self.alt_text?
def self.supports_alt_text?
true
end

Expand Down

0 comments on commit 03adad6

Please sign in to comment.