Class: DrawioDsl::Configuration::Theme

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

Defined Under Namespace

Classes: BackgroundThemeConfig, ElementThemeConfig

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_config) ⇒ Theme

Returns a new instance of Theme.



334
335
336
# File 'lib/drawio_dsl/configuration.rb', line 334

def initialize(source_config)
  @source_config = source_config
end

Instance Attribute Details

#source_configObject (readonly)

Returns the value of attribute source_config.



329
330
331
# File 'lib/drawio_dsl/configuration.rb', line 329

def source_config
  @source_config
end

Instance Method Details

#background(key) ⇒ Object



338
339
340
341
342
343
344
345
# File 'lib/drawio_dsl/configuration.rb', line 338

def background(key)
  backgrounds[key] || BackgroundThemeConfig.new(
    key: key,
    bg_color: '#000000',
    font_color: '#FFFFFF',
    favourite: false
  )
end

#background_keysObject



363
364
365
# File 'lib/drawio_dsl/configuration.rb', line 363

def background_keys
  backgrounds.keys
end

#backgroundsObject



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/drawio_dsl/configuration.rb', line 347

def backgrounds
  return @backgrounds if defined? @backgrounds

  @backgrounds = {}
  source_config['backgrounds'].each do |background|
    @backgrounds[background['key'].to_sym] = BackgroundThemeConfig.new(
      key: background['key'].to_sym,
      bg_color: background['bg_color'],
      font_color: background['font_color'],
      favourite: background['favourite'] == 1
    )
  end

  @backgrounds
end

#element(key) ⇒ Object



375
376
377
378
379
380
381
382
383
# File 'lib/drawio_dsl/configuration.rb', line 375

def element(key)
  elements[key] || ElementThemeConfig.new(
    key: key,
    fill_color: '#ffffff',
    stroke_color: '#000000',
    font_color: '#000000',
    gradient: nil
  )
end

#element_keysObject



402
403
404
# File 'lib/drawio_dsl/configuration.rb', line 402

def element_keys
  elements.keys
end

#elementsObject



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/drawio_dsl/configuration.rb', line 385

def elements
  return @elements if defined? @elements

  @elements = {}
  source_config['elements'].each do |element|
    @elements[element['key'].to_sym] = ElementThemeConfig.new(
      key: element['key'].to_sym,
      fill_color: element['fill_color'],
      stroke_color: element['stroke_color'],
      font_color: element['font_color'],
      gradient: element['gradient']
    )
  end

  @elements
end

#favourite_background_keysObject



367
368
369
# File 'lib/drawio_dsl/configuration.rb', line 367

def favourite_background_keys
  backgrounds.values.select(&:favourite).map(&:key)
end

#random_background_keyObject



371
372
373
# File 'lib/drawio_dsl/configuration.rb', line 371

def random_background_key
  backgrounds.values.sample.key
end

#random_element_keyObject



406
407
408
# File 'lib/drawio_dsl/configuration.rb', line 406

def random_element_key
  elements.values.sample.key
end