Skip to content

Commit

Permalink
Merge pull request #2 from lolcommits/use-captureready-hook
Browse files Browse the repository at this point in the history
Use captureready hook
  • Loading branch information
matthutchinson committed Apr 17, 2017
2 parents cecfec8 + dcde49d commit 84e89b5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,18 @@ You **should** override the following methods in this class:
* `def self.name` - identifies the plugin to lolcommits and users, keep things
simple and choose a name that matches your gem name.
* `def self.runner_order` - return the hooks this plugin should run at during
the capture process (`:precapture`, `:postcapture` or both).
* `def run_precapture` or `def run_postcapture` - override with your plugin's
behaviour.
the capture process (`:precapture`, `:postcapture` and/or `:captureready`).
* `def run_precapture`, `def run_postcapture` and/or `def run_captureready` -
override with your plugin's behaviour.

Three hooks points are available during the lolcommits capture process.

* `:precapture` - called before the camera starts capturing, at this point you
could alter the commit message/sha text.
* `:postcapture` - called immediately after the camera snaps the raw image (or
video for gif captures) use this hook to alter the image.
`:captureready` - called after all `:postcapture` plugins have ran, at this
point the capture should be ready for exporting or sharing.

### Plugin configuration

Expand Down Expand Up @@ -91,15 +100,15 @@ If your plugin requires no configuration, you could override the `enabled?`
method to always return `true`. Users could disable your plugin by uninstalling
the gem.

By default a plugin will only run its pre or post capture hook if:
By default a plugin will only run it's capture hooks if:

* `valid_configuration?` returns true
* `enabled?` returns true

For more help, check out [the
documentation](http://www.rubydoc.info/github/lolcommits/lolcommits-plugin-sample/Lolcommits/Plugin/Sample)
for this plugin, or take a look at [other
lolcommit_plugins](https://github.com/lolcommits) in the wild.
lolcommit_plugins](https://github.com/search?q=topic%3Alolcommits-plugin+org%3Alolcommits&type=Repositories) in the wild.

### The Lolcommits 'runner'

Expand All @@ -118,8 +127,8 @@ Use these runner methods to access the commit, repo and configuration:
[Lolcommits::Configuration](https://github.com/mroth/lolcommits/blob/master/lib/lolcommits/configuration.rb)
instance.

After the capturing process has completed, (i.e. in the `run_postcapture`
hook) these methods will reveal the captured snapshot file.
After the capturing process has completed, (i.e. in the `run_postcapture` or
`run_captureready` hooks) these methods will reveal the captured snapshot file.

* `runner.snapshot_loc` - the raw image file.
* `runner.main_image` - the processed image file, resized, with text overlay
Expand Down
13 changes: 8 additions & 5 deletions lib/lolcommits/plugin/sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ def self.name
# Returns position(s) of when this plugin should run during the capture
# process.
#
# Defines when your plugin will execute in the capture process. This must
# Defines when the plugin will execute in the capture process. This must
# be defined, if the method returns nil, or [] the plugin will never run.
# Three hook positions exist, your plugin code can execute in one or more
# of these.
#
# @return [Array] the position(s) (:precapture and/or :postcapture)
# @return [Array] the position(s) (:precapture, :postcapture,
# :captureready)
#
def self.runner_order
[:precapture, :postcapture]
[:precapture, :captureready]
end

##
Expand Down Expand Up @@ -58,15 +61,15 @@ def run_precapture

##
#
# Post-capture hook, runs after lolcommits captures a snapshot.
# Capture ready hook, runs after lolcommits captures a snapshot.
#
# Override this method to execute plugin code after the lolcommit snapshot
# is captured.
#
# Prints a short (emoji themed) message to STDOUT with the current commit
# sha.
#
def run_postcapture
def run_captureready
puts "✨ wow! #{self.runner.sha} is your best looking commit yet! 😘 💻"
end

Expand Down
4 changes: 2 additions & 2 deletions lolcommits-plugin-sample.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = "lolcommits-plugin-sample"
spec.version = "0.1.3"
spec.version = "0.1.4"
spec.authors = ["Matthew Hutchinson"]
spec.email = ["matt@hiddenloop.com"]

Expand All @@ -30,7 +30,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 2.0.0"

spec.add_development_dependency "lolcommits", ">= 0.9.3"
spec.add_development_dependency "lolcommits", ">= 0.9.4"
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
spec.add_development_dependency "minitest"
Expand Down
8 changes: 4 additions & 4 deletions test/lolcommits/plugin/sample_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def plugin_name
::Lolcommits::Plugin::Sample.name.must_equal plugin_name
end

it 'should run on post capturing' do
::Lolcommits::Plugin::Sample.runner_order.must_equal [:precapture, :postcapture]
it 'should run on precapture and captureready' do
::Lolcommits::Plugin::Sample.runner_order.must_equal [:precapture, :captureready]
end

describe 'with a runner' do
Expand Down Expand Up @@ -58,13 +58,13 @@ def valid_enabled_config
after { teardown_repo }
end

describe '#run_postcapture' do
describe '#run_captureready' do

before { commit_repo_with_message }

it 'should output a message to stdout' do
in_repo do
Proc.new { plugin.run_postcapture }.
Proc.new { plugin.run_captureready }.
must_output "✨ wow! #{last_commit.sha[0..10]} is your best looking commit yet! 😘 💻\n"
end
end
Expand Down

0 comments on commit 84e89b5

Please sign in to comment.