Skip to content

Commit 0574386

Browse files
committed
Wrote ugly code to be backwards compatible
1 parent 476a835 commit 0574386

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

app.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@
2626
headers 'Content-Type' => "image/svg+xml"
2727
username = params[:username].chomp('.svg')
2828

29-
base_color = '#'+params[:base]
30-
scheme = ['#EEEEEE', lighten_color(base_color, 0.3), lighten_color(base_color, 0.2), base_color, darken_color(base_color, 0.8)]
31-
29+
#Makes API backwards compatible
30+
if(params[:base] == "teal" || params[:base] == "halloween" || params[:base] == "default")
31+
scheme = COLOR_SCHEMES[params[:base].to_sym]
32+
else
33+
#this case will be executed a majority of the time
34+
base_color = '#'+params[:base]
35+
scheme = ['#EEEEEE', lighten_color(base_color, 0.3), lighten_color(base_color, 0.2), base_color, darken_color(base_color, 0.8)]
36+
end
37+
3238
svg = GithubChart.new(user: username, colors: scheme).svg
3339
stream do |out|
3440
out << svg

color.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#http://www.redguava.com.au/2011/10/lighten-or-darken-a-hexadecimal-color-in-ruby-on-rails/
22

3-
# COLOR_SCHEMES = {
4-
# default: ['#eeeeee', '#d6e685', '#8cc665', '#44a340', '#1e6823'],
5-
# halloween: ['#EEEEEE', '#FFEE4A', '#FFC501', '#FE9600', '#03001C'],
6-
# teal: ['#EEEEEE', "#7FFFD4", "#76EEC6", "#66CDAA", "#458B74"],
7-
# red: ['#EEEEEE', '#990100', '#8C0100', '#720100', '#4C0100']
8-
# }
3+
COLOR_SCHEMES = {
4+
default: ['#eeeeee', '#d6e685', '#8cc665', '#44a340', '#1e6823'],
5+
halloween: ['#EEEEEE', '#FFEE4A', '#FFC501', '#FE9600', '#03001C'],
6+
teal: ['#EEEEEE', "#7FFFD4", "#76EEC6", "#66CDAA", "#458B74"]
7+
}
98

109
# Amount should be a decimal between 0 and 1. Lower means darker
1110
def darken_color(hex_color, amount=0.4)

0 commit comments

Comments
 (0)