Artifact [24df81de33]

Artifact 24df81de33907567ef047a4a9a1fd9f7f2380330bf8e0932b17ec5019bc5a7c8:


<?
	proc iconfile {type name {checkUnknown true}} {
		if {![regexp {^[a-z]*$} $name]} {
			set name unknown
		}
		set file [file join [file dirname [info script]] $type "${name}.svg"]

		if {![file exists $file]} {
			if {$checkUnknown} {
				tailcall iconfile $type unknown false
			} else {
				error "No icon available for type=$type name=$name"
			}
		}

		return $file
	}

	proc icon {type name {x 5px} {y 2px} {width 16px} {height 16px}} {
		set file [iconfile $type $name]

		set fd [open $file]
		set data [read $fd]
		close $fd

		return [string map [list @@XPOS@@ $x @@YPOS@@ $y @@WIDTH@@ $width @@HEIGHT@@ $height] $data]
	}

	proc textColorFromBackground {color} {
		return "#fff"
	}

	set args(background_color) "#eee"
	set args(action) [list "build"]
	set args(status) [list "unknown"]
	set args(os)     [list "unknown"]
	set action_color_default "#555"
	set status_color_default "#4c1"
	set mapping([list status_color pass])    #00ff97
	set mapping([list status_color passed])  #00ff97
	set mapping([list status_color passing]) #00ff97
	set mapping([list status_color fail])    #f00
	set mapping([list status_color failed])  #f00
	set mapping([list status_color failing]) #f00
	set mapping([list status_color unknown]) #9932CC
	set errList [list]

	load_response args

	foreach arg {action status status_color action_color background_color os} {
		if {![info exists args($arg)]} {
			continue
		}

		set args($arg) [lindex [set args($arg)] end]
	}

	foreach arg {status_color action_color} {
		if {![info exists args($arg)]} {
			catch {
				set args($arg) $mapping([list $arg $args([lindex [split $arg _] 0])])
			} err
			lappend errList $err
			
		}

		if {![info exists args($arg)]} {
			set args($arg) [set ${arg}_default]
		}
	}

	set timestamp "Tue, 26 Oct 2017 00:00:00 GMT"
	set etag [binary encode base64 [list $timestamp $args(action) $args(status) $args(action_color) $args(status_color) $args(os)]]

	set actionTextColor [textColorFromBackground $args(action_color)]
	set statusTextColor [textColorFromBackground $args(status_color)]

	headers type image/svg+xml
	headers add Last-Modified $timestamp
	headers add ETag $etag

	set q [format %c 63]
	puts -nonewline "<${q}xml version=\"1.0\"${q}>"

	if {![info exists args(no_action_icon)]} {
		catch {
			set actionIcon [icon action $args(action) 24]
		}
	}
	if {[info exists actionIcon]} {
		set actionAreaWidth 18
	} else {
		set actionAreaWidth 45
	}

	if {![info exists args(no_status_icon)]} {
		catch {
			set statusIcon [icon status $args(status) [expr {20 + $actionAreaWidth}]]
		}
	}
	if {[info exists statusIcon]} {
		set statusAreaWidth 18
	} else {
		set statusAreaWidth 55
	}

	set osAreaWidth 20

	set totalWidth [expr {$osAreaWidth + $actionAreaWidth + $statusAreaWidth}]
?>
<svg xmlns="http://www.w3.org/2000/svg" width="<? puts -nonewline $totalWidth ?>" height="20">
<linearGradient id="a" x2="0" y2="100%">
    <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
    <stop offset="1" stop-opacity=".1"/>
</linearGradient>
<rect rx="3" width="<? puts -nonewline $totalWidth ?>" height="20" fill="<? puts -nonewline $args(background_color) ?>"/>
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<? if {[info exists actionIcon]} {
       puts -nonewline $actionIcon
   } else {
?>
    <rect rx="3" width="<? puts -nonewline $totalWidth ?>" height="20" fill="<? puts -nonewline $args(action_color) ?>"/>
    <text x="44" y="15" fill="#010101" fill-opacity=".3"><? puts -nonewline $args(action) ?></text>
    <text x="44" y="14" fill="<? puts -nonewline $actionTextColor ?>"><? puts -nonewline $args(action) ?></text>
<? } ?>
<? if {[info exists statusIcon]} {
      puts -nonewline $statusIcon
   } else {
      set statusTextLocation [expr {$osAreaWidth + $actionAreaWidth + ($statusAreaWidth / 2)}]
?>
    <rect rx="3" x="<? puts -nonewline [expr {$totalWidth - $statusAreaWidth}] ?>" width="<? puts -nonewline $statusAreaWidth ?>" height="20" fill="<? puts -nonewline $args(status_color) ?>"/>
    <text x="<? puts -nonewline $statusTextLocation ?>" y="15" fill="#010101" fill-opacity=".3"><? puts -nonewline $args(status) ?></text>
    <text x="<? puts -nonewline $statusTextLocation ?>" y="14" fill="<? puts -nonewline $statusTextColor ?>"><? puts -nonewline $args(status) ?></text>
<? } ?>
<rect rx="3" width="<? puts -nonewline $totalWidth ?>" height="20" fill="url(#a)"/>
<? catch {puts -nonewline [icon os $args(os)]} ?>
</g>
<!-- <? #puts $errList ?> -->
</svg>