Class: Lolcommits::Loltext

Inherits:
Plugin
  • Object
show all
Defined in:
lib/lolcommits/plugins/loltext.rb

Instance Attribute Summary

Attributes inherited from Plugin

#options, #runner

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plugin

#configuration, #configure_options!, #configured?, #debug, #execute, #puts, #valid_configuration?

Constructor Details

#initialize(runner) ⇒ Loltext

Returns a new instance of Loltext.



4
5
6
7
# File 'lib/lolcommits/plugins/loltext.rb', line 4

def initialize(runner)
  super
  @font_location = runner ? runner.font : nil
end

Class Method Details

.nameObject



47
48
49
# File 'lib/lolcommits/plugins/loltext.rb', line 47

def self.name
  'loltext'
end

Instance Method Details

#enabled?Boolean

enabled by default (if no configuration exists)

Returns:

  • (Boolean)


10
11
12
# File 'lib/lolcommits/plugins/loltext.rb', line 10

def enabled?
  !configured? || super
end

#runObject



14
15
16
17
18
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
# File 'lib/lolcommits/plugins/loltext.rb', line 14

def run
  font_location = @font_location || File.join(Configuration::LOLCOMMITS_ROOT,
                                              'vendor',
                                              'fonts',
                                              'Impact.ttf')

  debug 'Annotating image via MiniMagick'
  image = MiniMagick::Image.open(self.runner.main_image)
  image.combine_options do |c|
    c.gravity 'SouthWest'
    c.fill 'white'
    c.stroke 'black'
    c.strokewidth '2'
    c.pointsize(self.runner.animate? ? '24' : '48')
    c.interline_spacing '-9'
    c.font font_location
    c.annotate '0', clean_msg(self.runner.message)
  end

  image.combine_options do |c|
    c.gravity 'NorthEast'
    c.fill 'white'
    c.stroke 'black'
    c.strokewidth '2'
    c.pointsize(self.runner.animate? ? '21' : '32')
    c.font font_location
    c.annotate '0', self.runner.sha
  end

  debug "Writing changed file to #{self.runner.main_image}"
  image.write self.runner.main_image
end