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

Add WikiPage.unhyphenize

parent 4c57fa42
......@@ -7,7 +7,7 @@ module WikiHelper
# capitalized name of the page itself.
def breadcrumb(page_slug)
page_slug.split('/').
map { |dir_or_page| dir_or_page.gsub(/-+/, ' ').capitalize }.
map { |dir_or_page| WikiPage.unhyphenize(dir_or_page).capitalize }.
join(' / ')
end
end
......@@ -34,6 +34,10 @@ class WikiPage
flatten
end
def self.unhyphenize(name)
name.gsub(/-+/, ' ')
end
def to_key
[:slug]
end
......@@ -78,7 +82,7 @@ class WikiPage
# The formatted title of this page.
def title
if @attributes[:title]
@attributes[:title].gsub(/-+/, ' ')
self.class.unhyphenize(@attributes[:title])
else
""
end
......
......@@ -68,6 +68,14 @@ describe WikiPage, models: true do
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
context "when initialized with an existing gollum page" 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