class Lolcommits::Loltext
Public Class Methods
name()
click to toggle source
# File lib/lolcommits/plugins/loltext.rb, line 47 def self.name 'loltext' end
new(runner)
click to toggle source
Calls superclass method
Lolcommits::Plugin::new
# File lib/lolcommits/plugins/loltext.rb, line 4 def initialize(runner) super @font_location = runner ? runner.font : nil end
Public Instance Methods
is_enabled?()
click to toggle source
enabled by default (if no configuration exists)
Calls superclass method
Lolcommits::Plugin#is_enabled?
# File lib/lolcommits/plugins/loltext.rb, line 10 def is_enabled? !is_configured? || super end
run()
click to toggle source
# 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
Private Instance Methods
clean_msg(text)
click to toggle source
do whatever is required to commit message to get it clean and ready for imagemagick
# File lib/lolcommits/plugins/loltext.rb, line 55 def clean_msg(text) wrapped_text = word_wrap text escape_quotes wrapped_text end
escape_quotes(text)
click to toggle source
conversion for quotation marks to avoid shell interpretation does not seem to be a safe way to escape cross-platform?
# File lib/lolcommits/plugins/loltext.rb, line 62 def escape_quotes(text) text.gsub(/"/, "''") end
word_wrap(text, col = 27)
click to toggle source
convenience method for word wrapping based on github.com/cmdrkeene/memegen/blob/master/lib/meme_generator.rb
# File lib/lolcommits/plugins/loltext.rb, line 68 def word_wrap(text, col = 27) wrapped = text.gsub(/(.{1,#{col + 4}})(\s+|\Z)/, "\\1\n") wrapped.chomp! end