Commit 68309766 authored by Alex Braha Stoll's avatar Alex Braha Stoll

Add WikiPage.unhyphenize

parent 4c57fa42
...@@ -7,7 +7,7 @@ module WikiHelper ...@@ -7,7 +7,7 @@ module WikiHelper
# capitalized name of the page itself. # capitalized name of the page itself.
def breadcrumb(page_slug) def breadcrumb(page_slug)
page_slug.split('/'). page_slug.split('/').
map { |dir_or_page| dir_or_page.gsub(/-+/, ' ').capitalize }. map { |dir_or_page| WikiPage.unhyphenize(dir_or_page).capitalize }.
join(' / ') join(' / ')
end end
end end
...@@ -34,6 +34,10 @@ class WikiPage ...@@ -34,6 +34,10 @@ class WikiPage
flatten flatten
end end
def self.unhyphenize(name)
name.gsub(/-+/, ' ')
end
def to_key def to_key
[:slug] [:slug]
end end
...@@ -78,7 +82,7 @@ class WikiPage ...@@ -78,7 +82,7 @@ class WikiPage
# The formatted title of this page. # The formatted title of this page.
def title def title
if @attributes[:title] if @attributes[:title]
@attributes[:title].gsub(/-+/, ' ') self.class.unhyphenize(@attributes[:title])
else else
"" ""
end end
......
...@@ -68,6 +68,14 @@ describe WikiPage, models: true do ...@@ -68,6 +68,14 @@ describe WikiPage, models: true do
end end
end end
describe '.unhyphenize' do
it 'removes hyphens from a name' do
name = 'a-name--with-hyphens'
expect(WikiPage.unhyphenize(name)).to eq('a name with hyphens')
end
end
describe "#initialize" do describe "#initialize" do
context "when initialized with an existing gollum page" do context "when initialized with an existing gollum page" do
before do before do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment