Sha256: 67374fa65a9f090d4077bfa76b8717814d94a38e5da0daec62565cab9bd16df1

Contents?: true

Size: 1.35 KB

Versions: 29

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true
module Hyrax
  module Renderers
    module ConfiguredMicrodata
      def microdata?(field)
        return false unless Hyrax.config.display_microdata?
        translate_microdata(field: field, field_context: 'property', default: false)
      end

      def microdata_object?(field)
        return false unless Hyrax.config.display_microdata?
        translate_microdata(field: field, field_context: 'type', default: false)
      end

      def microdata_object_attributes(field)
        if microdata_object?(field)
          { itemprop: microdata_property(field), itemscope: '', itemtype: microdata_type(field) }
        else
          {}
        end
      end

      def microdata_property(field)
        translate_microdata(field: field, field_context: 'property')
      end

      def microdata_type(field)
        translate_microdata(field: field, field_context: 'type')
      end

      def microdata_value_attributes(field)
        if microdata?(field)
          field_context = microdata_object?(field) ? :value : :property
          { itemprop: translate_microdata(field: field, field_context: field_context) }
        else
          {}
        end
      end

      private

      def translate_microdata(field:, field_context:, default: true)
        Microdata.fetch("#{field}.#{field_context}", default: default)
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
hyrax-5.1.0.pre.beta1 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-5.0.4 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-5.0.3 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-5.0.2 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-5.0.1 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-5.0.0 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-5.0.0.rc3 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-5.0.0.rc2 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-5.0.0.rc1 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-3.6.0 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-4.0.0 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-4.0.0.rc3 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-4.0.0.rc2 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-4.0.0.rc1 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-3.5.0 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-4.0.0.beta2 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-3.4.2 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-4.0.0.beta1 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-3.4.1 app/renderers/hyrax/renderers/configured_microdata.rb
hyrax-3.4.0 app/renderers/hyrax/renderers/configured_microdata.rb