Class: Lolcommits::Plugin::Loltext

Inherits:
Base
  • Object
show all
Defined in:
lib/lolcommits/plugin/loltext.rb

Constant Summary collapse

DEFAULT_FONT_PATH =
File.join(
  File.dirname(__FILE__), "../../../vendor/fonts/Impact.ttf"
).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runner_orderArray

Returns position(s) of when this plugin should run during the capture process. We want to add text to the image after capturing, but before capture is ready for sharing.

Returns:

  • (Array)

    the position(s) (:post_capture)



19
20
21
# File 'lib/lolcommits/plugin/loltext.rb', line 19

def self.runner_order
  [:post_capture]
end

Instance Method Details

#configure_options!Hash

Prompts the user to configure text options.

Returns:

  • (Hash)

    a hash of configured plugin options



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lolcommits/plugin/loltext.rb', line 50

def configure_options!
  puts '---------------------------------------------------------------'
  puts '  LolText options '
  puts ''
  puts '  * any blank options will use the (default)'
  puts '  * always use the full absolute path to fonts'
  puts '  * valid text positions are NE, NW, SE, SW, S, C (centered)'
  puts '  * colors can be hex #FC0 value or a string \'white\''
  puts '      - use `none` for no stroke color'
  puts '  * overlay fills your image with a random color'
  puts '      - set one or more overlay_colors with a comma seperator'
  puts '      - overlay_percent (0-100) sets the fill colorize strength'
  puts '---------------------------------------------------------------'

  super
end

#enabled?Boolean

Returns true/false indicating if the plugin is enabled or not. Enabled by default (if no configuration exists)

Returns:

  • (Boolean)

    true/false indicating if plugin is enabled



29
30
31
# File 'lib/lolcommits/plugin/loltext.rb', line 29

def enabled?
  configuration.empty? || super
end

#run_post_captureObject

Post-capture hook, runs after lolcommits captures a snapshot.

Annotate runner overlay with message, sha, optional border, and semi-transparent colored background (based on config)



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/lolcommits/plugin/loltext.rb', line 74

def run_post_capture
  debug "creating annotation overlay with MiniMagick"
  if config_option(:overlay, :enabled)
    color = config_option(:overlay, :overlay_colors).split(',').map(&:strip).sample
    overlay_percent = config_option(:overlay, :overlay_percent).to_f
    debug "adding colorized overlay (#{color} at #{overlay_percent}% opacity)"
    overlay_percent = (255 * (overlay_percent/100)).round

    runner.overlay.combine_options do |c|
      c.fill "#{color}#{sprintf('%02X',overlay_percent)}"
      c.draw "color 0,0 reset"
    end
  end

  if config_option(:border, :enabled)
    debug "adding border (#{config_option(:border, :size)}px #{config_option(:border, :color)})"
    # mogrify doesn't allow compose, format forces use of convert
    runner.overlay.format("PNG32") do |c|
      c.compose "Copy"
      c.shave config_option(:border, :size)
      c.bordercolor config_option(:border, :color)
      c.border config_option(:border, :size)
    end
  end

  annotate(runner.overlay, :message, clean_msg(runner.message))
  annotate(runner.overlay, :sha, runner.sha)
end

#valid_configuration?Boolean

Returns true/false indicating if the plugin has been correctly configured.

Valid by default (if no configuration exists)

Returns:

  • (Boolean)

    true/false indicating if plugin is correct configured



41
42
43
# File 'lib/lolcommits/plugin/loltext.rb', line 41

def valid_configuration?
  configuration.empty? || super
end