summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-08-11 14:08:27 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-08-15 14:39:46 +0200
commitcc244160c5e2ecda2818348cb6b909f1dcb96e44 (patch)
treee4ac983c20b6caaddd8c6afd069a93a644c04104 /lib
parent7b840c8483e2fe17a6c04474323cfb57c3c8a7d3 (diff)
downloadgitlab-ce-cc244160c5e2ecda2818348cb6b909f1dcb96e44.tar.gz
Extract the abstract base class of badge metadata
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/badge/build/metadata.rb14
-rw-r--r--lib/gitlab/badge/coverage/metadata.rb14
-rw-r--r--lib/gitlab/badge/metadata.rb36
3 files changed, 42 insertions, 22 deletions
diff --git a/lib/gitlab/badge/build/metadata.rb b/lib/gitlab/badge/build/metadata.rb
index 52a10b19298..f87a7b7942e 100644
--- a/lib/gitlab/badge/build/metadata.rb
+++ b/lib/gitlab/badge/build/metadata.rb
@@ -4,22 +4,14 @@ module Gitlab
##
# Class that describes build badge metadata
#
- class Metadata
- include Gitlab::Application.routes.url_helpers
- include ActionView::Helpers::AssetTagHelper
- include ActionView::Helpers::UrlHelper
-
+ class Metadata < Badge::Metadata
def initialize(badge)
@project = badge.project
@ref = badge.ref
end
- def to_html
- link_to(image_tag(image_url, alt: 'build status'), link_url)
- end
-
- def to_markdown
- "[![build status](#{image_url})](#{link_url})"
+ def title
+ 'build status'
end
def image_url
diff --git a/lib/gitlab/badge/coverage/metadata.rb b/lib/gitlab/badge/coverage/metadata.rb
index ae9e5e84051..53588185622 100644
--- a/lib/gitlab/badge/coverage/metadata.rb
+++ b/lib/gitlab/badge/coverage/metadata.rb
@@ -4,23 +4,15 @@ module Gitlab
##
# Class that describes coverage badge metadata
#
- class Metadata
- include Gitlab::Application.routes.url_helpers
- include ActionView::Helpers::AssetTagHelper
- include ActionView::Helpers::UrlHelper
-
+ class Metadata < Badge::Metadata
def initialize(badge)
@project = badge.project
@ref = badge.ref
@job = badge.job
end
- def to_html
- link_to(image_tag(image_url, alt: 'coverage report'), link_url)
- end
-
- def to_markdown
- "[![coverage report](#{image_url})](#{link_url})"
+ def title
+ 'coverage report'
end
def image_url
diff --git a/lib/gitlab/badge/metadata.rb b/lib/gitlab/badge/metadata.rb
new file mode 100644
index 00000000000..548f85b78bb
--- /dev/null
+++ b/lib/gitlab/badge/metadata.rb
@@ -0,0 +1,36 @@
+module Gitlab
+ module Badge
+ ##
+ # Abstract class for badge metadata
+ #
+ class Metadata
+ include Gitlab::Application.routes.url_helpers
+ include ActionView::Helpers::AssetTagHelper
+ include ActionView::Helpers::UrlHelper
+
+ def initialize(badge)
+ @badge = badge
+ end
+
+ def to_html
+ link_to(image_tag(image_url, alt: title), link_url)
+ end
+
+ def to_markdown
+ "[![#{title}](#{image_url})](#{link_url})"
+ end
+
+ def title
+ raise NotImplementedError
+ end
+
+ def image_url
+ raise NotImplementedError
+ end
+
+ def link_url
+ raise NotImplementedError
+ end
+ end
+ end
+end