Module: Slideshow::Manifest
- Included in:
- Gen
- Defined in:
- lib/slideshow/manifest.rb
Instance Method Summary (collapse)
- - (Object) find_manifests(patterns)
- - (Object) installed_generator_manifests
- - (Object) installed_template_manifests
- - (Object) load_manifest(path)
- - (Object) load_manifest_core(path)
Instance Method Details
- (Object) find_manifests(patterns)
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/slideshow/manifest.rb', line 50 def find_manifests( patterns ) manifests = [] patterns.each do |pattern| pattern.gsub!( '\\', '/') # normalize path; make sure all path use / only logger.debug "Checking #{pattern}" Dir.glob( pattern ) do |file| logger.debug " Found manifest: #{file}" manifests << [ File.basename( file ), file ] end end manifests end |
- (Object) installed_generator_manifests
65 66 67 68 69 70 71 72 73 |
# File 'lib/slideshow/manifest.rb', line 65 def installed_generator_manifests # 1) search gem/templates builtin_patterns = [ "#{File.dirname( LIB_PATH )}/templates/*.txt.gen" ] find_manifests( builtin_patterns ) end |
- (Object) installed_template_manifests
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/slideshow/manifest.rb', line 75 def installed_template_manifests # 1) search ./templates # 2) search config_dir/templates # 3) search gem/templates builtin_patterns = [ "#{File.dirname( LIB_PATH )}/templates/*.txt" ] config_patterns = [ "#{config_dir}/templates/*.txt", "#{config_dir}/templates/*/*.txt" ] current_patterns = [ "templates/*.txt", "templates/*/*.txt" ] patterns = [] patterns += current_patterns unless LIB_PATH == File.( 'lib' ) # don't include working dir if we test code from repo (don't include slideshow/templates) patterns += config_patterns patterns += builtin_patterns find_manifests( patterns ) end |
- (Object) load_manifest(path)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/slideshow/manifest.rb', line 27 def load_manifest( path ) filename = path puts " Loading template manifest #{filename}..." manifest = load_manifest_core( filename ) # post-processing # normalize all source paths (1..-1) /make full path/add template dir templatesdir = File.dirname( path ) logger.debug "templatesdir=#{templatesdir}" manifest.each do |values| (1..values.size-1).each do |i| values[i] = "#{templatesdir}/#{values[i]}" logger.debug " path[#{i}]=>#{values[i]}<" end end manifest end |
- (Object) load_manifest_core(path)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/slideshow/manifest.rb', line 4 def load_manifest_core( path ) manifest = [] File.open( path ).readlines.each_with_index do |line,i| case line when /^\s*$/ # skip empty lines when /^\s*#.*$/ # skip comment lines else logger.debug "line #{i+1}: #{line.strip}" values = line.strip.split( /[ <,+]+/ ) # add source for shortcuts (assumes relative path; if not issue warning/error) values << values[0] if values.size == 1 manifest << values end end manifest end |