Class: Przn::Theme

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

Constant Summary collapse

DEFAULT_PATH =
File.expand_path('../../../default_theme.yml', __FILE__)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Theme

Returns a new instance of Theme.



44
45
46
47
48
49
50
51
# File 'lib/przn/theme.rb', line 44

def initialize(config)
  @colors = config[:colors]
  @font = config[:font]
  @bullet = config[:bullet]
  @bullet_size = config[:bullet_size]
  @bg = config[:bg]
  @heading_face = config[:heading_face]
end

Instance Attribute Details

#bgObject (readonly)

Returns the value of attribute bg.



9
10
11
# File 'lib/przn/theme.rb', line 9

def bg
  @bg
end

#bulletObject (readonly)

Returns the value of attribute bullet.



9
10
11
# File 'lib/przn/theme.rb', line 9

def bullet
  @bullet
end

#bullet_sizeObject (readonly)

Returns the value of attribute bullet_size.



9
10
11
# File 'lib/przn/theme.rb', line 9

def bullet_size
  @bullet_size
end

#colorsObject (readonly)

Returns the value of attribute colors.



9
10
11
# File 'lib/przn/theme.rb', line 9

def colors
  @colors
end

#fontObject (readonly)

Returns the value of attribute font.



9
10
11
# File 'lib/przn/theme.rb', line 9

def font
  @font
end

#heading_faceObject (readonly)

Returns the value of attribute heading_face.



9
10
11
# File 'lib/przn/theme.rb', line 9

def heading_face
  @heading_face
end

Class Method Details

.defaultObject



27
28
29
# File 'lib/przn/theme.rb', line 27

def self.default
  new(load_yaml(DEFAULT_PATH))
end

.load(path) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/przn/theme.rb', line 11

def self.load(path)
  raise ArgumentError, "Theme file not found: #{path}" unless File.exist?(path)

  defaults = load_yaml(DEFAULT_PATH)
  overrides = load_yaml(path)
  merged = {
    colors: defaults[:colors].merge(overrides[:colors] || {}),
    font: defaults[:font].merge(overrides[:font] || {}),
    bullet: overrides[:bullet] || defaults[:bullet],
    bullet_size: overrides[:bullet_size] || defaults[:bullet_size],
    bg: defaults[:bg].merge(overrides[:bg] || {}),
    heading_face: overrides[:heading_face] || defaults[:heading_face],
  }
  new(merged)
end