lolcommits-loltext 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7f540cfbbe558c62cbed5ce539fb1db7a8f8d57c
4
+ data.tar.gz: 5fff1e22ed73177e85a40bcd88e9485c1552cd5b
5
+ SHA512:
6
+ metadata.gz: ce01cb3c5333f4113950f250c6d3c78026e14632b504c1b2967e17119a426a81bdee5d67fd4c158496fec19b453b9e05285739b741468bc59f7da8935f6e8dd3
7
+ data.tar.gz: 47bf286e11da2c549085e265861d4bf18b2703f88b3e263c71d098eec206c2677c923a637d00fd975fa545c9a9fbec809ba7bd5ad0fddefd4e174a0e4aae5b8c
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.simplecov ADDED
@@ -0,0 +1,9 @@
1
+ SimpleCov.start do
2
+ add_filter '/test/'
3
+ add_filter '/vendor/'
4
+ end
5
+
6
+ SimpleCov.at_exit do
7
+ SimpleCov.result.format!
8
+ `open ./coverage/index.html` if RUBY_PLATFORM =~ /darwin/
9
+ end
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.0.0
6
+ - 2.1.7
7
+ - 2.2.4
8
+ - 2.3.3
9
+ - 2.4.1
10
+ - ruby-head
11
+
12
+ before_install:
13
+ - gem install bundler -v 1.13.7
14
+ - git --version
15
+ - git config --global user.email "lol@commits.org"
16
+ - git config --global user.name "Lolcommits"
17
+
18
+ matrix:
19
+ allow_failures:
20
+ - rvm: ruby-head
21
+
22
+ branches:
23
+ except:
24
+ - gh-pages
@@ -0,0 +1,50 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer via [GitHub][maintainer]. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [maintainer]: https://github.com/matthutchinson
49
+ [homepage]: http://contributor-covenant.org
50
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,37 @@
1
+ ### Contributing
2
+
3
+ Pull Requests are welcome! To start helping out:
4
+
5
+ [Fork](https://guides.github.com/activities/forking) then clone the repository:
6
+
7
+ git clone git@github.com:your-username/lolcommits-loltext.git
8
+
9
+ Create your feature branch:
10
+
11
+ git checkout -b my-new-feature
12
+
13
+ When you are happy with your change, run the full test suite:
14
+
15
+ bundle exec rake
16
+
17
+ With a passing test suite, commit your changes, push and submit a new [Pull
18
+ Request](https://github.com/lolcommits/lolcommits-loltext/compare):
19
+
20
+ git commit -am 'Added some feature'
21
+ git push origin my-new-feature
22
+
23
+ At this point you'll be waiting for one of our maintainers to review it. We will
24
+ try to reply to new Pull Requests within a few days. We might suggest some
25
+ changes, improvements or alternatives. To increase the chance that your pull
26
+ request gets accepted:
27
+
28
+ * Explain what your are doing (and why) in your Pull Request description.
29
+ * If you are fixing an
30
+ [issue](https://github.com/lolcommits/lolcommits-loltext/issues), link to
31
+ it in your description and [mention
32
+ it](https://help.github.com/articles/closing-issues-via-commit-messages) in
33
+ the commit message.
34
+ * Write a good [commit
35
+ message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
36
+ * Write tests.
37
+
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md ADDED
@@ -0,0 +1,168 @@
1
+ # Lolcommits Loltext
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/lolcommits-loltext.svg?style=flat)](http://rubygems.org/gems/lolcommits-loltext)
4
+ [![Travis Build Status](https://travis-ci.org/lolcommits/lolcommits-loltext.svg?branch=master)](https://travis-ci.org/lolcommits/lolcommits-loltext)
5
+ [![Coverage Status](https://coveralls.io/repos/github/lolcommits/lolcommits-loltext/badge.svg?branch=master)](https://coveralls.io/github/lolcommits/lolcommits-loltext)
6
+ [![Code Climate](https://codeclimate.com/github/lolcommits/lolcommits-loltext/badges/gpa.svg)](https://codeclimate.com/github/lolcommits/lolcommits-loltext)
7
+ [![Gem Dependency Status](https://gemnasium.com/badges/github.com/lolcommits/lolcommits-loltext.svg)](https://gemnasium.com/github.com/lolcommits/lolcommits-loltext)
8
+
9
+ [lolcommits](https://lolcommits.github.io/) takes a snapshot with your webcam
10
+ every time you git commit code, and archives a lolcat style image with it. Git
11
+ blame has never been so much fun!
12
+
13
+ This plugin annotates each lolcommit with the commit message and sha text. You
14
+ can style and position these however you like, or add a transparent overlay
15
+ color that covers the entire image.
16
+
17
+ By default your lolcommit will look something like this (maybe without the
18
+ horse):
19
+
20
+ ![horse
21
+ commit](https://github.com/lolcommits/lolcommits-loltext/raw/master/assets/images/horse.jpg)
22
+
23
+ You can easily change the plugin options to achieve something like this:
24
+
25
+ ![hipster
26
+ commit](https://github.com/lolcommits/lolcommits-loltext/raw/master/assets/images/hipster.jpg)
27
+
28
+ See [below](https://github.com/lolcommits/lolcommits-loltext#configuration) for
29
+ more information on the options available.
30
+
31
+ ## Requirements
32
+
33
+ * Ruby >= 2.0.0
34
+ * A webcam
35
+ * [ImageMagick](http://www.imagemagick.org)
36
+ * [ffmpeg](https://www.ffmpeg.org) (optional) for animated gif capturing
37
+
38
+ ## Installation
39
+
40
+ By default, this plugin is automatically included with the main lolcommits gem.
41
+ If you have uninstalled this gem, install it again with:
42
+
43
+ $ gem install lolcommits-loltext
44
+
45
+ That's it! Every lolcommit will now be stamped with your commit message and sha.
46
+ This plugin is enabled by default (if no configuration for it exists). To
47
+ disable (so no text or overlay is applied) use:
48
+
49
+ $ lolcommits --config -p loltext
50
+ # and set enabled to `false`
51
+
52
+ ### Configuration
53
+
54
+ Configure this plugin with:
55
+
56
+ $ lolcommits --config -p loltext
57
+ # set enabled to `true` (then set your own options or choose the defaults)
58
+
59
+ The following options are available:
60
+
61
+ * text color
62
+ * text font
63
+ * text position
64
+ * uppercase text?
65
+ * size (point size for the font)
66
+ * stroke color (font outline color, or none)
67
+ * transparent overlay (cover the image with a random background color)
68
+ * transparent overlay % (sets the fill colorize strength)
69
+
70
+ Please note that:
71
+
72
+ * The message and sha text can have different text options
73
+ * Any blank options will use the default (indicated when prompted for an option)
74
+ * Always use the full absolute path to font files
75
+ * Valid text positions are NE, NW, SE, SW, S, C (centered)
76
+ * Colors can be hex values (#FC0) or strings (white, red etc.)
77
+ * You can set one or more `overlay_colors` to pick from, separated with commas
78
+
79
+ With these options it is possible to create your own unique lolcommit format.
80
+ To achieve these '[hipster
81
+ styled](https://twitter.com/matthutchin/status/738411190343368704)' 🕶 commits,
82
+ try the following:
83
+
84
+ ```
85
+ loltext:
86
+ enabled: true
87
+ :message:
88
+ :color: white
89
+ :font: "/Users/matt/Library/Fonts/Raleway-Light.ttf"
90
+ :position: C
91
+ :size: 30
92
+ :stroke_color: none
93
+ :uppercase: true
94
+ :sha:
95
+ :color: white
96
+ :font: "/Users/matt/Library/Fonts/Raleway-Light.ttf"
97
+ :position: S
98
+ :size: 20
99
+ :stroke_color: none
100
+ :uppercase: false
101
+ :overlay:
102
+ :enabled: true
103
+ ```
104
+
105
+ **NOTE**: you can grab the '_Raleway-Light_' font for free from
106
+ [fontsquirrel](https://www.fontsquirrel.com/fonts/Raleway).
107
+
108
+ ## Development
109
+
110
+ Check out this repo and run `bin/setup`, to install all dependencies and
111
+ generate docs. Run `bundle exec rake` to run all tests and generate a coverage
112
+ report.
113
+
114
+ You can also run `bin/console` for an interactive prompt that will allow you to
115
+ experiment with the gem code.
116
+
117
+ ## Tests
118
+
119
+ MiniTest is used for testing. Run the test suite with:
120
+
121
+ $ rake test
122
+
123
+ ## Docs
124
+
125
+ Generate docs for this gem with:
126
+
127
+ $ rake rdoc
128
+
129
+ ## Troubles?
130
+
131
+ If you think something is broken or missing, please raise a new
132
+ [issue](https://github.com/lolcommits/lolcommits-loltext/issues). Take
133
+ a moment to check it hasn't been raised in the past (and possibly closed).
134
+
135
+ ## Contributing
136
+
137
+ Bug [reports](https://github.com/lolcommits/lolcommits-loltext/issues) and [pull
138
+ requests](https://github.com/lolcommits/lolcommits-loltext/pulls) are welcome on
139
+ GitHub.
140
+
141
+ When submitting pull requests, remember to add tests covering any new behaviour,
142
+ and ensure all tests are passing on [Travis
143
+ CI](https://travis-ci.org/lolcommits/lolcommits-loltext). Read the
144
+ [contributing
145
+ guidelines](https://github.com/lolcommits/lolcommits-loltext/blob/master/CONTRIBUTING.md)
146
+ for more details.
147
+
148
+ This project is intended to be a safe, welcoming space for collaboration, and
149
+ contributors are expected to adhere to the [Contributor
150
+ Covenant](http://contributor-covenant.org) code of conduct. See
151
+ [here](https://github.com/lolcommits/lolcommits-loltext/blob/master/CODE_OF_CONDUCT.md)
152
+ for more details.
153
+
154
+ ## License
155
+
156
+ The gem is available as open source under the terms of
157
+ [LGPL-3](https://opensource.org/licenses/LGPL-3.0).
158
+
159
+ ## Links
160
+
161
+ * [Travis CI](https://travis-ci.org/lolcommits/lolcommits-loltext)
162
+ * [Test Coverage](https://coveralls.io/github/lolcommits/lolcommits-loltext)
163
+ * [Code Climate](https://codeclimate.com/github/lolcommits/lolcommits-loltext)
164
+ * [RDoc](http://rdoc.info/projects/lolcommits/lolcommits-loltext)
165
+ * [Issues](http://github.com/lolcommits/lolcommits-loltext/issues)
166
+ * [Report a bug](http://github.com/lolcommits/lolcommits-loltext/issues/new)
167
+ * [Gem](http://rubygems.org/gems/lolcommits-loltext)
168
+ * [GitHub](https://github.com/lolcommits/lolcommits-loltext)
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require "rdoc/task"
4
+
5
+ # generate docs
6
+ RDoc::Task.new do |rd|
7
+ rd.main = "README.md"
8
+ rd.title = "Lolcommits Loltext"
9
+ rd.rdoc_dir = "doc"
10
+ rd.options << "--all"
11
+ rd.rdoc_files.include("README.md", "LICENSE", "lib/**/*.rb")
12
+ end
13
+
14
+ # run tests
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs << "test"
17
+ t.libs << "lib"
18
+ t.test_files = FileList["test/**/*_test.rb"]
19
+ end
20
+
21
+ # run tests with code coverage (default)
22
+ namespace :test do
23
+ desc "Run all tests and features and generate a code coverage report"
24
+ task :coverage do
25
+ ENV['COVERAGE'] = 'true'
26
+ Rake::Task['test'].execute
27
+ end
28
+ end
29
+
30
+
31
+ task :default => ['test:coverage']
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lolcommits/loltext"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ # install deps
7
+ bundle install
8
+
9
+ # generate docs
10
+ bundle exec rake rdoc
@@ -0,0 +1,2 @@
1
+ require 'lolcommits/loltext/version'
2
+ require 'lolcommits/plugin/loltext'
@@ -0,0 +1,5 @@
1
+ module Lolcommits
2
+ module Loltext
3
+ VERSION = "0.0.2".freeze
4
+ end
5
+ end
@@ -0,0 +1,236 @@
1
+ require 'lolcommits/plugin/base'
2
+
3
+ module Lolcommits
4
+ module Plugin
5
+ class Loltext < Base
6
+
7
+ DEFAULT_FONT_PATH = File.join(
8
+ File.dirname(__FILE__), "../../../vendor/fonts/Impact.ttf"
9
+ ).freeze
10
+
11
+ ##
12
+ # Returns the name of the plugin. Identifies the plugin to lolcommits.
13
+ #
14
+ # @return [String] the plugin name
15
+ #
16
+ def self.name
17
+ 'loltext'
18
+ end
19
+
20
+ # Returns position(s) of when this plugin should run during the capture
21
+ # process.
22
+ #
23
+ # @return [Array] the position(s) (:precapture and/or :postcapture)
24
+ #
25
+ def self.runner_order
26
+ [:postcapture]
27
+ end
28
+
29
+ ##
30
+ # Returns true/false indicating if the plugin is enabled or not.
31
+ # Enabled by default (if no configuration exists)
32
+ #
33
+ # @return [Boolean] true/false indicating if plugin is enabled
34
+ #
35
+ def enabled?
36
+ !configured? || super
37
+ end
38
+
39
+ ##
40
+ # Returns true/false indicating if the plugin has been correctly
41
+ # configured.
42
+ #
43
+ # Valid by default (if no configuration exists)
44
+ #
45
+ # @return [Boolean] true/false indicating if plugin is correct configured
46
+ #
47
+ def valid_configuration?
48
+ !configured? || super
49
+ end
50
+
51
+ ##
52
+ # Prompts the user to configure text options.
53
+ #
54
+ # @return [Hash] a hash of configured plugin options
55
+ #
56
+ def configure_options!
57
+ options = super
58
+ if options['enabled']
59
+ puts '---------------------------------------------------------------'
60
+ puts ' LolText options '
61
+ puts ''
62
+ puts ' * any blank options will use the (default)'
63
+ puts ' * always use the full absolute path to fonts'
64
+ puts ' * valid text positions are NE, NW, SE, SW, S, C (centered)'
65
+ puts ' * colors can be hex #FC0 value or a string \'white\''
66
+ puts ' - use `none` for no stroke color'
67
+ puts ' * overlay fills your image with a random color'
68
+ puts ' - set one or more overlay_colors with a comma seperator'
69
+ puts ' - overlay_percent (0-100) sets the fill colorize strength'
70
+ puts '---------------------------------------------------------------'
71
+
72
+ options[:message] = configure_sub_options(:message)
73
+ options[:sha] = configure_sub_options(:sha)
74
+ options[:overlay] = configure_sub_options(:overlay)
75
+ end
76
+ options
77
+ end
78
+
79
+ ##
80
+ #
81
+ # Post-capture hook, runs after lolcommits captures a snapshot.
82
+ #
83
+ # Annotates the image with the git commit message and sha text
84
+ #
85
+ def run_postcapture
86
+ debug 'Annotating image via MiniMagick'
87
+ image = MiniMagick::Image.open(runner.main_image)
88
+ if config_option(:overlay, :enabled)
89
+ image.combine_options do |c|
90
+ c.fill config_option(:overlay, :overlay_colors).sample
91
+ c.colorize config_option(:overlay, :overlay_percent)
92
+ end
93
+ end
94
+
95
+ annotate(image, :message, clean_msg(runner.message))
96
+ annotate(image, :sha, runner.sha)
97
+ debug "Writing changed file to #{runner.main_image}"
98
+ image.write runner.main_image
99
+ end
100
+
101
+
102
+ private
103
+
104
+ def annotate(image, type, string)
105
+ debug("annotating #{type} to image with #{string}")
106
+
107
+ transformed_position = position_transform(config_option(type, :position))
108
+ annotate_location = '0'
109
+
110
+ # move South gravity off the edge of the image.
111
+ if transformed_position == 'South'
112
+ annotate_location = '+0+20'
113
+ end
114
+
115
+ string.upcase! if config_option(type, :uppercase)
116
+
117
+ image.combine_options do |c|
118
+ c.strokewidth runner.capture_animated? ? '1' : '2'
119
+ c.interline_spacing(-(config_option(type, :size) / 5))
120
+ c.stroke config_option(type, :stroke_color)
121
+ c.fill config_option(type, :color)
122
+ c.gravity transformed_position
123
+ c.pointsize runner.capture_animated? ? (config_option(type, :size) / 2) : config_option(type, :size)
124
+ c.font config_option(type, :font)
125
+ c.annotate annotate_location, string
126
+ end
127
+ end
128
+
129
+ # TODO: consider this type of configuration prompting in Plugin::Base
130
+ # i.e. allow sub option and working with hash of defaults
131
+ def configure_sub_options(type)
132
+ print "#{type}:\n"
133
+ defaults = config_defaults[type]
134
+
135
+ # sort option keys since different `Hash#keys` varys across Ruby versions
136
+ defaults.keys.sort_by(&:to_s).reduce({}) do |acc, opt|
137
+ # if we have an enabled key set to false, abort asking for any more options
138
+ if acc.key?(:enabled) && acc[:enabled] != true
139
+ acc
140
+ else
141
+ print " #{opt.to_s.tr('_', ' ')} (#{defaults[opt]}): "
142
+ val = parse_user_input(gets.chomp.strip)
143
+ # handle array options (comma seperated string)
144
+ if defaults[opt].is_a?(Array) && !val.nil?
145
+ val = val.split(',').map(&:strip).delete_if(&:empty?)
146
+ end
147
+ acc.merge(opt => val)
148
+ end
149
+ end
150
+ end
151
+
152
+ # default text styling and positions
153
+ def config_defaults
154
+ {
155
+ message: {
156
+ color: 'white',
157
+ font: DEFAULT_FONT_PATH,
158
+ position: 'SW',
159
+ size: 48,
160
+ stroke_color: 'black',
161
+ uppercase: false
162
+ },
163
+ sha: {
164
+ color: 'white',
165
+ font: DEFAULT_FONT_PATH,
166
+ position: 'NE',
167
+ size: 32,
168
+ stroke_color: 'black',
169
+ uppercase: false
170
+ },
171
+ overlay: {
172
+ enabled: false,
173
+ overlay_colors: [
174
+ '#2e4970', '#674685', '#ca242f', '#1e7882', '#2884ae', '#4ba000',
175
+ '#187296', '#7e231f', '#017d9f', '#e52d7b', '#0f5eaa', '#e40087',
176
+ '#5566ac', '#ed8833', '#f8991c', '#408c93', '#ba9109'
177
+ ],
178
+ overlay_percent: 50
179
+ }
180
+ }
181
+ end
182
+
183
+ # return the config option, defaults apply if not set
184
+ def config_option(type, option)
185
+ default_option = config_defaults[type][option]
186
+ if configuration[type]
187
+ configuration[type][option] || default_option
188
+ else
189
+ default_option
190
+ end
191
+ end
192
+
193
+ # explode psuedo-names for text positioning
194
+ def position_transform(position)
195
+ case position
196
+ when 'NE'
197
+ 'NorthEast'
198
+ when 'NW'
199
+ 'NorthWest'
200
+ when 'SE'
201
+ 'SouthEast'
202
+ when 'SW'
203
+ 'SouthWest'
204
+ when 'C'
205
+ 'Center'
206
+ when 'S'
207
+ 'South'
208
+ end
209
+ end
210
+
211
+ # do whatever is required to commit message to get it clean and ready for
212
+ # imagemagick
213
+ def clean_msg(text)
214
+ wrapped_text = word_wrap text
215
+ escape_quotes wrapped_text
216
+ escape_ats wrapped_text
217
+ end
218
+
219
+ # conversion for quotation marks to avoid shell interpretation
220
+ def escape_quotes(text)
221
+ text.gsub(/"/, "''")
222
+ end
223
+
224
+ def escape_ats(text)
225
+ text.gsub(/@/, '\@')
226
+ end
227
+
228
+ # convenience method for word wrapping
229
+ # based on https://github.com/cmdrkeene/memegen/blob/master/lib/meme_generator.rb
230
+ def word_wrap(text, col = 27)
231
+ wrapped = text.gsub(/(.{1,#{col + 4}})(\s+|\Z)/, "\\1\n")
232
+ wrapped.chomp!
233
+ end
234
+ end
235
+ end
236
+ end
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lolcommits/loltext/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lolcommits-loltext"
8
+ spec.version = Lolcommits::Loltext::VERSION
9
+ spec.authors = ["Matthew Hutchinson"]
10
+ spec.email = ["matt@hiddenloop.com"]
11
+ spec.summary = %q{lolcommits text annotation plugin}
12
+
13
+ spec.description = <<-EOF
14
+ Overlay the commit message and sha on your lolcommit. Configure text style,
15
+ positioning and an optional transparent overlay.
16
+ EOF
17
+
18
+ spec.homepage = "https://lolcommits.github.io"
19
+ spec.license = "LGPL-3"
20
+
21
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
22
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
23
+ if spec.respond_to?(:metadata)
24
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(assets|test|features)/}) }
31
+ spec.test_files = `git ls-files -- {test,features}/*`.split("\n")
32
+ spec.bindir = "bin"
33
+ spec.executables = []
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.required_ruby_version = ">= 2.0.0"
37
+
38
+ spec.add_development_dependency "lolcommits", ">= 0.9.3"
39
+ spec.add_development_dependency "bundler"
40
+ spec.add_development_dependency "rake"
41
+ spec.add_development_dependency "minitest"
42
+ spec.add_development_dependency "simplecov"
43
+ spec.add_development_dependency "coveralls"
44
+ end
@@ -0,0 +1,136 @@
1
+ require 'test_helper'
2
+
3
+ describe Lolcommits::Plugin::Loltext do
4
+
5
+ include Lolcommits::TestHelpers::GitRepo
6
+ include Lolcommits::TestHelpers::FakeIO
7
+
8
+ def plugin_name
9
+ 'loltext'
10
+ end
11
+
12
+ it 'should have a name' do
13
+ ::Lolcommits::Plugin::Loltext.name.must_equal plugin_name
14
+ end
15
+
16
+ it 'should run on post capturing' do
17
+ ::Lolcommits::Plugin::Loltext.runner_order.must_equal [:postcapture]
18
+ end
19
+
20
+ describe 'default font' do
21
+ it 'should have the correct file permissions' do
22
+ font_permissions = File.lstat(Lolcommits::Plugin::Loltext::DEFAULT_FONT_PATH).mode & 0o777
23
+ (font_permissions == 0o644).must_equal(true,
24
+ "expected perms of 644/664 but instead got #{format '%o', font_permissions}")
25
+ end
26
+ end
27
+
28
+ describe 'with a runner' do
29
+ def runner
30
+ # a simple lolcommits runner with an empty configuration Hash
31
+ @runner ||= Lolcommits::Runner.new(
32
+ config: OpenStruct.new(read_configuration: {})
33
+ )
34
+ end
35
+
36
+ def plugin
37
+ @plugin ||= Lolcommits::Plugin::Loltext.new(runner)
38
+ end
39
+
40
+ def valid_enabled_config
41
+ @config ||= OpenStruct.new(
42
+ read_configuration: {
43
+ plugin.class.name => { 'enabled' => true }
44
+ }
45
+ )
46
+ end
47
+
48
+ describe 'initalizing' do
49
+ it 'should assign runner and an enabled option' do
50
+ plugin.runner.must_equal runner
51
+ plugin.options.must_equal ['enabled']
52
+ end
53
+ end
54
+
55
+ describe '#enabled?' do
56
+ it 'should be true by default' do
57
+ plugin.enabled?.must_equal true
58
+ end
59
+
60
+ it 'should true when configured' do
61
+ plugin.runner.config = valid_enabled_config
62
+ plugin.enabled?.must_equal true
63
+ end
64
+ end
65
+
66
+ describe 'configuration' do
67
+ it 'should not be configured by default' do
68
+ plugin.configured?.must_equal false
69
+ end
70
+
71
+ it 'should allow plugin options to be configured' do
72
+ # enabled
73
+ inputs = ['true']
74
+
75
+ # styling message and sha
76
+ inputs += %w(
77
+ red
78
+ myfont.ttf
79
+ SE
80
+ 38
81
+ orange
82
+ true
83
+ ) * 2
84
+
85
+ # styling overlay
86
+ inputs += %w(true #2884ae,#7e231f 40)
87
+
88
+ configured_plugin_options = {}
89
+ output = fake_io_capture(inputs: inputs) do
90
+ configured_plugin_options = plugin.configure_options!
91
+ end
92
+
93
+ configured_plugin_options.must_equal( {
94
+ "enabled" => true,
95
+ message: {
96
+ color: 'red',
97
+ font: 'myfont.ttf',
98
+ position: 'SE',
99
+ size: 38,
100
+ stroke_color: 'orange',
101
+ uppercase: true
102
+ },
103
+ sha: {
104
+ color: 'red',
105
+ font: 'myfont.ttf',
106
+ position: 'SE',
107
+ size: 38,
108
+ stroke_color: 'orange',
109
+ uppercase: true
110
+ },
111
+ overlay: {
112
+ enabled: true,
113
+ overlay_colors: ['#2884ae', '#7e231f'],
114
+ overlay_percent: 40
115
+ }
116
+ })
117
+ end
118
+
119
+ it 'should indicate when configured' do
120
+ plugin.runner.config = valid_enabled_config
121
+ plugin.configured?.must_equal true
122
+ end
123
+
124
+ describe '#valid_configuration?' do
125
+ it 'should be trye even if config is not set' do
126
+ plugin.valid_configuration?.must_equal(true)
127
+ end
128
+
129
+ it 'should be true for a valid configuration' do
130
+ plugin.runner.config = valid_enabled_config
131
+ plugin.valid_configuration?.must_equal true
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ # necessary libs from lolcommits (allowing plugin to run)
4
+ require 'git'
5
+ require 'lolcommits/runner'
6
+ require 'lolcommits/vcs_info'
7
+ require 'lolcommits/backends/git_info'
8
+
9
+ # lolcommit test helpers
10
+ require 'lolcommits/test_helpers/git_repo'
11
+ require 'lolcommits/test_helpers/fake_io'
12
+
13
+ if ENV['COVERAGE']
14
+ if ENV['TRAVIS']
15
+ require 'coveralls'
16
+ Coveralls.wear!
17
+ else
18
+ require 'simplecov'
19
+ end
20
+ end
21
+
22
+ # plugin gem test libs
23
+ require 'lolcommits/loltext'
24
+ require 'lolcommits/plugin/loltext'
25
+ require 'minitest/autorun'
26
+
27
+ # swallow all debug output during test runs
28
+ def debug(msg); end
Binary file
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lolcommits-loltext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Hutchinson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lolcommits
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.3
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |2
98
+ Overlay the commit message and sha on your lolcommit. Configure text style,
99
+ positioning and an optional transparent overlay.
100
+ email:
101
+ - matt@hiddenloop.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".simplecov"
108
+ - ".travis.yml"
109
+ - CODE_OF_CONDUCT.md
110
+ - CONTRIBUTING.md
111
+ - Gemfile
112
+ - LICENSE
113
+ - README.md
114
+ - Rakefile
115
+ - bin/console
116
+ - bin/setup
117
+ - lib/lolcommits/loltext.rb
118
+ - lib/lolcommits/loltext/version.rb
119
+ - lib/lolcommits/plugin/loltext.rb
120
+ - lolcommits-loltext.gemspec
121
+ - test/lolcommits/plugin/loltext_test.rb
122
+ - test/test_helper.rb
123
+ - vendor/fonts/Impact.ttf
124
+ homepage: https://lolcommits.github.io
125
+ licenses:
126
+ - LGPL-3
127
+ metadata:
128
+ allowed_push_host: https://rubygems.org
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: 2.0.0
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.6.11
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: lolcommits text annotation plugin
149
+ test_files:
150
+ - test/lolcommits/plugin/loltext_test.rb
151
+ - test/test_helper.rb