Sha256: ff04edd97b1be4c40f50703cbc9d0dd47da06ed7b641455ea50a2d1ace43171d

Contents?: true

Size: 820 Bytes

Versions: 25

Compression:

Stored size: 820 Bytes

Contents

# frozen_string_literal: true

module Maglev
  # Fetch the style of a site. Use default values from the theme if needed.
  class FetchStyle
    include Injectable

    argument :site
    argument :theme

    def call
      Maglev::Site::StyleValue::Store.new(
        build_style_value_list
      )
    end

    protected

    def build_style_value_list
      theme.style_settings.map do |setting|
        build_style_value(setting)
      end
    end

    def build_style_value(setting)
      Maglev::Site::StyleValue.new(
        setting.id,
        setting.type,
        custom_value(setting)
      )
    end

    def custom_value(setting)
      value = site.style.find { |local_value| local_value['id'] == setting.id }
      value && value['type'] == setting.type ? value['value'] : setting.default
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
maglevcms-1.8.0 app/services/maglev/fetch_style.rb
maglevcms-1.7.3 app/services/maglev/fetch_style.rb
maglevcms-1.7.2 app/services/maglev/fetch_style.rb
maglevcms-1.7.1 app/services/maglev/fetch_style.rb
maglevcms-1.7.0 app/services/maglev/fetch_style.rb
maglevcms-1.6.1 app/services/maglev/fetch_style.rb
maglevcms-1.6.0 app/services/maglev/fetch_style.rb
maglevcms-1.5.1 app/services/maglev/fetch_style.rb
maglevcms-1.4.0 app/services/maglev/fetch_style.rb
maglevcms-1.3.0 app/services/maglev/fetch_style.rb
maglevcms-1.2.2 app/services/maglev/fetch_style.rb
maglevcms-1.2.1 app/services/maglev/fetch_style.rb
maglevcms-1.2.0 app/services/maglev/fetch_style.rb
maglevcms-1.1.7 app/services/maglev/fetch_style.rb
maglevcms-1.1.6 app/services/maglev/fetch_style.rb
maglevcms-1.1.5 app/services/maglev/fetch_style.rb
maglevcms-1.1.4 app/services/maglev/fetch_style.rb
maglevcms-1.1.3 app/services/maglev/fetch_style.rb
maglevcms-1.1.2 app/services/maglev/fetch_style.rb
maglevcms-1.1.1 app/services/maglev/fetch_style.rb