Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorConnor Shea <connor.james.shea@gmail.com>2016-11-23 02:35:16 +0300
committerConnor Shea <connor.james.shea@gmail.com>2016-11-23 02:35:16 +0300
commit8c590df5e77f9fc657137ad7b2f5b3c233f56d73 (patch)
treef877f7e8bbd355910ad81dd743e68b133af9d815 /lib
parent0917668eccd55fa3f90f6e9c993e72e678172eca (diff)
parent19ed85c1e18ebba8e1fb12bed4255ad29b78922b (diff)
Merge branch 'edit-on-gitlab-helper' into 'master'
Make Edit on GitLab a helper. Fixes #30. See merge request !30
Diffstat (limited to 'lib')
-rw-r--r--lib/filters/edit_on_gitlab_link.rb34
-rw-r--r--lib/helpers/edit_on_gitlab.rb27
-rw-r--r--lib/helpers_.rb1
3 files changed, 28 insertions, 34 deletions
diff --git a/lib/filters/edit_on_gitlab_link.rb b/lib/filters/edit_on_gitlab_link.rb
deleted file mode 100644
index c304cd7f..00000000
--- a/lib/filters/edit_on_gitlab_link.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-module Nanoc::Filters
- class EditOnGitLabLink < Nanoc::Filter
- identifier :edit_on_gitlab_link
-
- def run(content, params = {})
- # Returns the source content's path.
- content_filename = @item[:content_filename]
- # Make an array out of the path
- content_filename_array = content_filename.split('/')
- # Remove "/content/"
- content_filename_array.shift
- # Get the product name.
- product = content_filename_array.shift
- # This should be the path from the doc/ directory for a given file.
- content_filename = content_filename_array.join("/")
-
- # Replace `EDIT_ON_GITLAB_LINK` with the actual URL pointing to
- # the source file.
- content.gsub(/href="(EDIT_ON_GITLAB_LINK)"/) do |result|
- if product == "omnibus"
- # omnibus-gitlab repo
- result.gsub!(/EDIT_ON_GITLAB_LINK/, "https://gitlab.com/gitlab-org/#{product}-gitlab/blob/master/doc/#{content_filename}")
- elsif product == "runner"
- # omnibus-gitlab repo
- result.gsub!(/EDIT_ON_GITLAB_LINK/, "https://gitlab.com/gitlab-org/gitlab-ci-multi-#{product}/blob/master/docs/#{content_filename}")
- else
- # gitlab-ce and gitlab-ee repos
- result.gsub!(/EDIT_ON_GITLAB_LINK/, "https://gitlab.com/gitlab-org/gitlab-#{product}/blob/master/doc/#{content_filename}")
- end
- result
- end
- end
- end
-end
diff --git a/lib/helpers/edit_on_gitlab.rb b/lib/helpers/edit_on_gitlab.rb
new file mode 100644
index 00000000..df623290
--- /dev/null
+++ b/lib/helpers/edit_on_gitlab.rb
@@ -0,0 +1,27 @@
+module Nanoc::Helpers
+ module EditOnGitLab
+ def edit_on_gitlab(item)
+ # Make an array out of the content's source path.
+ content_filename_array = @item[:content_filename].split('/')
+ # Remove "/content/"
+ content_filename_array.shift
+ # Get the product name.
+ product = content_filename_array.shift
+ # This should be the path from the doc/ directory for a given file.
+ content_filename = content_filename_array.join("/")
+
+ if product == "omnibus"
+ # omnibus-gitlab repo
+ gitlab_url = "https://gitlab.com/gitlab-org/#{product}-gitlab/blob/master/doc/#{content_filename}"
+ elsif product == "runner"
+ # gitlab-runner repo
+ gitlab_url = "https://gitlab.com/gitlab-org/gitlab-ci-multi-#{product}/blob/master/docs/#{content_filename}"
+ else
+ # gitlab-ce and gitlab-ee repos
+ gitlab_url = "https://gitlab.com/gitlab-org/gitlab-#{product}/blob/master/doc/#{content_filename}"
+ end
+
+ result = "<a href='#{gitlab_url}'>Improve this documentation on GitLab.com</a>"
+ end
+ end
+end
diff --git a/lib/helpers_.rb b/lib/helpers_.rb
index 7fa9d11f..b9a560f0 100644
--- a/lib/helpers_.rb
+++ b/lib/helpers_.rb
@@ -2,6 +2,7 @@ include Nanoc::Helpers::LinkTo
include Nanoc::Helpers::XMLSitemap
include Nanoc::Helpers::Rendering
include Nanoc::Helpers::ChildParentBetter
+include Nanoc::Helpers::EditOnGitLab
require 'redcarpet'
require 'rouge'