Sha256: 1f473de463f38d81bf11eb045d47ab9de15e36228a817fd59fb196385f77d67e

Contents?: true

Size: 1.76 KB

Versions: 48

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

require_relative '../../models/configuration'
require_relative '../../models/color_theme'

module Dsu
  module Views
    module ColorTheme
      class Index
        include Support::ColorThemable

        def render
          render!
        end

        private

        def render!
          presenter = color_theme.presenter
          puts presenter.header
          puts
          render_theme_details
          puts
          puts presenter.footer
        end

        def render_theme_details
          themes_folder = Models::Configuration.new.themes_folder
          theme_file_names = Dir.glob("#{themes_folder}/*").map { |theme_path| File.basename(theme_path, '.*') }
          theme_file_names << default_theme_name unless theme_file_names.include?(default_theme_name)
          theme_file_names.sort.each_with_index do |theme_file, index|
            color_theme = if theme_file == default_theme_name
              default_theme
            else
              Models::ColorTheme.find(theme_name: theme_file)
            end
            presenter = color_theme.presenter
            puts presenter.detail_with_index(index: index)
          end
        end

        # When getting the default theme, if it exists on disk, use that; otherwise,
        # use the in-memory default theme.
        def default_theme
          if Models::ColorTheme.exist?(theme_name: default_theme_name)
            Models::ColorTheme.find(theme_name: default_theme_name)
          else
            Models::ColorTheme.default
          end
        end

        def default_theme_name
          Dsu::Models::ColorTheme::DEFAULT_THEME_NAME
        end

        def color_theme
          @color_theme ||= Models::ColorTheme.current_or_default
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
dsu-3.0.5 lib/dsu/views/color_theme/index.rb
dsu-3.0.4 lib/dsu/views/color_theme/index.rb
dsu-3.0.3 lib/dsu/views/color_theme/index.rb
dsu-3.0.1 lib/dsu/views/color_theme/index.rb
dsu-3.0.0 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.beta.3 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.beta.2 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.beta.1 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.beta.0 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.alpha.12 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.alpha.11 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.alpha.10 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.alpha.9 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.alpha.8 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.alpha.7 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.alpha.6 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.alpha.5 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.alpha.4 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.alpha.3 lib/dsu/views/color_theme/index.rb
dsu-3.0.0.alpha.2 lib/dsu/views/color_theme/index.rb