Class: Slideshow::ManifestFinder

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging, ManifestHelper
Defined in:
lib/slideshow/commands/manifest_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ManifestHelper

#installed_plugin_manifest_patterns, #installed_plugin_manifests, #installed_quick_manifest_patterns, #installed_quick_manifests, #installed_template_manifest_patterns, #installed_template_manifests

Constructor Details

#initialize(config) ⇒ ManifestFinder

Returns a new instance of ManifestFinder.

[View source]

12
13
14
15
# File 'lib/slideshow/commands/manifest_finder.rb', line 12

def initialize( config )
  @config = config
  @usrdir = File.expand_path( Dir.pwd )  # save original (current) working directory
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.


17
18
19
# File 'lib/slideshow/commands/manifest_finder.rb', line 17

def config
  @config
end

#usrdirObject (readonly)

original working dir (user called slideshow from)


18
19
20
# File 'lib/slideshow/commands/manifest_finder.rb', line 18

def usrdir
  @usrdir
end

Instance Method Details

#find_manifestsrc(manifest_arg) ⇒ Object

rename - just use find_manifest ??

[View source]

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
# File 'lib/slideshow/commands/manifest_finder.rb', line 21

def find_manifestsrc( manifest_arg )    ## rename - just use find_manifest ??

  manifest_path_or_name = manifest_arg.dup   ## make a copy

  # add .txt file extension if missing (for convenience)
  if manifest_path_or_name.downcase.ends_with?( '.txt' ) == false
    manifest_path_or_name << '.txt'
  end

  logger.debug "manifest=#{manifest_path_or_name}"

  # check if file exists (if yes use custom template package!) - allows you to override builtin package with same name
  if File.exists?( manifest_path_or_name )
    manifestsrc = manifest_path_or_name
  else
    # check for builtin manifests
    manifests = installed_template_manifests
    matches = manifests.select { |m| m[0] == manifest_path_or_name }

    if matches.empty?
      puts "*** error: unknown template manifest '#{manifest_path_or_name}'"
      puts
      puts "Use"
      puts "  slideshow list      # or"
      puts "  slideshow ls"
      puts "to see what template packs you have installed."
      puts
      puts "Use"
      puts "  slideshow install #{manifest_path_or_name.sub('.txt','')}      # or"
      puts "  slideshow i #{manifest_path_or_name.sub('.txt','')}"
      puts "to (try to) install the missing template pack."
      puts
      puts "See github.com/slideshow-templates for some ready-to-use/download template packs"
      puts "or use your very own."
      puts

      # todo: list installed manifests - why? why not?
      exit 2
    end

    manifestsrc = matches[0][1]
  end

  ### todo: use File.expand_path( xx, relative_to ) always with second arg
  ##   do NOT default to cwd (because cwd will change!)

  # Reference src with absolute path, because this can be used with different pwd
  manifestsrc = File.expand_path( manifestsrc, usrdir )
  manifestsrc
end