diff options
author | Connor Shea <connor.james.shea@gmail.com> | 2016-11-23 02:35:16 +0300 |
---|---|---|
committer | Connor Shea <connor.james.shea@gmail.com> | 2016-11-23 02:35:16 +0300 |
commit | 8c590df5e77f9fc657137ad7b2f5b3c233f56d73 (patch) | |
tree | f877f7e8bbd355910ad81dd743e68b133af9d815 /lib | |
parent | 0917668eccd55fa3f90f6e9c993e72e678172eca (diff) | |
parent | 19ed85c1e18ebba8e1fb12bed4255ad29b78922b (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.rb | 34 | ||||
-rw-r--r-- | lib/helpers/edit_on_gitlab.rb | 27 | ||||
-rw-r--r-- | lib/helpers_.rb | 1 |
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' |