Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #9 from nature/tidy_up
Browse files Browse the repository at this point in the history
Extract out some duplication into a helper function.
  • Loading branch information
clowder committed May 29, 2012
2 parents 369d78e + 0bfd5d6 commit 0bc80e5
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/gollum/frontend/app.rb
Expand Up @@ -70,6 +70,11 @@ def extract_path(file_path)
def extract_name(file_path)
file_path.split("/").last
end

# Extrace the 'format' from the file name
def extract_format(filename)
$1 if filename =~ /^.+\.(\w+)$/
end
end

get '/login' do
Expand Down Expand Up @@ -118,14 +123,10 @@ def extract_name(file_path)
authentication_required!
@path = extract_path(params[:splat].first)
@name = extract_name(params[:splat].first)
@format = extract_format(@name)
wiki_options = settings.wiki_options.merge({ :page_file_dir => @path })
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)

@format = nil
if @name =~ /^.+\.(\w+)$/
@format = $1
end

if page = wiki.page(@name)
if page.format.to_s.include?('markdown')
redirect '/livepreview/index.html?page=' + encodeURIComponent(@name)
Expand Down Expand Up @@ -320,11 +321,8 @@ def show_page_or_file(name)
content_type file.mime_type
file.raw_data
else
@name = name
@format = nil
if name =~ /^.+\.(\w+)$/
@format = $1
end
@name = name
@format = extract_format(@name)
mustache :create
end
end
Expand Down

0 comments on commit 0bc80e5

Please sign in to comment.