Class: Lolcommits::Plugin::Loltext
- Inherits:
-
Base
- Object
- Base
- Lolcommits::Plugin::Loltext
- 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
-
.runner_order ⇒ Array
Returns position(s) of when this plugin should run during the capture process.
Instance Method Summary collapse
-
#configure_options! ⇒ Hash
Prompts the user to configure text options.
-
#enabled? ⇒ Boolean
Returns true/false indicating if the plugin is enabled or not.
-
#run_post_capture ⇒ Object
Post-capture hook, runs after lolcommits captures a snapshot.
-
#valid_configuration? ⇒ Boolean
Returns true/false indicating if the plugin has been correctly configured.
Class Method Details
.runner_order ⇒ Array
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.
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.
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 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)
29 30 31 |
# File 'lib/lolcommits/plugin/loltext.rb', line 29 def enabled? configuration.empty? || super end |
#run_post_capture ⇒ Object
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 = config_option(:overlay, :overlay_percent).to_f debug "adding colorized overlay (#{color} at #{}% opacity)" = (255 * (/100)).round runner.. do |c| c.fill "#{color}#{sprintf('%02X',)}" 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..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., :message, clean_msg(runner.)) annotate(runner., :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)
41 42 43 |
# File 'lib/lolcommits/plugin/loltext.rb', line 41 def valid_configuration? configuration.empty? || super end |