Class: Slideshow::Opts

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

Overview

todo: split (command line) options and headers? e.g. share (command line) options between slide shows (but not headers?)

Constant Summary

DEFAULTS =
{
  :title             => 'Untitled Slide Show',
  :footer            => '',
  :subfooter         => '',
  :gradient_theme    => 'dark',
  :gradient_color1   => 'red',
  :gradient_color2   => 'black',

  :code_engine       => 'sh',  # SyntaxHighligher (sh) | ultraviolet (uv) | coderay (cr)
  :code_txmt         => 'false', # Text Mate Hyperlink for Source?
}

Instance Method Summary collapse

Constructor Details

#initializeOpts



8
9
10
# File 'lib/slideshow/opts.rb', line 8

def initialize
  @hash = {}
end

Instance Method Details

#[](key) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/slideshow/opts.rb', line 39

def []( key )
  value = @hash[ normalize_key( key ) ]
  if value.nil?
    puts "** Warning: header '#{key}' undefined"
    "- #{key} not found -"
  else
    value 
  end
end

#code_engineObject



86
87
88
# File 'lib/slideshow/opts.rb', line 86

def code_engine
  get( 'code-engine', DEFAULTS[ :code_engine ] )
end

#code_txmtObject



90
91
92
# File 'lib/slideshow/opts.rb', line 90

def code_txmt
  get( 'code-txmt', DEFAULTS[ :code_txmt ])
end

#config_pathObject



78
79
80
# File 'lib/slideshow/opts.rb', line 78

def config_path
  get( 'config_path', nil )
end

#fetch?Boolean



57
58
59
# File 'lib/slideshow/opts.rb', line 57

def fetch?
  get( 'fetch_uri', nil ) != nil
end

#fetch_uriObject



61
62
63
# File 'lib/slideshow/opts.rb', line 61

def fetch_uri
  get( 'fetch_uri', '-fetch uri required-' )
end

#generate?Boolean



49
50
51
# File 'lib/slideshow/opts.rb', line 49

def generate?
  get_boolean( 'generate', false )
end

#get(key, default) ⇒ Object



114
115
116
# File 'lib/slideshow/opts.rb', line 114

def get( key, default )
  @hash.fetch( normalize_key(key), default )
end

#gradient=(value) ⇒ Object



23
24
25
# File 'lib/slideshow/opts.rb', line 23

def gradient=( value )
  put_gradient( value, :theme, :color1, :color2 )
end

#gradient_color=(value) ⇒ Object



31
32
33
# File 'lib/slideshow/opts.rb', line 31

def gradient_color=( value )
  put_gradient( value, :color1 )
end

#gradient_colors=(value) ⇒ Object



27
28
29
# File 'lib/slideshow/opts.rb', line 27

def gradient_colors=( value )
  put_gradient( value, :color1, :color2 )
end

#gradient_theme=(value) ⇒ Object



35
36
37
# File 'lib/slideshow/opts.rb', line 35

def gradient_theme=( value )
  put_gradient( value, :theme )
end

#has_includes?Boolean



65
66
67
# File 'lib/slideshow/opts.rb', line 65

def has_includes?
  @hash[ :include ]
end

#includesObject



69
70
71
72
# File 'lib/slideshow/opts.rb', line 69

def includes
  # fix: use os-agnostic delimiter (use : for Mac/Unix?)
  has_includes? ? @hash[ :include ].split( ';' ) : []
end

#list?Boolean



53
54
55
# File 'lib/slideshow/opts.rb', line 53

def list?
  get_boolean( 'list', false )
end

#manifestObject



74
75
76
# File 'lib/slideshow/opts.rb', line 74

def manifest  
  get( 'manifest', 's6.txt' )
end

#output_pathObject



82
83
84
# File 'lib/slideshow/opts.rb', line 82

def output_path
  get( 'output', '.' )
end

#put(key, value) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/slideshow/opts.rb', line 12

def put( key, value )
  key = normalize_key( key )
  setter = "#{key}=".to_sym

  if respond_to? setter
    send setter, value
  else
    @hash[ key ] = value
  end
end

#set_defaultsObject



108
109
110
111
112
# File 'lib/slideshow/opts.rb', line 108

def set_defaults      
  DEFAULTS.each_pair do | key, value |
    @hash[ key ] = value if @hash[ key ].nil?
  end
end