summaryrefslogtreecommitdiff
path: root/lib/gitlab/badge/metadata.rb
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/gitlab/badge/metadata.rb
parent7b840c8483e2fe17a6c04474323cfb57c3c8a7d3 (diff)
downloadgitlab-ce-cc244160c5e2ecda2818348cb6b909f1dcb96e44.tar.gz
Extract the abstract base class of badge metadata
Diffstat (limited to 'lib/gitlab/badge/metadata.rb')
-rw-r--r--lib/gitlab/badge/metadata.rb36
1 files changed, 36 insertions, 0 deletions
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