Skip to content

Commit

Permalink
Merge pull request #304 from Ruxton/feature/south_gravity_and_overlays
Browse files Browse the repository at this point in the history
Add south gravity, overlays & uppercasing to loltext
  • Loading branch information
matthutchinson committed May 15, 2016
2 parents 99213b6 + 2fe1fa8 commit b3786fa
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Metrics/AbcSize:
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 127
Max: 150

# Offense count: 5
Metrics/CyclomaticComplexity:
Expand Down
16 changes: 14 additions & 2 deletions features/lolcommits.feature
Original file line number Diff line number Diff line change
Expand Up @@ -121,32 +121,44 @@ Feature: Basic UI functionality
Then I type "loltext"
And I wait for output to contain "enabled:"
Then I type "true"
And I wait for output to contain "global text:"
And I wait for output to contain "overlay"
Then I type "true"
And I wait for output to contain "overlay colors"
Then I type "#2884ae,#7e231f"
And I wait for output to contain "message text:"
And I wait for output to contain "color"
Then I type "red"
And I wait for output to contain "font"
Then I type "my-font.ttf"
And I wait for output to contain "position"
Then I type "SouthEast"
Then I type "SE"
And I wait for output to contain "size"
Then I type "32"
And I wait for output to contain "stroke color"
Then I type "white"
And I wait for output to contain "uppercase"
Then I type "true"
And I wait for output to contain "sha text"
Then I type ""
Then I type ""
Then I type ""
Then I type ""
Then I type ""
Then I type ""
Then the output should contain "Successfully configured plugin: loltext"
And the output should contain a list of plugins
And a file named "~/.lolcommits/config-test/config.yml" should exist
When I successfully run `lolcommits --show-config`
Then the output should match /enabled: true/
And the output should match /:overlay: true/
And the output should match /:overlay_colors:.*\n.*['"]#2884ae['"].*\n.*['"]#7e231f['"].*\n/
And the output should match /:font: my-font\.ttf/
And the output should match /:size: 32/
And the output should match /:position: SouthEast/
And the output should match /:position: S/
And the output should match /:color: red/
And the output should match /:stroke_color: white/
And the output should match /:uppercase: true/

Scenario: Configuring loltext plugin in test mode affects test loldir not repo loldir
Given I am in a git repo named "testmode-config-test"
Expand Down
47 changes: 38 additions & 9 deletions lib/lolcommits/plugins/loltext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,39 @@ def enabled?
def run_postcapture
debug 'Annotating image via MiniMagick'
image = MiniMagick::Image.open(runner.main_image)
if config_option(:global, :overlay)
image.combine_options do |c|
c.fill config_option(:global, :overlay_colors).sample
c.colorize 50
end
end

annotate(image, :message, clean_msg(runner.message))
annotate(image, :sha, runner.sha)
debug "Writing changed file to #{runner.main_image}"
image.write runner.main_image
end

def annotate(image, type, string)
debug("annotating #{type} text to image")
debug("annotating #{type} to image with #{string}")

transformed_position = position_transform(config_option(type, :position))
annotate_location = '0'
if transformed_position == 'South'
annotate_location = '+0+20' # Move South gravity off the edge of the image.
end

string.upcase! if config_option(type, :uppercase)

image.combine_options do |c|
c.strokewidth '2'
c.interline_spacing '-9'
c.strokewidth runner.animate? ? '1' : '2'
c.interline_spacing(-(config_option(type, :size) / 5))
c.stroke config_option(type, :stroke_color)
c.fill config_option(type, :color)
c.gravity position_transform(config_option(type, :position))
c.pointsize runner.animate? ? 24 : config_option(type, :size)
c.gravity transformed_position
c.pointsize runner.animate? ? (config_option(type, :size) / 2) : config_option(type, :size)
c.font config_option(type, :font)
c.annotate '0', string
c.annotate annotate_location, string
end
end

Expand All @@ -45,10 +60,11 @@ def configure_options!
puts
puts ' * blank options use the (default)'
puts ' * use full absolute path to fonts'
puts ' * valid positions are NE, NW, SE, SW, C (centered)'
puts ' * valid positions are NE, NW, SE, SW, S, C (centered)'
puts ' * colors can be hex #FC0 value or a string \'white\''
puts '------------------------------------------------------'

options[:global] = configure_sub_options(:global)
options[:message] = configure_sub_options(:message)
options[:sha] = configure_sub_options(:sha)
end
Expand All @@ -65,25 +81,36 @@ def configure_sub_options(type)
defaults.keys.sort_by(&:to_s).reduce({}) do |acc, opt|
print " #{opt.to_s.tr('_', ' ')} (#{defaults[opt]}): "
val = parse_user_input(STDIN.gets.strip)
val = val.split(',') if opt == :overlay_colors && !val.nil?
acc.merge(opt => val)
end
end

def config_defaults
{
:global => {
:overlay => false,
:overlay_colors => [
'#2e4970', '#674685', '#ca242f', '#1e7882', '#2884ae', '#4ba000',
'#187296', '#7e231f', '#017d9f', '#e52d7b', '#0f5eaa', '#e40087',
'#5566ac', '#ed8833', '#f8991c', '#408c93', '#ba9109'
]
},
:message => {
:font => DEFAULT_FONT_PATH,
:size => 48,
:position => 'SW',
:color => 'white',
:stroke_color => 'black'
:stroke_color => 'black',
:uppercase => false
},
:sha => {
:font => DEFAULT_FONT_PATH,
:size => 32,
:position => 'NE',
:color => 'white',
:stroke_color => 'black'
:stroke_color => 'black',
:uppercase => false
}
}
end
Expand Down Expand Up @@ -112,6 +139,8 @@ def position_transform(position)
'SouthWest'
when 'C'
'Center'
when 'S'
'South'
end
end

Expand Down

0 comments on commit b3786fa

Please sign in to comment.