From daa0925016a63dcde448643cbf1310aca359cf37 Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Wed, 13 May 2015 01:40:11 +0200 Subject: Rename MarkdownHelper to MarkupHelper --- app/helpers/application_helper.rb | 6 ++-- app/helpers/blob_helper.rb | 2 +- app/models/tree.rb | 6 ++-- lib/gitlab/markdown_helper.rb | 38 ------------------------ lib/gitlab/markup_helper.rb | 38 ++++++++++++++++++++++++ spec/lib/gitlab/gitlab_markdown_helper_spec.rb | 40 -------------------------- spec/lib/gitlab/markup_helper_spec.rb | 40 ++++++++++++++++++++++++++ 7 files changed, 85 insertions(+), 85 deletions(-) delete mode 100644 lib/gitlab/markdown_helper.rb create mode 100644 lib/gitlab/markup_helper.rb delete mode 100644 spec/lib/gitlab/gitlab_markdown_helper_spec.rb create mode 100644 spec/lib/gitlab/markup_helper_spec.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bc07c09cd4a..5bcc0026016 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -233,15 +233,15 @@ module ApplicationHelper end def markup?(filename) - Gitlab::MarkdownHelper.markup?(filename) + Gitlab::MarkupHelper.markup?(filename) end def gitlab_markdown?(filename) - Gitlab::MarkdownHelper.gitlab_markdown?(filename) + Gitlab::MarkupHelper.gitlab_markdown?(filename) end def asciidoc?(filename) - Gitlab::MarkdownHelper.asciidoc?(filename) + Gitlab::MarkupHelper.asciidoc?(filename) end # Overrides ActionView::Helpers::UrlHelper#link_to to add `rel="nofollow"` to diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 4ea838ca447..885ac5f85b8 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -55,7 +55,7 @@ module BlobHelper end def editing_preview_title(filename) - if Gitlab::MarkdownHelper.previewable?(filename) + if Gitlab::MarkupHelper.previewable?(filename) 'Preview' else 'Preview changes' diff --git a/app/models/tree.rb b/app/models/tree.rb index f279e896cda..93b3246a668 100644 --- a/app/models/tree.rb +++ b/app/models/tree.rb @@ -1,11 +1,11 @@ class Tree - include Gitlab::MarkdownHelper + include Gitlab::MarkupHelper attr_accessor :repository, :sha, :path, :entries def initialize(repository, sha, path = '/') path = '/' if path.blank? - + @repository = repository @sha = sha @path = path @@ -20,7 +20,7 @@ class Tree available_readmes = blobs.select(&:readme?) if available_readmes.count == 0 - return @readme = nil + return @readme = nil end # Take the first previewable readme, or the first available readme, if we diff --git a/lib/gitlab/markdown_helper.rb b/lib/gitlab/markdown_helper.rb deleted file mode 100644 index 70384b1db2c..00000000000 --- a/lib/gitlab/markdown_helper.rb +++ /dev/null @@ -1,38 +0,0 @@ -module Gitlab - module MarkdownHelper - module_function - - # Public: Determines if a given filename is compatible with GitHub::Markup. - # - # filename - Filename string to check - # - # Returns boolean - def markup?(filename) - filename.downcase.end_with?(*%w(.textile .rdoc .org .creole .wiki - .mediawiki .rst .adoc .ad .asciidoc)) - end - - # Public: Determines if a given filename is compatible with - # GitLab-flavored Markdown. - # - # filename - Filename string to check - # - # Returns boolean - def gitlab_markdown?(filename) - filename.downcase.end_with?(*%w(.mdown .md .markdown)) - end - - # Public: Determines if the given filename has AsciiDoc extension. - # - # filename - Filename string to check - # - # Returns boolean - def asciidoc?(filename) - filename.downcase.end_with?(*%w(.adoc .ad .asciidoc)) - end - - def previewable?(filename) - gitlab_markdown?(filename) || markup?(filename) - end - end -end diff --git a/lib/gitlab/markup_helper.rb b/lib/gitlab/markup_helper.rb new file mode 100644 index 00000000000..fb037266d23 --- /dev/null +++ b/lib/gitlab/markup_helper.rb @@ -0,0 +1,38 @@ +module Gitlab + module MarkupHelper + module_function + + # Public: Determines if a given filename is compatible with GitHub::Markup. + # + # filename - Filename string to check + # + # Returns boolean + def markup?(filename) + filename.downcase.end_with?(*%w(.textile .rdoc .org .creole .wiki + .mediawiki .rst .adoc .ad .asciidoc)) + end + + # Public: Determines if a given filename is compatible with + # GitLab-flavored Markdown. + # + # filename - Filename string to check + # + # Returns boolean + def gitlab_markdown?(filename) + filename.downcase.end_with?(*%w(.mdown .md .markdown)) + end + + # Public: Determines if the given filename has AsciiDoc extension. + # + # filename - Filename string to check + # + # Returns boolean + def asciidoc?(filename) + filename.downcase.end_with?(*%w(.adoc .ad .asciidoc)) + end + + def previewable?(filename) + gitlab_markdown?(filename) || markup?(filename) + end + end +end diff --git a/spec/lib/gitlab/gitlab_markdown_helper_spec.rb b/spec/lib/gitlab/gitlab_markdown_helper_spec.rb deleted file mode 100644 index beaafd56352..00000000000 --- a/spec/lib/gitlab/gitlab_markdown_helper_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'spec_helper' - -describe Gitlab::MarkdownHelper do - describe '#markup?' do - %w(textile rdoc org creole wiki - mediawiki rst adoc ad asciidoc).each do |type| - it "returns true for #{type} files" do - expect(Gitlab::MarkdownHelper.markup?("README.#{type}")).to be_truthy - end - end - - it 'returns false when given a non-markup filename' do - expect(Gitlab::MarkdownHelper.markup?('README.rb')).not_to be_truthy - end - end - - describe '#gitlab_markdown?' do - %w(mdown md markdown).each do |type| - it "returns true for #{type} files" do - expect(Gitlab::MarkdownHelper.gitlab_markdown?("README.#{type}")).to be_truthy - end - end - - it 'returns false when given a non-markdown filename' do - expect(Gitlab::MarkdownHelper.gitlab_markdown?('README.rb')).not_to be_truthy - end - end - - describe '#asciidoc?' do - %w(adoc ad asciidoc ADOC).each do |type| - it "returns true for #{type} files" do - expect(Gitlab::MarkdownHelper.asciidoc?("README.#{type}")).to be_truthy - end - end - - it 'returns false when given a non-asciidoc filename' do - expect(Gitlab::MarkdownHelper.asciidoc?('README.rb')).not_to be_truthy - end - end -end diff --git a/spec/lib/gitlab/markup_helper_spec.rb b/spec/lib/gitlab/markup_helper_spec.rb new file mode 100644 index 00000000000..448beecf01f --- /dev/null +++ b/spec/lib/gitlab/markup_helper_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe Gitlab::MarkupHelper do + describe '#markup?' do + %w(textile rdoc org creole wiki + mediawiki rst adoc ad asciidoc).each do |type| + it "returns true for #{type} files" do + expect(Gitlab::MarkupHelper.markup?("README.#{type}")).to be_truthy + end + end + + it 'returns false when given a non-markup filename' do + expect(Gitlab::MarkupHelper.markup?('README.rb')).not_to be_truthy + end + end + + describe '#gitlab_markdown?' do + %w(mdown md markdown).each do |type| + it "returns true for #{type} files" do + expect(Gitlab::MarkupHelper.gitlab_markdown?("README.#{type}")).to be_truthy + end + end + + it 'returns false when given a non-markdown filename' do + expect(Gitlab::MarkupHelper.gitlab_markdown?('README.rb')).not_to be_truthy + end + end + + describe '#asciidoc?' do + %w(adoc ad asciidoc ADOC).each do |type| + it "returns true for #{type} files" do + expect(Gitlab::MarkupHelper.asciidoc?("README.#{type}")).to be_truthy + end + end + + it 'returns false when given a non-asciidoc filename' do + expect(Gitlab::MarkupHelper.asciidoc?('README.rb')).not_to be_truthy + end + end +end -- cgit v1.2.1