Class: Graphomaton::Theme

Inherits:
Object
  • Object
show all
Defined in:
lib/graphomaton.rb

Class Method Summary collapse

Class Method Details

.available_namesObject



28
29
30
# File 'lib/graphomaton.rb', line 28

def self.available_names
  Exporters::Svg::THEMES.keys
end

.defaultObject



24
25
26
# File 'lib/graphomaton.rb', line 24

def self.default
  Exporters::Svg::THEMES.fetch(Exporters::Svg::DEFAULT_THEME)
end


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/graphomaton.rb', line 59

def self.gallery_html(title: 'Graphomaton Theme Gallery', themes: Exporters::Svg::THEMES, animated: false)
  cards = themes.map do |name, theme|
    normalized = normalize(theme)
    theme_card(name, normalized)
  end.join("\n")

  <<~HTML
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>#{escape_html(title)}</title>
      <style>
        body { background: #f8fafc; color: #0f172a; font-family: Georgia, serif; margin: 0; padding: 32px; }
        h1 { font-size: clamp(2rem, 4vw, 4rem); margin: 0 0 24px; }
        .theme-gallery { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
        .theme-card { background: white; border: 1px solid #e2e8f0; border-radius: 18px; box-shadow: 0 18px 40px rgba(15, 23, 42, 0.08); overflow: hidden; }
        .theme-card h2 { font-size: 1rem; letter-spacing: 0.08em; margin: 0; padding: 16px 18px; text-transform: uppercase; }
        .theme-card svg { display: block; width: 100%; }
        #{theme_gallery_animation_css(animated)}
      </style>
    </head>
    <body>
      <h1>#{escape_html(title)}</h1>
      <div class="theme-gallery">
    #{cards}
      </div>
    </body>
    </html>
  HTML
end

.normalize(theme, context: 'Graphomaton theme') ⇒ Object

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/graphomaton.rb', line 32

def self.normalize(theme, context: 'Graphomaton theme')
  raise ArgumentError, "#{context} must be a Hash" unless theme.is_a?(Hash)

  normalized = theme.transform_keys { |key| key.to_sym }
  unknown = normalized.keys - default.keys
  raise ArgumentError, "Unknown #{context} keys: #{unknown.join(', ')}" unless unknown.empty?

  normalized.each do |key, value|
    validate_value(key, value, context: context)
  end

  default.merge(normalized)
end

.resolve(theme, context: 'Graphomaton theme', allow_auto: false) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/graphomaton.rb', line 46

def self.resolve(theme, context: 'Graphomaton theme', allow_auto: false)
  return normalize(theme, context: context) if theme.is_a?(Hash)

  theme_name = theme.to_s.to_sym
  return default if allow_auto && theme_name == :auto

  Exporters::Svg::THEMES.fetch(theme_name)
rescue KeyError
  available = available_names
  available = available + [:auto] if allow_auto
  raise ArgumentError, "Unknown #{context}: #{theme.inspect}. Available themes: #{available.join(', ')}"
end


92
93
94
# File 'lib/graphomaton.rb', line 92

def self.save_gallery_html(filename, **options)
  AtomicFile.write(filename, gallery_html(**options))
end