Class: Slideshow::Config

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/slideshow/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Config

Returns a new instance of Config.



7
8
9
# File 'lib/slideshow/config.rb', line 7

def initialize( opts )
  @opts   = opts
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



11
12
13
# File 'lib/slideshow/config.rb', line 11

def opts
  @opts
end

Instance Method Details

#cache_dirObject

todo/fix: fix references after this move to here, that is, Config class

  • used in syntax/uv_helper (use config.cache_dir to access?)



29
30
31
# File 'lib/slideshow/config.rb', line 29

def cache_dir
  File.join( Env.home, '.slideshow' )
end

#config_dirObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/slideshow/config.rb', line 33

def config_dir
  unless @config_dir  # first time? calculate config_dir value to "cache"
    @config_dir = opts.config_path
  
    # make sure path exists
    FileUtils.makedirs( @config_dir ) unless File.directory? @config_dir
  end
  
  @config_dir
end

#default_fetch_shortcutsObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/slideshow/config.rb', line 86

def default_fetch_shortcuts
  ## NB: used by install --all

  ['s6blank',
   's6syntax',
   's5blank',
   's5themes',
   'g5',
   'slidy',
   'deck.js',
   'impress.js',
   'analytics'
  ]
  
  ## todo: use @props_shortcuts keys
  #  and use
  #
  # fetch_shortcuts = fetch_shortcuts.clone
  # fetch_shortcuts.delete( 'fullerscreen' )  # obsolete (do not promote any longer)
  # fetch_shortcuts.delete( 'slippy' )  # needs update/maintainer anyone?
  # fetch_shortcuts.delete( 'shower' )  # needs update/maintainer anyone?
  # etc. to strip keys for all install
end

#dumpObject

dump settings for debugging



144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/slideshow/config.rb', line 144

def dump  # dump settings for debugging
  puts "Slideshow settings:"
  @props_builtin.dump  if @props_builtin
  @props_default.dump  if @props_default
  @props_home.dump     if @props_home
  @props_work.dump     if @props_work
  
  puts "Slideshow shortcuts:"
  @props_shortcuts_default.dump  if @props_shortcuts_default
  @props_shortcuts_home.dump     if @props_shortcuts_home
  ## todo: add props from 'standard' props via fetch key
  
  ## todo: add more config settings?
end

#google_analytics_codeObject



206
207
208
# File 'lib/slideshow/config.rb', line 206

def google_analytics_code
  @props.fetch_from_section( 'analytics', 'google', nil )
end

#header(key) ⇒ Object



160
161
162
# File 'lib/slideshow/config.rb', line 160

def header( key )
  @props.fetch_from_section( 'headers', normalize_key( key ), nil )
end

#header_levelObject



13
14
15
# File 'lib/slideshow/config.rb', line 13

def header_level
  @opts.header_level
end

#helper_exprsObject



221
222
223
224
225
226
# File 'lib/slideshow/config.rb', line 221

def helper_exprs
  ## NB: for now user cannot override/extent helper exprs
  # allow expression as directives (no need for %end block)
  # by default directives are assumed statements (e.g. %mydir  %end)
  @props_builtin['helper']['exprs']
end

#helper_renamesObject



210
211
212
213
# File 'lib/slideshow/config.rb', line 210

def helper_renames
  ## NB: for now user cannot override/extent renames
  @props_builtin['helper']['renames']
end

#helper_unparsedObject



215
216
217
218
219
# File 'lib/slideshow/config.rb', line 215

def helper_unparsed
  ## NB: for now user cannot override/extent unparsed helpers
  # use unparsed params (passed along a single string)
  @props_builtin['helper']['unparsed']
end

#known_extnamesObject



188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/slideshow/config.rb', line 188

def known_extnames
  # returns an array of known file extensions e.g.
  # [ '.textile', '.t' ]
  #
  # using nested key
  # textile:
  #   extnames:  [ .textile, .t ]
  #
  # ruby check: is it better self. ?? or more confusing
  #  possible conflict only with write access (e.g. prop=) 
  
  known_textile_extnames + known_markdown_extnames + known_mediawiki_extnames + known_rest_extnames
end

#known_markdown_extnamesObject



182
183
184
185
186
# File 'lib/slideshow/config.rb', line 182

def known_markdown_extnames
  ## delegate config to Markdown gem for now
  ## todo/fix: how to pass on setting to Markdown gem??
  Markdown.extnames
