Skip to content

Commit

Permalink
Allow --png as a option
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Feb 4, 2014
1 parent 322683e commit 35bc3f4
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 6 deletions.
3 changes: 2 additions & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
badge_service: img.shields.io
license_colour: blue
bonus_badge_colour: ff6799
bonus_badge_link: https://github.com/pikesley/badger
bonus_badge_link: https://github.com/pikesley/badger
badge_type: svg
18 changes: 18 additions & 0 deletions features/png.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Feature: Badge robot

Background:
Given git remote is "https://github.com/doge/wow"

@travis @gemnasium @coveralls @gemspec @mit
Scenario: One with everything
When I successfully run `badger badge /tmp/wow_repo --png `
Then the output should contain:
"""
[![Build Status](http://img.shields.io/travis/doge/wow.png)](https://travis-ci.org/doge/wow)
[![Dependency Status](http://img.shields.io/gemnasium/doge/wow.png)](https://gemnasium.com/doge/wow)
[![Coverage Status](http://img.shields.io/coveralls/doge/wow.png)](https://coveralls.io/r/doge/wow)
[![Code Climate](http://img.shields.io/codeclimate/github/doge/wow.png)](https://codeclimate.com/github/doge/wow)
[![Gem Version](http://img.shields.io/gem/v/suchgem.png)](https://rubygems.org/gems/suchgem)
[![License](http://img.shields.io/:license-mit-blue.png)](http://doge.mit-license.org)
[![Badges](http://img.shields.io/:badges-7/7-ff6799.png)](https://github.com/pikesley/badger)
"""
3 changes: 2 additions & 1 deletion lib/badger/badge.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Badger
def Badger.badge text, badge_url, target_url
"[![%s](%s)](%s)" % [
"[![%s](%s.%s)](%s)" % [
text,
badge_url,
Config.instance.config['badge_type'],
target_url
]
end
Expand Down
4 changes: 4 additions & 0 deletions lib/badger/badger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def bonus
self << Bonus.badge(self)
end

def badge_type type
Config.instance.config['badge_type'] = type
end

def to_s
self.uniq!

Expand Down
2 changes: 1 addition & 1 deletion lib/badger/bonus.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Badger
class Bonus
def self.badge badger
badge_url = 'http://%s/:badges-%d/%d-%s.svg' % [
badge_url = 'http://%s/:badges-%d/%d-%s' % [
Config.instance.config['badge_service'],
badger.length + 1,
badger.length + 1,
Expand Down
3 changes: 3 additions & 0 deletions lib/badger/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ class CLI < Thor

desc 'badge', 'Generate badge markdown'
long_desc File.read File.join File.dirname( __FILE__), '..', '..', 'DESC.md'
method_option :png, :type => :boolean, :default => false, :desc => 'Generate PNG badges instead of the default SVG'

def badge dir = '.'
@badger = Badger.new Badger.git_remote dir

@badger.badge_type 'png' if options[:png]

@badger.add 'travis' if Badger.has_travis? dir
@badger.add 'gemnasium' if Badger.has_gemfile? dir
@badger.add 'coveralls' if Badger.has_coveralls? dir
Expand Down
4 changes: 4 additions & 0 deletions lib/badger/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def config
@config
end

# def badge_type= type
# @config['badge_type'] = type
# end

private

def fetch_yaml file
Expand Down
2 changes: 1 addition & 1 deletion lib/badger/license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.badge type, owner
end

badge_text = type unless badge_text = params['badge_text']
badge_url = 'http://%s/:license-%s-%s.svg' % [
badge_url = 'http://%s/:license-%s-%s' % [
Config.instance.config['badge_service'],
badge_text,
Config.instance.config['license_colour']
Expand Down
2 changes: 1 addition & 1 deletion lib/badger/rubygem.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Badger
class Rubygem
def self.badge name
badge_url = 'http://%s/gem/v/%s.svg' % [
badge_url = 'http://%s/gem/v/%s' % [
Config.instance.config['badge_service'],
name
]
Expand Down
2 changes: 1 addition & 1 deletion lib/badger/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def self.badge name, github_slug
return nil unless params = Config.instance.services[name]
params = Config.instance.services[name]

badge_url = 'http://%s/%s/%s.svg' % [
badge_url = 'http://%s/%s/%s' % [
Config.instance.config['badge_service'],
params['badge_slug'],
github_slug
Expand Down
6 changes: 6 additions & 0 deletions spec/badger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,11 @@ module Badger
@badger.add 'travis'
@badger[0].should == '[![Build Status](http://img.shields.io/travis/pikesley/diabetes-dashboard.svg)](https://travis-ci.org/pikesley/diabetes-dashboard)'
end

it 'should let me choose a different badge type' do
@badger.badge_type 'png'
@badger.add 'travis'
@badger[0].should == '[![Build Status](http://img.shields.io/travis/doge/wow.png)](https://travis-ci.org/doge/wow)'
end
end
end

0 comments on commit 35bc3f4

Please sign in to comment.