Class: Slideshow::Config
- Inherits:
-
Object
- Object
- Slideshow::Config
- Defined in:
- lib/slideshow/config.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
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(logger, opts) ⇒ Config
constructor
A new instance of Config.
- #known_extnames ⇒ Object
- #known_markdown_extnames ⇒ Object
- #known_rest_extnames ⇒ Object
- #known_textile_extnames ⇒ Object
- #load ⇒ Object
- #map_fetch_shortcut(key) ⇒ Object
- #map_quick_shortcut(key) ⇒ Object
- #markdown_post_processing?(lib) ⇒ Boolean
- #slide? ⇒ Boolean
- #takahashi? ⇒ Boolean
- #text_filters ⇒ Object
Constructor Details
#initialize(logger, opts) ⇒ Config
Returns a new instance of Config.
5 6 7 8 |
# File 'lib/slideshow/config.rb', line 5 def initialize( logger, opts ) @logger = logger @opts = opts end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/slideshow/config.rb', line 10 def logger @logger end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
10 11 12 |
# File 'lib/slideshow/config.rb', line 10 def 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?)
27 28 29 |
# File 'lib/slideshow/config.rb', line 27 def cache_dir File.join( Env.home, '.slideshow' ) end |
#config_dir ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/slideshow/config.rb', line 31 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
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/slideshow/config.rb', line 89 def default_fetch_shortcuts fetch_shortcuts = @props_default.fetch( 'fetch', {} ) 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? fetch_shortcuts.delete( 's6syntax' ) # better wait for next update fetch_shortcuts.delete( 's6blank' ) # better wait for next update fetch_shortcuts end |
#dump ⇒ Object
dump settings for debugging
74 75 76 77 78 79 80 81 82 |
# File 'lib/slideshow/config.rb', line 74 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 ## todo: add more config settings? end |
#google_analytics_code ⇒ Object
140 141 142 |
# File 'lib/slideshow/config.rb', line 140 def google_analytics_code @props.fetch_from_section( 'analytics', 'google', nil ) end |
#header(key) ⇒ Object
85 86 87 |
# File 'lib/slideshow/config.rb', line 85 def header( key ) @props.fetch_from_section( 'headers', normalize_key( key ), nil ) end |
#header_level ⇒ Object
12 13 14 |
# File 'lib/slideshow/config.rb', line 12 def header_level @opts.header_level end |
#helper_exprs ⇒ Object
165 166 167 168 169 170 |
# File 'lib/slideshow/config.rb', line 165 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
154 155 156 157 |
# File 'lib/slideshow/config.rb', line 154 def helper_renames ## NB: for now user cannot override/extent renames @props_builtin['helper']['renames'] end |
#helper_unparsed ⇒ Object
159 160 161 162 163 |
# File 'lib/slideshow/config.rb', line 159 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_extnames ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/slideshow/config.rb', line 122 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_rest_extnames end |
#known_markdown_extnames ⇒ Object
116 117 118 119 120 |
# File 'lib/slideshow/config.rb', line 116 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_rest_extnames ⇒ Object
108 109 110 |
# File 'lib/slideshow/config.rb', line 108 def known_rest_extnames @props.fetch_from_section( 'rest', 'extnames', [] ) end |
#known_textile_extnames ⇒ Object
112 113 114 |
# File 'lib/slideshow/config.rb', line 112 def known_textile_extnames @props.fetch_from_section( 'textile', 'extnames', [] ) end |
#load ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/slideshow/config.rb', line 43 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 end |
#map_fetch_shortcut(key) ⇒ Object
144 145 146 147 |
# File 'lib/slideshow/config.rb', line 144 def map_fetch_shortcut( key ) ## todo: normalize key??? @props.fetch_from_section( 'fetch', key, nil ) end |
#map_quick_shortcut(key) ⇒ Object
149 150 151 152 |
# File 'lib/slideshow/config.rb', line 149 def map_quick_shortcut( key ) ## todo: normalize key??? @props.fetch_from_section( 'quick', key, nil ) end |
#markdown_post_processing?(lib) ⇒ Boolean
103 104 105 106 |
# File 'lib/slideshow/config.rb', line 103 def markdown_post_processing?( lib ) ## todo: normalize key/lib??? @props.fetch_from_section( lib, 'post-processing', true ) end |
#slide? ⇒ Boolean
16 17 18 |
# File 'lib/slideshow/config.rb', line 16 def @opts. end |
#takahashi? ⇒ Boolean
20 21 22 |
# File 'lib/slideshow/config.rb', line 20 def takahashi? @opts.takahashi? end |
#text_filters ⇒ Object
136 137 138 |
# File 'lib/slideshow/config.rb', line 136 def text_filters @props.fetch( 'filters', [] ) end |