end

#known_mediawiki_extnamesObject



178
179
180
# File 'lib/slideshow/config.rb', line 178

def known_mediawiki_extnames
  @props.fetch_from_section( 'mediawiki', 'extnames', [] )
end

#known_rest_extnamesObject



170
171
172
# File 'lib/slideshow/config.rb', line 170

def known_rest_extnames
  @props.fetch_from_section( 'rest', 'extnames', [] )
end

#known_textile_extnamesObject



174
175
176
# File 'lib/slideshow/config.rb', line 174

def known_textile_extnames
  @props.fetch_from_section( 'textile', 'extnames', [] )
end

#loadObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/slideshow/config.rb', line 111

def load
  
  # load builtin config file @  <gem>/config/slideshow.yml
  #
  # NB: builtin use a different hierachy (not linked to default/home/user/cli props)
  #     for now builtin has no erb processing
  #     user cannot override builtin settings (only defaults see below)
  props_builtin_file  = File.join( Slideshow.root, 'config', 'slideshow.builtin.yml' )
  @props_builtin = Props.load_file( props_builtin_file )

  props_default_file  = File.join( Slideshow.root, 'config', 'slideshow.yml' )
  @props = @props_default = Props.load_file_with_erb( props_default_file, binding() )

  # check for user settings (slideshow.yml) in home folder
  
  props_home_file = File.join( Env.home, 'slideshow.yml' )
  if File.exists?( props_home_file )
    puts "Loading settings from '#{props_home_file}'..."
    @props = @props_home = Props.load_file_with_erb( props_home_file, binding(), @props )
  end
    
  # check for user settings (slideshow.yml) in working folder
  
  props_work_file = File.join( '.', 'slideshow.yml' )
  if File.exists?( props_work_file )
    puts "Loading settings from '#{props_work_file}'..."
    @props = @props_work = Props.load_file_with_erb( props_work_file, binding(), @props )
  end
  
  # load shortcuts
  load_shortcuts
end

#load_shortcutsObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/slideshow/config.rb', line 51

def load_shortcuts
  # load default index/registry for shortcuts
  props_shortcuts_default_file = File.join( Slideshow.root, 'config', 'slideshow.index.yml' )
  @props_shortcuts = @props_shortcuts_default = Props.load_file( props_shortcuts_default_file )

  # check for update (slideshow.index.yml) in home folder

  props_shortcuts_home_file = File.join( Env.home, 'slideshow.index.yml' )
  if File.exists?( props_shortcuts_home_file )
    puts "Loading shortcut index from '#{props_shortcuts_home_file}'..."
    @props_shortcuts = @props_shortcuts_home = Props.load_file( props_shortcuts_home_file, @props_shortcuts )
  end
  
  # todo: add props from (optional) fetch section from 'standard' props (e.g. props[:fetch])
  #  - allows user to add own shortcuts in slideshow.yml settings
end

#map_fetch_shortcut(key) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/slideshow/config.rb', line 69

def map_fetch_shortcut( key )
  # NB: always returns an array!!!  0,1 or more entries
  # - no value - return empty ary
  
  ## todo: normalize key???
  value = @props.fetch_from_section( 'fetch', key, @props_shortcuts.fetch( key, nil ))

  if value.nil?
    []
  elsif value.kind_of?( String )
    [value]
  else  # assume it's an array already;  ## todo: check if it's an array
    value
  end
end

#markdown_post_processing?(lib) ⇒ Boolean

Returns:

  • (Boolean)


165
166
167
168
# File 'lib/slideshow/config.rb', line 165

def markdown_post_processing?( lib )
  ## todo: normalize key/lib???
  @props.fetch_from_section( lib, 'post-processing', true )
end

#shortcut_index_fileObject



45
46
47
48
# File 'lib/slideshow/config.rb', line 45

def shortcut_index_file
  ## e.g. ~/slideshow.index.yml
  File.join( Env.home, 'slideshow.index.yml' )
end

#slide?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/slideshow/config.rb', line 17

def slide?
  @opts.slide?
end

#takahashi?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/slideshow/config.rb', line 21

def takahashi?
  @opts.takahashi?
end

#text_filtersObject



202
203
204
# File 'lib/slideshow/config.rb', line 202

def text_filters
  @props.fetch( 'filters', [] )
end