Class: Hookworm::DirectoryIndexUpdater
- Inherits:
-
Object
- Object
- Hookworm::DirectoryIndexUpdater
- Defined in:
- lib/hookworm/directory_index_updater.rb
Defined Under Namespace
Classes: TemplateContext
Instance Method Summary collapse
-
#initialize(cfg) ⇒ DirectoryIndexUpdater
constructor
A new instance of DirectoryIndexUpdater.
- #update_all!(root_dir) ⇒ Object
- #update_index!(directory) ⇒ Object
Constructor Details
#initialize(cfg) ⇒ DirectoryIndexUpdater
Returns a new instance of DirectoryIndexUpdater.
6 7 8 9 |
# File 'lib/hookworm/directory_index_updater.rb', line 6 def initialize(cfg) @path_base = cfg[:static_dir] @version = cfg[:version] end |
Instance Method Details
#update_all!(root_dir) ⇒ Object
11 12 13 14 15 |
# File 'lib/hookworm/directory_index_updater.rb', line 11 def update_all!(root_dir) Dir.glob(%W(#{root_dir} #{root_dir}/* #{root_dir}/**/*)) do |entry| update_index!(entry) if File.directory?(entry) end end |
#update_index!(directory) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/hookworm/directory_index_updater.rb', line 17 def update_index!(directory) File.open(File.join(directory, 'index.html'), 'w:UTF-8') do |f| f.write TemplateContext.new( @version, directory.gsub(/#{@path_base}/, ''), Dir.entries(directory).sort.reject { |e| e =~ /^(\.|index\.html)$/ } ).render(index_tmpl) end end |