Module: Sevgi::Showcase::Dark Private

Extended by:
Dark
Included in:
Dark
Defined in:
lib/sevgi/showcase/dark.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Applies dark-theme color mappings to showcase source files.

Instance Method Summary collapse

Instance Method Details

#apply(source, mapping) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Applies a color mapping to source text.

Parameters:

  • source (String)

    source text

  • mapping (Hash{String => String})

    source color to dark color mapping

Returns:

  • (String)

    transformed source text

Raises:

  • (Sevgi::ArgumentError)

    when a mapping key is not found



15
16
17
18
19
20
21
22
23
24
# File 'lib/sevgi/showcase/dark.rb', line 15

def apply(source, mapping)
  applied = Hash.new(0)
  content = replace_quoted(source, mapping, applied)
  content = replace_percent_words(content, mapping, applied)
  missing = mapping.keys.reject { applied[it].positive? }

  ArgumentError.("Unapplied dark mapping(s): #{missing.join(", ")}") unless missing.empty?

  content
end

#apply_file(source, target, mapping) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Applies a color mapping to a source file and preserves its mode.

Parameters:

  • source (String)

    source file path

  • target (String)

    target file path

  • mapping (Hash{String => String})

    source color to dark color mapping

Returns:

  • (String)

    target file path

Raises:

  • (Sevgi::ArgumentError)

    when a mapping key is not found



32
33
34
35
36
37
# File 'lib/sevgi/showcase/dark.rb', line 32

def apply_file(source, target, mapping)
  target.tap do
    File.write(target, apply(File.read(source), mapping))
    File.chmod(File.stat(source).mode & 0o777, target)
  end
end