Class: Slideshow::Config
- Inherits:
-
Object
- Object
- Slideshow::Config
- Includes:
- LogUtils::Logging
- Defined in:
- lib/slideshow/config.rb
Instance Method Summary collapse
-
#cache_dir ⇒ Object
todo/fix: fix references after this move to here, that is, Config class - used in syntax/uv_helper (use config.cache_dir to access?).
- #config_dir ⇒ Object
- #default_fetch_shortcuts ⇒ Object
-
#dump ⇒ Object
dump settings for debugging.
- #google_analytics_code ⇒ Object
- #header(key) ⇒ Object
- #header_level ⇒ Object
- #helper_exprs ⇒ Object
- #helper_renames ⇒ Object
- #helper_unparsed ⇒ Object
-
#initialize(opts) ⇒ Config
constructor
A new instance of Config.
- #load ⇒ Object
- #load_shortcuts ⇒ Object
-
#manifest ⇒ Object
– todo: allow (direct) access to opts - why? why not? attr_reader :opts.
- #map_fetch_shortcut(key) ⇒ Object
- #output_path ⇒ Object
- #quick_manifest ⇒ Object
- #shortcut_index_file ⇒ Object
- #slide? ⇒ Boolean
- #takahashi? ⇒ Boolean
-
#test? ⇒ Boolean
in test mode (yes/no) - will (auto-)include test templates.
- #text_filters ⇒ Object
- #verbose? ⇒ Boolean
Constructor Details
#initialize(opts) ⇒ Config
Returns a new instance of Config.
9 10 11 |
# File 'lib/slideshow/config.rb', line 9 def initialize( opts ) @opts = opts end |
Instance Method Details
#cache_dir ⇒ Object
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_dir ⇒ Object
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_shortcuts ⇒ Object
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 |
#dump ⇒ Object
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_code ⇒ Object
169 170 171 |
# File 'lib/slideshow/config.rb', line 169 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_level ⇒ Object
18 |
# File 'lib/slideshow/config.rb', line 18 def header_level() @opts.header_level; end |
#helper_exprs ⇒ Object
184 185 186 187 188 189 |
# File 'lib/slideshow/config.rb', line 184 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_renames ⇒ Object
173 174 175 176 |
# File 'lib/slideshow/config.rb', line 173 def helper_renames ## NB: for now user cannot override/extent renames @props_builtin['helper']['renames'] end |
#helper_unparsed ⇒ Object
178 179 180 181 182 |
# File 'lib/slideshow/config.rb', line 178 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 |
#load ⇒ Object
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_shortcuts ⇒ Object
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 |
#manifest ⇒ Object
– todo: allow (direct) access to opts - why? why not? attr_reader :opts
16 |
# File 'lib/slideshow/config.rb', line 16 def manifest() @opts.manifest; 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 |
#output_path ⇒ Object
23 |
# File 'lib/slideshow/config.rb', line 23 def output_path() @opts.output_path; end |
#quick_manifest ⇒ Object
17 |
# File 'lib/slideshow/config.rb', line 17 def quick_manifest() @opts.quick_manifest; end |
#shortcut_index_file ⇒ Object
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
19 |
# File 'lib/slideshow/config.rb', line 19 def () @opts.; end |
#takahashi? ⇒ Boolean
20 |
# File 'lib/slideshow/config.rb', line 20 def takahashi?() @opts.takahashi?; end |
#test? ⇒ Boolean
in test mode (yes/no) - will (auto-)include test templates
21 |
# File 'lib/slideshow/config.rb', line 21 def test?() @opts.test?; end |
#text_filters ⇒ Object
165 166 167 |
# File 'lib/slideshow/config.rb', line 165 def text_filters @props.fetch( 'filters', [] ) end |
#verbose? ⇒ Boolean
22 |
# File 'lib/slideshow/config.rb', line 22 def verbose?() @opts.verbose?; end |