From dfdc3926903fcb3d6691ef1298160a15f623b60e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josef=20=C5=A0im=C3=A1nek?=
Date: Mon, 12 May 2014 02:14:52 +0200
Subject: [PATCH] Trim status image modal.
Closes https://github.com/travis-ci/travis-ci/issues/1900
---
assets/scripts/app/helpers.coffee | 1 +
.../app/helpers/status_image_formatter.coffee | 50 +++++++++++++++++++
.../scripts/app/templates/status_images.hbs | 29 ++---------
assets/scripts/app/views/status_images.coffee | 46 +++++++----------
assets/styles/app/popup.sass | 4 +-
5 files changed, 73 insertions(+), 57 deletions(-)
create mode 100644 assets/scripts/app/helpers/status_image_formatter.coffee
diff --git a/assets/scripts/app/helpers.coffee b/assets/scripts/app/helpers.coffee
index bcbd98c1..98608e18 100644
--- a/assets/scripts/app/helpers.coffee
+++ b/assets/scripts/app/helpers.coffee
@@ -1,3 +1,4 @@
require 'helpers/handlebars'
require 'helpers/helpers'
require 'helpers/urls'
+require 'helpers/status_image_formatter'
diff --git a/assets/scripts/app/helpers/status_image_formatter.coffee b/assets/scripts/app/helpers/status_image_formatter.coffee
new file mode 100644
index 00000000..b346a5c3
--- /dev/null
+++ b/assets/scripts/app/helpers/status_image_formatter.coffee
@@ -0,0 +1,50 @@
+@Travis.StatusImageFormatter =
+ slug: null
+ url: null
+ branch: null
+
+ format: (version, slug, branch) ->
+ @slug = slug
+ @branch = branch
+ @url = @urlRepo()
+
+ switch version
+ when 'Image URL' then @statusImageUrl()
+ when 'Markdown' then @markdownStatusImage()
+ when 'Textile' then @textileStatusImage()
+ when 'RDOC' then @rdocStatusImage()
+ when 'AsciiDoc' then @asciidocStatusImage()
+ when 'Rst' then @rstStatusImage()
+ when 'POD' then @podStatusImage()
+
+ urlRepo: (->
+ "https://#{location.host}/#{@slug}"
+ )
+
+ statusImageUrl: (->
+ Travis.Urls.statusImage(@slug, @branch)
+ )
+
+ markdownStatusImage: (->
+ "[})](#{@url})"
+ )
+
+ textileStatusImage: (->
+ "!#{@statusImageUrl()}!:#{@url}"
+ )
+
+ rdocStatusImage: (->
+ "{
}[#{@url}]"
+ )
+
+ asciidocStatusImage: (->
+ "image:#{@statusImageUrl()}[\"Build Status\", link=\"#{@url}\"]"
+ )
+
+ rstStatusImage: (->
+ ".. image:: #{@statusImageUrl()}\n :target: #{@url}"
+ )
+
+ podStatusImage: (->
+ "=for HTML
"
+ )
diff --git a/assets/scripts/app/templates/status_images.hbs b/assets/scripts/app/templates/status_images.hbs
index 1b314730..4cff16a6 100644
--- a/assets/scripts/app/templates/status_images.hbs
+++ b/assets/scripts/app/templates/status_images.hbs
@@ -7,31 +7,8 @@
{{/if}}
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
diff --git a/assets/scripts/app/views/status_images.coffee b/assets/scripts/app/views/status_images.coffee
index a9a9ea88..2b3b75a6 100644
--- a/assets/scripts/app/views/status_images.coffee
+++ b/assets/scripts/app/views/status_images.coffee
@@ -9,10 +9,21 @@ Travis.StatusImagesView = Em.View.extend
jobBinding: 'toolsView.job'
branchesBinding: 'repo.branches'
+ formats: [
+ 'Image URL',
+ 'Markdown',
+ 'Textile',
+ 'RDOC',
+ 'AsciiDoc',
+ 'Rst',
+ 'POD'
+ ]
+
didInsertElement: ->
@_super.apply(this, arguments)
@setStatusImageBranch()
+ @setStatusImageFormat()
@show()
show: ->
@@ -21,9 +32,9 @@ Travis.StatusImagesView = Em.View.extend
close: ->
@destroy()
- urlRepo: (->
- "https://#{location.host}/#{@get('repo.slug')}"
- ).property('repo.slug')
+ setStatusImageFormat: (->
+ @set('statusImageFormat', @formats[0])
+ )
setStatusImageBranch: (->
if @get('repo.branches.isLoaded')
@@ -32,30 +43,7 @@ Travis.StatusImagesView = Em.View.extend
@set('statusImageBranch', null)
).observes('repo.branches', 'repo.branches.isLoaded', 'build.commit.branch')
- statusImageUrl: (->
- Travis.Urls.statusImage(@get('repo.slug'), @get('statusImageBranch.commit.branch'))
- ).property('repo.slug', 'statusImageBranch')
+ statusString: (->
+ Travis.StatusImageFormatter.format(@get('statusImageFormat'), @get('repo.slug'), @get('statusImageBranch.commit.branch'))
+ ).property('statusImageFormat', 'repo.slug', 'statusImageBranch.commit.branch')
- markdownStatusImage: (->
- "[})](#{@get('urlRepo')})"
- ).property('statusImageUrl')
-
- textileStatusImage: (->
- "!#{@get('statusImageUrl')}!:#{@get('urlRepo')}"
- ).property('statusImageUrl')
-
- rdocStatusImage: (->
- "{
}[#{@get('urlRepo')}]"
- ).property('statusImageUrl')
-
- asciidocStatusImage: (->
- "image:#{@get('statusImageUrl')}[\"Build Status\", link=\"#{@get('urlRepo')}\"]"
- ).property('statusImageUrl')
-
- rstStatusImage: (->
- ".. image:: #{@get('statusImageUrl')} :target: #{@get('urlRepo')}"
- ).property('statusImageUrl')
-
- podStatusImage: (->
- "=for HTML
"
- ).property('statusImageUrl')
diff --git a/assets/styles/app/popup.sass b/assets/styles/app/popup.sass
index c7308790..14d944d3 100644
--- a/assets/styles/app/popup.sass
+++ b/assets/styles/app/popup.sass
@@ -49,11 +49,11 @@
p
margin: 10px 0
label
- width: 80px
+ width: 100px
display: inline-block
input
border: 1px solid $color-border-light
- width: 505px
+ width: 485px
padding: 4px
@include border-radius(3px)