Class: Slideshow::Fetch

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/slideshow/cli/commands/fetch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts, config) ⇒ Fetch

Returns a new instance of Fetch.



9
10
11
12
# File 'lib/slideshow/cli/commands/fetch.rb', line 9

def initialize( opts, config )
  @opts    = opts
  @config  = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



14
15
16
# File 'lib/slideshow/cli/commands/fetch.rb', line 14

def config
  @config
end

#optsObject (readonly)

Returns the value of attribute opts.



14
15
16
# File 'lib/slideshow/cli/commands/fetch.rb', line 14

def opts
  @opts
end

Instance Method Details

#fetch(src) ⇒ Object



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
# File 'lib/slideshow/cli/commands/fetch.rb', line 23

def fetch( src )
  
  logger.debug "src=>#{src}<"
  
  ## check for builtin shortcut (assume no / or \) 
  if src.index( '/' ).nil? && src.index( '\\' ).nil?
    shortcut = src.dup
    src = config.map_fetch_shortcut( src )

    if src.nil?
      puts "** Error: No mapping found for fetch shortcut '#{shortcut}'."
      return
    end
    puts "  Mapping fetch shortcut '#{shortcut}' to: #{src}"
  else
    shortcut = nil
  end

  ## if manifest includes .plugin assume it's a plugin
  if src.include?( '.plugin' )
    fetch_plugin( src )
  else # otherwise assume it's a template pack
    fetch_template( src )
  
    ###################################
    ## step 2) if shortcut exists (auto include quickstarter manifest w/ same name/key)
  
    if shortcut.present?
    
      src = config.map_quick_shortcut( shortcut )
      return if src.nil?   # no shortcut found; sorry; returning (nothing more to do)
    
      puts "  Mapping quick shortcut '#{shortcut}' to: #{src}"

      fetch_quick( src )
    end
  end

end

#fetch_allObject



17
18
19
20
21
# File 'lib/slideshow/cli/commands/fetch.rb', line 17

def fetch_all
  config.default_fetch_shortcuts.keys.each do |shortcut|
    fetch( shortcut )
  end
end

#fetch_plugin(src) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/slideshow/cli/commands/fetch.rb', line 93

def fetch_plugin( src )
  uri = URI.parse( src )
  logger.debug "scheme: #{uri.scheme}, host: #{uri.host}, port: #{uri.port}, path: #{uri.path}"
  
  # downcase basename w/ extension (remove .txt)
  pakname = File.basename( uri.path ).downcase.gsub('.txt','').gsub('.plugin','')
  pakpath = File.expand_path( "#{config.config_dir}/plugins/#{pakname}" )

  logger.debug "pakname >#{pakname}<"
  logger.debug "pakpath >#{pakpath}<"
 
  Pakman::Fetcher.new( logger ).fetch_pak( src, pakpath )
end

#fetch_quick(src) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/slideshow/cli/commands/fetch.rb', line 79

def fetch_quick( src )
  uri = URI.parse( src )
  logger.debug "scheme: #{uri.scheme}, host: #{uri.host}, port: #{uri.port}, path: #{uri.path}"
  
  # downcase basename w/ extension (remove .txt)
  pakname = File.basename( uri.path ).downcase.gsub('.txt','')
  pakpath = File.expand_path( "#{config.config_dir}/templates/#{pakname}" )

  logger.debug "pakname >#{pakname}<"
  logger.debug "pakpath >#{pakpath}<"
 
  Pakman::Fetcher.new( logger ).fetch_pak( src, pakpath )
end

#fetch_template(src) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/slideshow/cli/commands/fetch.rb', line 64

def fetch_template( src )
  # src = 'http://github.com/geraldb/slideshow/raw/d98e5b02b87ee66485431b1bee8fb6378297bfe4/code/templates/fullerscreen.txt'
  # src = 'http://github.com/geraldb/sandbox/raw/13d4fec0908fbfcc456b74dfe2f88621614b5244/s5blank/s5blank.txt'
  uri = URI.parse( src )
  logger.debug "scheme: #{uri.scheme}, host: #{uri.host}, port: #{uri.port}, path: #{uri.path}"
  
  pakname = File.basename( uri.path ).downcase.gsub('.txt','')
  pakpath = File.expand_path( "#{config.config_dir}/templates/#{pakname}" )
  
  logger.debug "packname >#{pakname}<"
  logger.debug "pakpath >#{pakpath}<"

  Pakman::Fetcher.new( logger ).fetch_pak( src, pakpath )
end