Class: RhetButler::FileManager
- Inherits:
-
Object
- Object
- RhetButler::FileManager
- Defined in:
- lib/rhet-butler/file-manager.rb
Overview
All file handling is routed through this class.
Basic configuration (including additional search paths for other configs and slides) can only come from the current directory or the “basic search path”:
-
.rhet/
-
~/.rhet/
-
/usr/share/rhet-butler/
-
/etc/rhet-butler/
- the defaults provided by the gem
-
Other paths configured by –sources or sources: [] in base configs are added after the current directory and before that list.
There are several subdirectories searched in these search paths, depending on context:
-
presenter/
-
viewer/
-
common/
Presenter and viewer files are used for displaying the appropriate presentation, so that the presenter can have a different display (e.g. with notes and a timer) than the audience (e.g. nifty transitions etc.)
Slide files are loaded without a sub-directory - they’re always the same regardless of context.
Presenter configs, templates, and assets are searched for in presenter, then common.
Audience configs, templates and assets are searched for in viewer, then common.
-
Instance Method Summary collapse
- #all_files ⇒ Object
- #aspect_config(aspect_name) ⇒ Object
- #aspect_search_path(aspect) ⇒ Object
- #aspect_templates(aspect, template_cache = nil) ⇒ Object
- #base_assets(template_cache) ⇒ Object
- #base_config ⇒ Object
- #base_config_search_path ⇒ Object
- #base_config_set ⇒ Object
- #configured_search_path ⇒ Object
- #current_directory ⇒ Object
-
#initialize(overrides = nil) ⇒ FileManager
constructor
A new instance of FileManager.
- #load_config(files) ⇒ Object
- #slide_files ⇒ Object
- #target_valise ⇒ Object
- #template_config(type) ⇒ Object
Constructor Details
#initialize(overrides = nil) ⇒ FileManager
Returns a new instance of FileManager.
43 44 45 46 47 |
# File 'lib/rhet-butler/file-manager.rb', line 43 def initialize(overrides = nil) @overrides = overrides || {} @cached_configs = {} @cached_templates = {} end |
Instance Method Details
#all_files ⇒ Object
57 58 59 |
# File 'lib/rhet-butler/file-manager.rb', line 57 def all_files current_directory + configured_search_path + base_config_set end |
#aspect_config(aspect_name) ⇒ Object
79 80 81 |
# File 'lib/rhet-butler/file-manager.rb', line 79 def aspect_config(aspect_name) load_config(aspect_search_path(aspect_name)) end |
#aspect_search_path(aspect) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/rhet-butler/file-manager.rb', line 95 def aspect_search_path(aspect) aspect = aspect.to_s set = all_files.sub_set(aspect) set += all_files.sub_set("common") set += all_files return set end |
#aspect_templates(aspect, template_cache = nil) ⇒ Object
89 90 91 92 93 |
# File 'lib/rhet-butler/file-manager.rb', line 89 def aspect_templates(aspect, template_cache = nil) aspect_search_path(aspect).templates do |mapping| (template_config(mapping) || {}).merge(:template_cache => template_cache) end end |
#base_assets(template_cache) ⇒ Object
83 84 85 86 87 |
# File 'lib/rhet-butler/file-manager.rb', line 83 def base_assets(template_cache) all_files.templates("assets") do |mapping| (template_config(mapping) || {}).merge(:template_cache => template_cache) end end |
#base_config ⇒ Object
49 50 51 |
# File 'lib/rhet-butler/file-manager.rb', line 49 def base_config @base_config ||= load_config(base_config_search_path) end |
#base_config_search_path ⇒ Object
61 62 63 64 |
# File 'lib/rhet-butler/file-manager.rb', line 61 def base_config_search_path set = current_directory + base_config_set set + set.sub_set("common") end |
#base_config_set ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/rhet-butler/file-manager.rb', line 123 def base_config_set @base_config_set ||= Valise::Set.define do rw [".rhet"] rw ["~", ".rhet"] rw ["", "usr", "share", "rhet-butler"] rw ["", "etc", "rhet-butler"] ro from_here(["..", "..", "..", "default-configuration"]) handle "config.yaml", :yaml, :hash_merge end end |
#configured_search_path ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/rhet-butler/file-manager.rb', line 114 def configured_search_path base_config = self.base_config Valise::Set.define do base_config.search_paths.each do |path| rw path end end end |
#current_directory ⇒ Object
107 108 109 110 111 112 |
# File 'lib/rhet-butler/file-manager.rb', line 107 def current_directory Valise::Set.define do rw "." handle "config.yaml", :yaml, :hash_merge end end |
#load_config(files) ⇒ Object
103 104 105 |
# File 'lib/rhet-butler/file-manager.rb', line 103 def load_config(files) Configuration.new(files, @overrides) end |
#slide_files ⇒ Object
53 54 55 |
# File 'lib/rhet-butler/file-manager.rb', line 53 def all_files.sub_set("slides") + all_files end |
#target_valise ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/rhet-butler/file-manager.rb', line 136 def target_valise @target_valise ||= begin target_directory = base_config.static_target Valise::define do rw target_directory end end end |
#template_config(type) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rhet-butler/file-manager.rb', line 66 def template_config(type) case type when "sass", "scss" load_paths = all_files.sub_set("assets/stylesheets").map(&:to_s) load_paths << Compass::Core.base_directory("stylesheets") FileUtils::mkdir_p base_config.template_cache {:template_options => { :load_paths => load_paths, :cache_location => base_config.template_cache }} else nil end end |