Class: Ralber::Commands::Publish

Inherits:
Object
  • Object
show all
Defined in:
lib/ralber/commands/publish_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(args, options) ⇒ Publish

Returns a new instance of Publish.



10
11
12
13
14
15
# File 'lib/ralber/commands/publish_command.rb', line 10

def initialize(args, options) 
    @album = Ralber::Album.new(Dir.pwd)
    self.set_defaults(options)
    @options = options
    self.publish
end

Instance Method Details

#configure_destinationObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ralber/commands/publish_command.rb', line 37

def configure_destination
    dest = @options.to
    dest = @album.destination unless dest
    
    if not dest
       puts "Please provide a destination path with --to <path>"
       exit 2
    end

    @album.destination = dest

    if not (Pathname.new dest).absolute?
        dest = File.join(@album.path,dest)
    end
    
    return dest
end

#configure_templateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ralber/commands/publish_command.rb', line 22

def configure_template
    tpl = @options.template
    tpl = @album.template unless tpl
    tpl = "default" unless tpl
    tplObj = nil
    begin
        tplObj = Ralber::Template.find(tpl)
        @album.template = tpl
    rescue
        puts "Could not find template. Either give the name or path to a template via --template parameter, or put a 'template' config in album.json."
        exit 2
    end
    return tplObj
end

#message(context, message) ⇒ Object



67
68
69
# File 'lib/ralber/commands/publish_command.rb', line 67

def message(context, message)
    puts message
end

#publishObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ralber/commands/publish_command.rb', line 55

def publish
    template = self.configure_template
    dest = self.configure_destination                

    puts "please wait, work in progress..."
    publisher = Ralber::Publisher.new(@album, template)
    publisher.force = @options.force
    publisher.add_listener(self)
    publisher.publish_to(dest)
    publisher.save_album if @options.save
end

#set_defaults(options) ⇒ Object



17
18
19
20
# File 'lib/ralber/commands/publish_command.rb', line 17

def set_defaults(options)
    options.default \
        :title => nil
end