-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gemify #77
Gemify #77
Changes from all commits
5742eee
ed27488
01948e9
0e0d286
1c10b61
76ca737
563f9cd
5668f06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: ruby | ||
rvm: | ||
- 2.0.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in shields_io.gemspec | ||
gemspec |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "bundler/gem_tasks" | ||
require 'rake/testtask' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need both these requires, it'll double up on the bundler tasks (sadly). rake/testtask also loads bundler/gem_tasks. |
||
|
||
Rake::TestTask.new do |t| | ||
t.libs << "lib" | ||
t.test_files = FileList['lib/test/**/*_spec.rb'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't test files usually stored in |
||
end | ||
|
||
task :default => [:test] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env ruby | ||
require "slop" | ||
require_relative "../lib/shields_io" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to use require relative for a binary of a gem, just do |
||
|
||
opts = Slop.parse help: true do | ||
banner 'Usage: ./generate_shield [options] | ||
example: | ||
./generate_shield --font_size=18 --height=18 --vendor_text=Travis --vendor_width=40 --vendor_color=gray --status_text=Passing --status_color=green --format=png >travis.png | ||
' | ||
|
||
on '-v', 'Print the version' do | ||
puts "Version #{ShieldsIo::VERSION}" | ||
end | ||
|
||
on :height=, "Shield height", as: Integer | ||
on :font_size=, "Font size", as: Integer | ||
on :vendor_text=, "Vendor text" | ||
on :vendor_width=, "Vendor width", as: Integer | ||
on :vendor_color=, "Vendor Color #{ShieldsIo::SVG::Colors.join(",")}" | ||
on :status_text=, "Status Text" | ||
on :status_width=, "Status Width", as: Integer | ||
on :status_color=, "Status Color #{ShieldsIo::SVG::Colors.join(",")}" | ||
on :format=, "Format svg, png etc.." | ||
end | ||
|
||
opts = ShieldsIo::SVG::Defaults.merge(opts.to_h.delete_if { |k, v| v.nil? }) | ||
|
||
if opts[:format]=="svg" | ||
$stdout.print ShieldsIo::SVG.new(opts).render | ||
exit(0) | ||
else | ||
$stdout.print ShieldsIo::SVG.new(opts).render_bitmap opts[:format] unless opts[:format].nil? | ||
exit(0) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require_relative "shields_io/version" | ||
require "erubis" | ||
require "mini_magick" | ||
|
||
module ShieldsIo | ||
class SVG | ||
Colors = %w{gray lightgray darkgray green yellowgreen yellow red} | ||
Defaults = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. General accepted ruby standards suggest having all caps for constants, like |
||
font_size: 10, | ||
height: 18, | ||
vendor_text: "vendor", | ||
vendor_width: 50, | ||
vendor_color: "gray", | ||
status_text: "status", | ||
status_width: 70, | ||
status_color: "lightgray" | ||
} | ||
|
||
def initialize(opts={}) | ||
@shield=opts | ||
@template = File.read("#{File.dirname(__FILE__)}/template.svg.erb") | ||
raise "unknown vendor color" unless ShieldsIo::SVG::Colors.include? @shield[:vendor_color] | ||
raise "unknown status color" unless ShieldsIo::SVG::Colors.include? @shield[:status_color] | ||
raise "height not an integer" unless @shield[:height].is_a? Integer | ||
raise "vendor width not an integer" unless @shield[:vendor_width].is_a? Integer | ||
raise "status width not an integer" unless @shield[:status_width].is_a? Integer | ||
raise "font_size not an integer" unless @shield[:font_size].is_a? Integer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd switch this to a case statement for readabilities sake. I would also suggest raising an actual error, like |
||
end | ||
|
||
def render | ||
Erubis::Eruby.new(@template).result(@shield) | ||
end | ||
|
||
def render_bitmap(format="png") | ||
buffer = StringIO.new(self.render) | ||
img = MiniMagick::Image.read(buffer,".svg") | ||
img.format format | ||
img.to_blob | ||
end | ||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module ShieldsIo | ||
VERSION = "0.0.1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gem seems complete enough, it should be 1.0.0. |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<svg version="1.1" | ||
xmlns="http://www.w3.org/2000/svg" | ||
xmlns:xlink="http://www.w3.org/1999/xlink" | ||
width="<%=vendor_width + status_width + 4%>px" | ||
height="<%= height %>px"> | ||
<defs> | ||
<linearGradient id="gray" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="0" y2="<%= height %>"> | ||
<stop offset="0" style="stop-color:#AAAAAA" /> | ||
<stop offset="0.1" style="stop-color:#5A5A5A" /> | ||
<stop offset="0.96" style="stop-color:#3F3F3F" /> | ||
<stop offset="1" style="stop-color:#2E2E2E" /> | ||
</linearGradient> | ||
<linearGradient id="lightgray" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="0" y2="<%= height %>"> | ||
<stop offset="0" style="stop-color:#D6D6D6" /> | ||
<stop offset="0.1" style="stop-color:#9F9F9F" /> | ||
<stop offset="0.96" style="stop-color:#707070" /> | ||
<stop offset="1" style="stop-color:#515151" /> | ||
</linearGradient> | ||
<linearGradient id="darkgray" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="0" y2="<%= height %>"> | ||
<stop offset="0.0" style="stop-color:#909090" /> | ||
<stop offset="0.1" style="stop-color:#313131" /> | ||
<stop offset="0.96" style="stop-color:#232323" /> | ||
<stop offset="1" style="stop-color:#191919" /> | ||
</linearGradient> | ||
<linearGradient id="green" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="0" y2="<%= height %>"> | ||
<stop offset="0" style="stop-color:#9DED7D"/> | ||
<stop offset="0.1" style="stop-color:#4AD115"/> | ||
<stop offset="0.96" style="stop-color:#31B70E"/> | ||
<stop offset="1" style="stop-color:#23630A"/> | ||
</linearGradient> | ||
<linearGradient id="yellowgreen" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="0" y2="<%= height %>"> | ||
<stop offset="0" style="stop-color:#D1F171"/> | ||
<stop offset="0.1" style="stop-color:#97CA00"/> | ||
<stop offset="0.96" style="stop-color:#6B8F00"/> | ||
<stop offset="1" style="stop-color:#4D6700"/> | ||
</linearGradient> | ||
<linearGradient id="yellow" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="0" y2="<%= height %>"> | ||
<stop offset="0" style="stop-color:#FFE37F"/> | ||
<stop offset="0.1" style="stop-color:#E0B417"/> | ||
<stop offset="0.96" style="stop-color:#9E7F10"/> | ||
<stop offset="1" style="stop-color:#725C0C"/> | ||
</linearGradient> | ||
<linearGradient id="red" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="0" y2="<%= height %>"> | ||
<stop offset="0" style="stop-color:#FFAC9C"/> | ||
<stop offset="0.1" style="stop-color:#E05D44"/> | ||
<stop offset="0.96" style="stop-color:#9E4230"/> | ||
<stop offset="1" style="stop-color:#722F22"/> | ||
</linearGradient> | ||
<filter id="dropshadow" height="100%"> | ||
<feGaussianBlur in="SourceAlpha" stdDeviation="0"/> | ||
<feOffset dx="0" dy="1" result="offsetblur"/> | ||
<feComponentTransfer xmlns="http://www.w3.org/2000/svg"> | ||
<feFuncA type="linear" slope="0.3"/> | ||
</feComponentTransfer> | ||
<feMerge> | ||
<feMergeNode/> | ||
<feMergeNode in="SourceGraphic"/> | ||
</feMerge> | ||
</filter> | ||
</defs> | ||
|
||
<g id="vendor"> | ||
<path d="M0,9 v-6 q0,-3,3,-3 v18 q-3,0,-3,-3 Z" fill="url(#<%= vendor_color %>)" /> | ||
<rect x="3" y="0" width="<%= vendor_width %>" height="<%= height%>" fill="url(#<%= vendor_color %>)" /> | ||
<text x="6" y="12" font-family="Open Sans" font-size="<%= font_size %>" fill="#FFFFFF" style="filter:url(#dropshadow)"><%= vendor_text %></text> | ||
</g> | ||
|
||
<g id="status"> | ||
<rect x="<%= vendor_width%>" y="0" width="<%= status_width %>" height="<%= height %>" fill="url(#<%= status_color %>)" /> | ||
<path fill="url(#<%= status_color %>)" d="M<%=vendor_width + status_width + 3%>,9 v-6 q0,-3,-3,-3 v<%=height%> q3,0,3,-3 Z" /> | ||
<text x="<%= vendor_width + 4%>" y="12" font-family="Open Sans" font-size="<%= font_size %>" fill="#FFFFFF" style="filter:url(#dropshadow)"><%= status_text%></text> | ||
</g> | ||
</svg> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "minitest/autorun" | ||
require 'rake/testtask' | ||
require "rexml/document" | ||
require "mini_magick" | ||
require_relative "../shields_io" | ||
|
||
describe ShieldsIo::SVG do | ||
before do | ||
@shield = ShieldsIo::SVG.new(ShieldsIo::SVG::Defaults) | ||
end | ||
|
||
describe "render" do | ||
it "must render svg" do | ||
doc = REXML::Document.new @shield.render | ||
doc.root.name.must_equal "svg" | ||
end | ||
|
||
it "must take into account default options" do | ||
doc = REXML::Document.new @shield.render | ||
doc.elements.to_a("//text").first.text.must_equal "vendor" | ||
end | ||
|
||
it "must take into account custom options" do | ||
doc = REXML::Document.new ShieldsIo::SVG.new(ShieldsIo::SVG::Defaults.merge(vendor_text: "plop")).render | ||
doc.elements.to_a("//text").first.text.must_equal "plop" | ||
end | ||
end | ||
|
||
describe "render bitmap" do | ||
it "renders a png" do | ||
buffer = StringIO.new(@shield.render_bitmap) | ||
img = MiniMagick::Image.read(buffer,".png") | ||
img.mime_type.must_equal "image/png" | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'shields_io/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "shields_io" | ||
spec.version = ShieldsIo::VERSION | ||
spec.authors = ["Ori Pekelman"] | ||
spec.email = ["ori@pekelman.com"] | ||
spec.description = %q{Small gem to generate shields (travis, code climate, etc..)} | ||
spec.summary = %q{Small gem to generate shields (travis, code climate, etc..} | ||
spec.homepage = "http://shields.io/" | ||
spec.license = "Public Domain" | ||
|
||
spec.files = `git ls-files`.split($/) | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_development_dependency "bundler", "~> 1.3" | ||
spec.add_development_dependency "rake" | ||
spec.add_development_dependency "minitest" | ||
spec.add_dependency "erubis", "~> 2.7.0" | ||
spec.add_dependency "mini_magick", "~> 3.6.0" | ||
spec.add_dependency "slop", "~> 3.4.0" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more concise version of this would be:
Based off the Rails template gitignore.