Class: Pluto::Formatter

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging, ManifestHelper, Models
Defined in:
lib/pluto/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ManifestHelper

#installed_template_manifest_patterns, #installed_template_manifests

Constructor Details

#initialize(opts, config) ⇒ Formatter

Returns a new instance of Formatter.



10
11
12
13
# File 'lib/pluto/formatter.rb', line 10

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

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



15
16
17
# File 'lib/pluto/formatter.rb', line 15

def opts
  @opts
end

Instance Method Details

#run(arg) ⇒ Object



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
# File 'lib/pluto/formatter.rb', line 21

def run( arg )
  manifest_name = opts.manifest
  manifest_name = manifest_name.downcase.gsub('.txt', '' )  # remove .txt if present
  
  logger.debug "manifest=#{manifest_name}"

  # check for matching manifests
  manifests = installed_template_manifests.select { |m| m[0] == manifest_name+'.txt' }
      
  if manifests.empty?
    
    ### try - autodownload
    puts "*** template pack '#{manifest_name}' not found; trying auto-install..."
    
    Installer.new( opts ).install( manifest_name )

    ### try again
    
    # check for matching manifests
    manifests = installed_template_manifests.select { |m| m[0] == manifest_name+'.txt' }
    
    if manifests.empty?
       puts "*** error: unknown template pack '#{manifest_name}'; use pluto ls to list installed template packs"
       exit 2
    end
  end

  manifestsrc = manifests[0][1]
  pakpath     = opts.output_path
  
      
  name = arg
  Pakman::Templater.new.merge_pak( manifestsrc, pakpath, binding, name )
end

#siteObject



17
18
19
# File 'lib/pluto/formatter.rb', line 17

def site
  @config
end