Class: Pluto::Formatter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TemplateHelper

#image_tag, #link_to, #strip_tags, #stylesheet_link_tag, #textify, #time_ago_in_words, #whitelist

Methods included from ManifestHelper

#installed_template_manifest_patterns, #installed_template_manifests

Constructor Details

#initialize(opts, config) ⇒ Formatter

Returns a new instance of Formatter.



12
13
14
15
# File 'lib/pluto/formatter.rb', line 12

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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#optsObject (readonly)

Returns the value of attribute opts.



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

def opts
  @opts
end

#siteObject (readonly)

Returns the value of attribute site.



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

def site
  @site
end

Instance Method Details

#run(arg) ⇒ Object



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

def run( arg )
  ## fix: change arg to planet_key or just key or similar
  #  todo: rename run to some less generic  - merge/build/etc. ??
  
  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

  ## for now - use single site w/ key planet
  ##-- fix!! allow multiple sites (planets)

  site_key = 'planet'
  @site = Site.find_by_key( site_key )
  if @site.nil?
    puts "*** warn: no site with key '#{site_key}' found; using untitled site record"
    @site = Site.new
    @site.title = 'Planet Untitled'
  end

  Pakman::Templater.new.merge_pak( manifestsrc, pakpath, binding, name )
end