Sha256: e23836c63c6661bce56e48cce2397ff556ef47d4a11ff2660b75fb2a22f2e5d9

Contents?: true

Size: 2 KB

Versions: 5

Compression:

Stored size: 2 KB

Contents

# frozen_string_literal: true

module BootstrapEmail
  class Config
    def initialize(options = {})
      @config_store = BootstrapEmail::ConfigStore.new(options)
      file = File.expand_path('bootstrap-email.config.rb', Dir.pwd)
      if options[:config_path]
        require_relative options[:config_path]
      elsif File.exist?(file)
        require_relative file
      end
    end

    def sass_string_for(type:)
      # look for custom sass string
      sub_type = type.sub('bootstrap-', '')
      string = config_for_option("sass_#{sub_type}_string")
      return string unless string.nil?

      # look for custom sass path
      path = config_for_option("sass_#{sub_type}_location")
      return File.read(path) unless path.nil?

      # look up and return others if found in default locations
      lookup_locations = ["#{type}.scss", "app/assets/stylesheets/#{type}.scss"]
      locations = lookup_locations.map { |location| File.expand_path(location, Dir.pwd) }.select { |location| File.exist?(location) }
      File.read(locations.first) if locations.any?
    end

    def sass_load_paths
      paths_array = [SassCache::SASS_DIR]
      custom_load_paths = config_for_option(:sass_load_paths) || []
      paths_array.concat(custom_load_paths)
    end

    def sass_cache_location
      option = config_for_option(:sass_cache_location)
      return option unless option.nil?

      if defined?(::Rails) && ::Rails.root
        ::Rails.root.join('tmp', 'cache', 'bootstrap-email', '.sass-cache')
      elsif File.writable?(Dir.pwd)
        File.join(Dir.pwd, '.sass-cache', 'bootstrap-email')
      else
        File.join(Dir.tmpdir, '.sass-cache', 'bootstrap-email')
      end
    end

    def sass_log_enabled?
      option = config_for_option(:sass_log_enabled)
      option.nil? ? true : option
    end

    private

    def config_for_option(option)
      if @config_store.did_set?(option)
        @config_store.public_send(option)
      else
        BootstrapEmail.static_config.public_send(option)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bootstrap-email-1.4.1 lib/bootstrap-email/config.rb
bootstrap-email-1.4.0 lib/bootstrap-email/config.rb
bootstrap-email-1.3.1 lib/bootstrap-email/config.rb
bootstrap-email-1.3.0 lib/bootstrap-email/config.rb
bootstrap-email-1.2.0 lib/bootstrap-email/config.rb