Sha256: 7a8818cc599897c8fd24608a0f1c3608ca42f0fe57d52035444691519b436156

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

module Kentico
  module Kontent
    module Resolvers
      ##
      # This class resolve the content of the content item to be injected
      # under the front matter part of the page.
      # If no user-defined resolver was provided or it returned nil
      # then content will be resolved in a default way.

      class ContentResolver
        def initialize(global_config)
          @global_config = global_config
        end

        def execute(content_item, config)
          content = custom_resolver && custom_resolver.resolve(content_item)
          content || resolve_internal(content_item, config)
        end

        private

        ##
        # User-provided provided resolver is instantiated based on the name from configuration.

        def custom_resolver
          return @custom_resolver if @custom_resolver

          resolver_name = @global_config.content_resolver
          return unless resolver_name

          @custom_resolver = Module.const_get(resolver_name).new
        end

        ##
        # Resolves content in a default way, it looks up element with a codename 'content'
        # or codename specified in the config and takes its string value. This also resolves
        # content components and linked items.

        def resolve_internal(content_item, config)
          element_name = config.content || 'content'
          element = content_item.elements[element_name]
          element && content_item.get_string(element_name)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kontent-jekyll-0.11.1 lib/kontent-jekyll/resolvers/content_resolver.rb
kontent-jekyll-0.11.0 lib/kontent-jekyll/resolvers/content_resolver.rb