lib/drawio_dsl/configuration.rb in drawio_dsl-0.9.0 vs lib/drawio_dsl/configuration.rb in drawio_dsl-0.10.0
- old
+ new
@@ -3,38 +3,29 @@
# Attach configuration to the DrawIO DSL module
module DrawioDsl
# Configuration container for the DrawIO DSL
class Configuration
include DrawioDsl::ConfigurationShapes
- include DrawioDsl::ConfigurationThemes
include KLog::Logging
- BaseStyle = Struct.new(:white_space, :html, :rounded, :shadow, :sketch, :glass, keyword_init: true)
+ BaseStyle = Struct.new(:white_space, :html, :rounded, :shadow, :sketch, :glass, keyword_init: true)
ElementConfig = Struct.new(:type, :x, :y, :w, :h, :style_modifiers, keyword_init: true)
- LineConfig = Struct.new(:type, :x, :y, :w, :h, :style_modifiers, keyword_init: true)
- TextConfig = Struct.new(:type, :x, :y, :w, :h, :style_modifiers, keyword_init: true)
+ LineConfig = Struct.new(:type, :x, :y, :w, :h, :style_modifiers, keyword_init: true)
+ TextConfig = Struct.new(:type, :x, :y, :w, :h, :style_modifiers, keyword_init: true)
attr_accessor :base_style
attr_accessor :shapes
def initialize
@base_style = BaseStyle.new(white_space: :wrap, html: 1, rounded: nil, shadow: nil, sketch: nil, glass: nil)
+ # TODO: these need to be removed
add_shapes
- add_themes
end
- def palette(theme)
- themes[theme]
- end
-
- def random_theme
- themes.keys.sample
- end
-
def stroke(type)
strokes[type] || ''
end
def strokes
@@ -128,10 +119,14 @@
def connector
@connector ||= Connector.new(source_config['connector'])
end
+ def theme
+ @theme ||= Theme.new(source_config['theme'])
+ end
+
def source_config
return @source_config if defined? @source_config
@source_config = begin
file = File.join(DrawioDsl::ROOT_PATH, 'config/configuration.json')
@@ -205,9 +200,86 @@
source_config['designs'].each do |design|
@designs[design['type'].to_sym] = design['style']
end
@designs
+ end
+ end
+
+ class Theme
+ attr_reader :source_config
+
+ BackgroundThemeConfig = Struct.new(:type, :bg_color, :font_color, keyword_init: true)
+ ElementThemeConfig = Struct.new(:type, :fill_color, :stroke_color, :font_color, :gradient, keyword_init: true)
+
+ def initialize(source_config)
+ @source_config = source_config
+ end
+
+ def background(type)
+ backgrounds[type] || BackgroundThemeConfig.new(
+ type: type,
+ bg_color: '#000000',
+ font_color: '#ffffff'
+ )
+ end
+
+ def backgrounds
+ return @backgrounds if defined? @backgrounds
+
+ @backgrounds = {}
+ source_config['backgrounds'].each do |background|
+ @backgrounds[background['type'].to_sym] = BackgroundThemeConfig.new(
+ type: background['type'].to_sym,
+ bg_color: background['bg_color'],
+ font_color: background['font_color']
+ )
+ end
+
+ @backgrounds
+ end
+
+ def background_types
+ backgrounds.keys
+ end
+
+ def random_background_type
+ backgrounds.values.sample.type
+ end
+
+ def element(type)
+ elements[type] || ElementThemeConfig.new(
+ type: type,
+ fill_color: '#ffffff',
+ stroke_color: '#000000',
+ font_color: '#000000',
+ gradient: nil
+ )
+ end
+
+ def elements
+ return @elements if defined? @elements
+
+ @elements = {}
+ source_config['elements'].each do |element|
+ @elements[element['type'].to_sym] = ElementThemeConfig.new(
+ type: element['type'].to_sym,
+ fill_color: element['fill_color'],
+ stroke_color: element['stroke_color'],
+ font_color: element['font_color'],
+ gradient: element['gradient']
+ )
+ end
+
+ @elements
+ end
+
+ def element_types
+ elements.keys
+ end
+
+ def random_element_type
+ elements.values.sample.type
end
end
end
end