diff --git a/Gemfile b/Gemfile index 015bd1eb..6f59602a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +source 'https://rubygems.org' + if RUBY_PLATFORM == 'java' gem 'gollum-rjgit_adapter', :git => 'https://github.com/repotag/gollum-lib_rjgit_adapter' # For development purposes gem 'warbler' @@ -7,6 +9,5 @@ end gem 'gollum-lib', :git => 'https://github.com/gollum/gollum-lib.git', :branch => 'gollum-lib-5.x' # For development purposes -source 'https://rubygems.org' gemspec -gem 'rake', '~> 11.2' \ No newline at end of file +gem 'rake', '~> 11.2' diff --git a/gollum.gemspec b/gollum.gemspec index 0497e90d..7daf025c 100644 --- a/gollum.gemspec +++ b/gollum.gemspec @@ -27,6 +27,7 @@ Gem::Specification.new do |s| s.add_dependency 'gollum-lib', '~> 5.0.a' s.add_dependency 'kramdown', '~> 1.17.0' s.add_dependency 'sinatra', '~> 2.0' + s.add_dependency 'sinatra-contrib', '~> 2.0' s.add_dependency 'mustache', ['>= 0.99.5', '< 1.0.0'] s.add_dependency 'useragent', '~> 0.16.2' s.add_dependency 'gemojione', '~> 3.2' diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 22715841..42191d67 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -1,6 +1,7 @@ # ~*~ encoding: utf-8 ~*~ require 'cgi' require 'sinatra' +require 'sinatra/namespace' require 'gollum-lib' require 'mustache/sinatra' require 'stringex' @@ -47,11 +48,12 @@ end # } # # See the wiki.rb file for more details on wiki options + module Precious class App < Sinatra::Base register Mustache::Sinatra + register Sinatra::Namespace include Precious::Helpers - dir = File.dirname(File.expand_path(__FILE__)) set :sprockets, ::Precious::Assets.sprockets(dir) @@ -97,6 +99,7 @@ module Precious Sprockets::Helpers.configure do |config| config.environment = settings.sprockets + config.environment.context_class.class_variable_set(:@@base_url, @base_url) config.prefix = "#{@base_url}/#{Precious::Assets::ASSET_URL}" config.digest = @use_static_assets if @use_static_assets @@ -110,344 +113,372 @@ module Precious redirect clean_url(::File.join(@base_url, @page_dir, wiki_new.index_page)) end - get '/assets/*' do - env['PATH_INFO'].sub!("/#{Precious::Assets::ASSET_URL}", '') - if @use_static_assets - env['PATH_INFO'].sub!(Sprockets::Helpers.prefix, '') if @base_url - not_found_msg = "Not found." - not_found = Proc.new {[404, {'Content-Type' => 'text/html', 'Content-Length' => not_found_msg.length.to_s}, [not_found_msg]]} - Rack::Static.new(not_found, {:root => @static_assets_path, :urls => ['']}).call(env) - else - settings.sprockets.call(env) - end - end + namespace '/gollum' do - get '/last-commit-info' do - content_type :json - if page = wiki_page(params[:path]).page - version = page.last_version - {:author => version.author.name, :date => version.authored_date}.to_json - end - end - - get '/emoji/:name' do - begin - [200, {'Content-Type' => 'image/png'}, emoji(params['name'])] - rescue ArgumentError - not_found - end - end - - get '/data/*' do - if page = wiki_page(params[:splat].first).page - page.raw_data - end - end - - get %r{/(edit|create)/custom\.(js|css)} do - forbid('Changing this resource is not allowed.') - end - - post %r{/(deleteFile|rename|edit|create)/custom\.(js|css)} do - forbid('Changing this resource is not allowed.') - end - - post %r{/revert/custom\.(js|css)/.*/.*} do - forbid('Changing this resource is not allowed.') - end - - get '/edit/*' do - forbid unless @allow_editing - wikip = wiki_page(params[:splat].first) - @name = join_page_name(wikip.name, wikip.ext) - @path = wikip.path - @upload_dest = find_upload_dest(@path) - - wiki = wikip.wiki - @allow_uploads = wiki.allow_uploads - if page = wikip.page - @page = page - @page.version = wiki.repo.log(wiki.ref, @page.path).first - @content = page.text_data - mustache :edit - else - redirect to("/create/#{encodeURIComponent(@name)}") - end - end - - post '/uploadFile' do - wiki = wiki_new - - unless wiki.allow_uploads - @message = "File uploads are disabled" - mustache :error - return + get '/assets/*' do + env['PATH_INFO'].sub!("/#{Precious::Assets::ASSET_URL}", '') + if @use_static_assets + env['PATH_INFO'].sub!(Sprockets::Helpers.prefix, '') if @base_url + not_found_msg = "Not found." + not_found = Proc.new {[404, {'Content-Type' => 'text/html', 'Content-Length' => not_found_msg.length.to_s}, [not_found_msg]]} + Rack::Static.new(not_found, {:root => @static_assets_path, :urls => ['']}).call(env) + else + settings.sprockets.call(env) + end end - if params[:file] - fullname = params[:file][:filename] - tempfile = params[:file][:tempfile] - end - halt 500 unless tempfile.is_a? Tempfile - - # Remove page file dir prefix from upload path if necessary -- committer handles this itself - dir = wiki.per_page_uploads ? params[:upload_dest] : ::File.join([wiki.page_file_dir, 'uploads'].compact) - ext = ::File.extname(fullname) - format = ext.split('.').last || 'txt' - filename = ::File.basename(fullname, ext) - contents = ::File.read(tempfile) - reponame = "#{filename}.#{format}" - - head = wiki.repo.head - - options = { - :message => "Uploaded file to #{dir}/#{reponame}", - :parent => wiki.repo.head.commit, - } - author = session['gollum.author'] - unless author.nil? - options.merge! author + get '/last-commit-info' do + content_type :json + if page = wiki_page(params[:path]).page + version = page.last_version + {:author => version.author.name, :date => version.authored_date}.to_json + end end - begin - committer = Gollum::Committer.new(wiki, options) - committer.add_to_index(dir, filename, format, contents) - committer.after_commit do |committer, sha| - wiki.clear_cache - committer.update_working_dir(dir, filename, format) + get '/emoji/:name' do + begin + [200, {'Content-Type' => 'image/png'}, emoji(params['name'])] + rescue ArgumentError + not_found + end + end + + get '/data/*' do + if page = wiki_page(params[:splat].first).page + page.raw_data + end + end + + get %r{/(edit|create)/custom\.(js|css)} do + forbid('Changing this resource is not allowed.') + end + + post %r{/(deleteFile|rename|edit|create)/custom\.(js|css)} do + forbid('Changing this resource is not allowed.') + end + + post %r{/revert/custom\.(js|css)/.*/.*} do + forbid('Changing this resource is not allowed.') + end + + get '/edit/*' do + forbid unless @allow_editing + wikip = wiki_page(params[:splat].first) + @name = join_page_name(wikip.name, wikip.ext) + @path = wikip.path + @upload_dest = find_upload_dest(@path) + + wiki = wikip.wiki + @allow_uploads = wiki.allow_uploads + if page = wikip.page + @page = page + @page.version = wiki.repo.log(wiki.ref, @page.path).first + @content = page.text_data + mustache :edit + else + redirect_to("/create/#{encodeURIComponent(@name)}") + end + end + + post '/uploadFile' do + wiki = wiki_new + + unless wiki.allow_uploads + @message = "File uploads are disabled" + mustache :error + return + end + + if params[:file] + fullname = params[:file][:filename] + tempfile = params[:file][:tempfile] + end + halt 500 unless tempfile.is_a? Tempfile + + # Remove page file dir prefix from upload path if necessary -- committer handles this itself + dir = wiki.per_page_uploads ? params[:upload_dest] : ::File.join([wiki.page_file_dir, 'uploads'].compact) + ext = ::File.extname(fullname) + format = ext.split('.').last || 'txt' + filename = ::File.basename(fullname, ext) + contents = ::File.read(tempfile) + reponame = "#{filename}.#{format}" + + head = wiki.repo.head + + options = { + :message => "Uploaded file to #{dir}/#{reponame}", + :parent => wiki.repo.head.commit, + } + author = session['gollum.author'] + unless author.nil? + options.merge! author + end + + begin + committer = Gollum::Committer.new(wiki, options) + committer.add_to_index(dir, filename, format, contents) + committer.after_commit do |committer, sha| + wiki.clear_cache + committer.update_working_dir(dir, filename, format) + end + committer.commit + redirect to(request.referer) + rescue Gollum::DuplicatePageError => e + @message = "Duplicate page: #{e.message}" + mustache :error + end + end + + post '/deleteFile/*' do + forbid unless @allow_editing + wiki = wiki_new + filepath = params[:splat].first + unless filepath.nil? + commit = commit_message + commit[:message] = "Deleted #{filepath}" + wiki.delete_file(filepath, commit) + end + + redirect_to('/pages') + end + + post '/rename/*' do + wikip = wiki_page(params[:splat].first) + halt 500 if wikip.nil? + wiki = wikip.wiki + page = wiki.paged(join_page_name(wikip.name, wikip.ext), wikip.path, exact = true) + rename = params[:rename] + halt 500 if page.nil? + halt 500 if rename.nil? or rename.empty? + + # Fixup the rename if it is a relative path + # In 1.8.7 rename[0] != rename[0..0] + if rename[0..0] != '/' + source_dir = ::File.dirname(page.path) + source_dir = '' if source_dir == '.' + (target_dir, target_name) = ::File.split(rename) + target_dir = target_dir == '' ? source_dir : "#{source_dir}/#{target_dir}" + rename = "#{target_dir}/#{target_name}" + end + + committer = Gollum::Committer.new(wiki, commit_message) + commit = { :committer => committer } + + success = wiki.rename_page(page, rename, commit) + if !success + # This occurs on NOOPs, for example renaming A => A + redirect to("/#{page.escaped_url_path}") + return end committer.commit - redirect to(request.referer) - rescue Gollum::DuplicatePageError => e - @message = "Duplicate page: #{e.message}" - mustache :error - end - end - post '/deleteFile/*' do - forbid unless @allow_editing - wiki = wiki_new - filepath = params[:splat].first - unless filepath.nil? - commit = commit_message - commit[:message] = "Deleted #{filepath}" - wiki.delete_file(filepath, commit) - end - - redirect to('/pages') - end - - post '/rename/*' do - wikip = wiki_page(params[:splat].first) - halt 500 if wikip.nil? - wiki = wikip.wiki - page = wiki.paged(join_page_name(wikip.name, wikip.ext), wikip.path, exact = true) - rename = params[:rename] - halt 500 if page.nil? - halt 500 if rename.nil? or rename.empty? - - # Fixup the rename if it is a relative path - # In 1.8.7 rename[0] != rename[0..0] - if rename[0..0] != '/' - source_dir = ::File.dirname(page.path) - source_dir = '' if source_dir == '.' - (target_dir, target_name) = ::File.split(rename) - target_dir = target_dir == '' ? source_dir : "#{source_dir}/#{target_dir}" - rename = "#{target_dir}/#{target_name}" - end - - committer = Gollum::Committer.new(wiki, commit_message) - commit = { :committer => committer } - - success = wiki.rename_page(page, rename, commit) - if !success - # This occurs on NOOPs, for example renaming A => A + wikip = wiki_page(rename) + page = wiki.paged(join_page_name(wikip.name, wikip.ext), wikip.path, exact = true) + return if page.nil? redirect to("/#{page.escaped_url_path}") - return - end - committer.commit - - wikip = wiki_page(rename) - page = wiki.paged(join_page_name(wikip.name, wikip.ext), wikip.path, exact = true) - return if page.nil? - redirect to("/#{page.escaped_url_path}") - end - - post '/edit/*' do - path = "/#{clean_url(sanitize_empty_params(params[:path]))}" - page_name = CGI.unescape(params[:page]) - wiki = wiki_new - page = wiki.paged(page_name, path, exact = true) - return if page.nil? - committer = Gollum::Committer.new(wiki, commit_message) - commit = { :committer => committer } - - update_wiki_page(wiki, page, params[:content], commit, page.name, params[:format]) - update_wiki_page(wiki, page.header, params[:header], commit) if params[:header] - update_wiki_page(wiki, page.footer, params[:footer], commit) if params[:footer] - update_wiki_page(wiki, page.sidebar, params[:sidebar], commit) if params[:sidebar] - committer.commit - - redirect to("/#{page.escaped_url_path}") unless page.nil? - end - - get '/delete/*' do - forbid unless @allow_editing - wikip = wiki_page(params[:splat].first) - name = join_page_name(wikip.name, wikip.ext) - wiki = wikip.wiki - page = wikip.page - unless page.nil? - commit = commit_message - commit[:message] = "Destroyed #{name} (#{page.format})" - wiki.delete_page(page, commit) end - redirect to('/') - end + post '/edit/*' do + path = "/#{clean_url(sanitize_empty_params(params[:path]))}" + page_name = CGI.unescape(params[:page]) + wiki = wiki_new + page = wiki.paged(page_name, path, exact = true) + return if page.nil? + committer = Gollum::Committer.new(wiki, commit_message) + commit = { :committer => committer } - get '/create/*' do - forbid unless @allow_editing - if settings.wiki_options[:template_page] then - temppage = wiki_page("/_Template") - @template_page = (temppage.page != nil) ? temppage.page.raw_data : "Template page option is set, but no /_Template page is present or committed." + update_wiki_page(wiki, page, params[:content], commit, page.name, params[:format]) + update_wiki_page(wiki, page.header, params[:header], commit) if params[:header] + update_wiki_page(wiki, page.footer, params[:footer], commit) if params[:footer] + update_wiki_page(wiki, page.sidebar, params[:sidebar], commit) if params[:sidebar] + committer.commit + + redirect to("/#{page.escaped_url_path}") unless page.nil? end - wikip = wiki_page(params[:splat].first) - @name = wikip.name.to_url - @ext = wikip.ext - @path = wikip.path - @allow_uploads = wikip.wiki.allow_uploads - @upload_dest = find_upload_dest(@path) - page_dir = settings.wiki_options[:page_file_dir].to_s - unless page_dir.empty? - # --page-file-dir docs - # /docs/Home should be created in /Home - # not /docs/Home because write_page will append /docs - @path = @path.sub(page_dir, '/') if @path.start_with? page_dir - end - @path = clean_path(@path) - - page = wikip.page - if page - page_dir = settings.wiki_options[:page_file_dir].to_s - redirect to("/#{clean_url(::File.join(page_dir, page.escaped_url_path))}") - else - unless Gollum::Page.format_for("#{@name}#{@ext}") - @name = "#{@name}#{@ext}" - @ext = nil + get '/delete/*' do + forbid unless @allow_editing + wikip = wiki_page(params[:splat].first) + name = join_page_name(wikip.name, wikip.ext) + wiki = wikip.wiki + page = wikip.page + unless page.nil? + commit = commit_message + commit[:message] = "Destroyed #{name} (#{page.format})" + wiki.delete_page(page, commit) end - mustache :create + + redirect to('/') end - end - post '/create' do - name = params[:page].to_url - path = sanitize_empty_params(params[:path]) || '' - format = params[:format].intern - wiki = wiki_new - - path.gsub!(/^\//, '') - - begin - wiki.write_page(name, format, params[:content], commit_message, path) + get '/create/*' do + forbid unless @allow_editing + if settings.wiki_options[:template_page] then + temppage = wiki_page("/_Template") + @template_page = (temppage.page != nil) ? temppage.page.raw_data : "Template page option is set, but no /_Template page is present or committed." + end + wikip = wiki_page(params[:splat].first) + @name = wikip.name.to_url + @ext = wikip.ext + @path = wikip.path + @allow_uploads = wikip.wiki.allow_uploads + @upload_dest = find_upload_dest(@path) page_dir = settings.wiki_options[:page_file_dir].to_s - redirect to("/#{clean_url(::File.join(encodeURIComponent(page_dir), encodeURIComponent(path), encodeURIComponent(wiki.page_file_name(name, format))))}") - rescue Gollum::DuplicatePageError => e - @message = "Duplicate page: #{e.message}" - mustache :error + unless page_dir.empty? + # --page-file-dir docs + # /docs/Home should be created in /Home + # not /docs/Home because write_page will append /docs + @path = @path.sub(page_dir, '/') if @path.start_with? page_dir + end + @path = clean_path(@path) + + page = wikip.page + if page + page_dir = settings.wiki_options[:page_file_dir].to_s + redirect to("/#{clean_url(::File.join(page_dir, page.escaped_url_path))}") + else + unless Gollum::Page.format_for("#{@name}#{@ext}") + @name = "#{@name}#{@ext}" + @ext = nil + end + mustache :create + end end - end - post '/revert/*/:sha1/:sha2' do - wikip = wiki_page(params[:splat].first) - @path = wikip.path - @name = join_page_name(wikip.name, wikip.ext) - wiki = wikip.wiki - @page = wiki.paged(@name, @path) - sha1 = params[:sha1] - sha2 = params[:sha2] + post '/create' do + name = params[:page].to_url + path = sanitize_empty_params(params[:path]) || '' + format = params[:format].intern + wiki = wiki_new - commit = commit_message - commit[:message] = "Revert commit #{sha1.chars.take(7).join}" - if wiki.revert_page(@page, sha1, sha2, commit) - redirect to("/#{@page.escaped_url_path}") - else - sha2, sha1 = sha1, "#{sha1}^" if !sha2 - @versions = [sha1, sha2] - diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path) - @diff = diffs.first - @message = "The patch does not apply." + path.gsub!(/^\//, '') + + begin + wiki.write_page(name, format, params[:content], commit_message, path) + + page_dir = settings.wiki_options[:page_file_dir].to_s + redirect to("/#{clean_url(::File.join(encodeURIComponent(page_dir), encodeURIComponent(path), encodeURIComponent(wiki.page_file_name(name, format))))}") + rescue Gollum::DuplicatePageError => e + @message = "Duplicate page: #{e.message}" + mustache :error + end + end + + post '/revert/*/:sha1/:sha2' do + wikip = wiki_page(params[:splat].first) + @path = wikip.path + @name = join_page_name(wikip.name, wikip.ext) + wiki = wikip.wiki + @page = wiki.paged(@name, @path) + sha1 = params[:sha1] + sha2 = params[:sha2] + + commit = commit_message + commit[:message] = "Revert commit #{sha1.chars.take(7).join}" + if wiki.revert_page(@page, sha1, sha2, commit) + redirect to("/#{@page.escaped_url_path}") + else + sha2, sha1 = sha1, "#{sha1}^" if !sha2 + @versions = [sha1, sha2] + diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path) + @diff = diffs.first + @message = "The patch does not apply." + mustache :compare + end + end + + post '/preview' do + wiki = wiki_new + @name = params[:page] || "Preview" + @page = wiki.preview_page(@name, params[:content], params[:format]) + @content = @page.formatted_data + @toc_content = wiki.universal_toc ? @page.toc_data : nil + @mathjax = wiki.mathjax + @h1_title = wiki.h1_title + @editable = false + @bar_side = wiki.bar_side + @allow_uploads = wiki.allow_uploads + mustache :page + end + + get '/history/*' do + @page = wiki_page(params[:splat].first).page + @page_num = [params[:page].to_i, 1].max + unless @page.nil? + @versions = @page.versions(:page => @page_num, :follow => settings.wiki_options.fetch(:follow_renames, ::Gollum::GIT_ADAPTER == 'rjgit' ? false : true)) + mustache :history + else + redirect to("/") + end + end + + get '/latest_changes' do + @wiki = wiki_new + max_count = settings.wiki_options.fetch(:latest_changes_count, 10) + @versions = @wiki.latest_changes({:max_count => max_count}) + mustache :latest_changes + end + + post '/compare/*' do + @file = encodeURIComponent(params[:splat].first) + @versions = params[:versions] || [] + if @versions.size < 2 + redirect_to("/history/#{@file}") + else + redirect_to("/compare/%s/%s...%s" % [ + @file, + @versions.last, + @versions.first] + ) + end + end + + get %r{ + /compare/ # match any URL beginning with /compare/ + (.+) # extract the full path (including any directories) + / # match the final slash + ([^.]+) # match the first SHA1 + \.{2,3} # match .. or ... + (.+) # match the second SHA1 + }x do |path, start_version, end_version| + wikip = wiki_page(path) + @path = wikip.path + @name = join_page_name(wikip.name, wikip.ext) + @versions = [start_version, end_version] + wiki = wikip.wiki + @page = wikip.page + diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path) + @diff = diffs.first mustache :compare end - end - post '/preview' do - wiki = wiki_new - @name = params[:page] || "Preview" - @page = wiki.preview_page(@name, params[:content], params[:format]) - @content = @page.formatted_data - @toc_content = wiki.universal_toc ? @page.toc_data : nil - @mathjax = wiki.mathjax - @h1_title = wiki.h1_title - @editable = false - @bar_side = wiki.bar_side - @allow_uploads = wiki.allow_uploads - mustache :page - end - - get '/history/*' do - @page = wiki_page(params[:splat].first).page - @page_num = [params[:page].to_i, 1].max - unless @page.nil? - @versions = @page.versions(:page => @page_num, :follow => settings.wiki_options.fetch(:follow_renames, ::Gollum::GIT_ADAPTER == 'rjgit' ? false : true)) - mustache :history - else - redirect to("/") + get '/search' do + @query = params[:q] || '' + wiki = wiki_new + # Sort wiki search results by count (desc) and then by name (asc) + @results = wiki.search(@query).sort { |a, b| (a[:count] <=> b[:count]).nonzero? || b[:name] <=> a[:name] }.reverse + @name = @query + mustache :search end - end - get '/latest_changes' do - @wiki = wiki_new - max_count = settings.wiki_options.fetch(:latest_changes_count, 10) - @versions = @wiki.latest_changes({:max_count => max_count}) - mustache :latest_changes - end - - post '/compare/*' do - @file = encodeURIComponent(params[:splat].first) - @versions = params[:versions] || [] - if @versions.size < 2 - redirect to("/history/#{@file}") - else - redirect to("/compare/%s/%s...%s" % [ - @file, - @versions.last, - @versions.first] - ) + get %r{ + /pages # match any URL beginning with /pages + (?: # begin an optional non-capturing group + /(.+) # capture any path after the "/pages" excluding the leading slash + )? # end the optional non-capturing group + }x do |path| + @path = extract_path(path) if path + wiki_options = settings.wiki_options.merge({ :page_file_dir => @path }) + wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options) + @results = wiki.pages + @results += wiki.files + @results = @results.sort_by { |p| p.name.downcase } # Sort Results alphabetically, fixes 922 + @ref = wiki.ref + mustache :pages end end - get %r{ - /compare/ # match any URL beginning with /compare/ - (.+) # extract the full path (including any directories) - / # match the final slash - ([^.]+) # match the first SHA1 - \.{2,3} # match .. or ... - (.+) # match the second SHA1 - }x do |path, start_version, end_version| - wikip = wiki_page(path) - @path = wikip.path - @name = join_page_name(wikip.name, wikip.ext) - @versions = [start_version, end_version] - wiki = wikip.wiki - @page = wikip.page - diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path) - @diff = diffs.first - mustache :compare - end - get %r{/(.+?)/([0-9a-f]{40})} do file_path = params[:captures][0] version = params[:captures][1] @@ -468,32 +499,6 @@ module Precious end end - get '/search' do - @query = params[:q] || '' - wiki = wiki_new - # Sort wiki search results by count (desc) and then by name (asc) - @results = wiki.search(@query).sort { |a, b| (a[:count] <=> b[:count]).nonzero? || b[:name] <=> a[:name] }.reverse - @name = @query - mustache :search - end - - get %r{ - /pages # match any URL beginning with /pages - (?: # begin an optional non-capturing group - /(.+) # capture any path after the "/pages" excluding the leading slash - )? # end the optional non-capturing group - }x do |path| - @path = extract_path(path) if path - wiki_options = settings.wiki_options.merge({ :page_file_dir => @path }) - wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options) - @results = wiki.pages - @results += wiki.files - @results = @results.sort_by { |p| p.name.downcase } # Sort Results alphabetically, fixes 922 - @ref = wiki.ref - mustache :pages - end - - get '/*' do show_page_or_file(params[:splat].first) end @@ -525,7 +530,7 @@ module Precious else if @allow_editing page_path = [path, join_page_name(name, ext)].compact.join('/') - redirect to("/create/#{clean_url(encodeURIComponent(page_path))}") + redirect to("/gollum/create/#{clean_url(encodeURIComponent(page_path))}") else @message = "The requested page does not exist." status 404 diff --git a/lib/gollum/assets.rb b/lib/gollum/assets.rb index 84763678..50003804 100644 --- a/lib/gollum/assets.rb +++ b/lib/gollum/assets.rb @@ -1,7 +1,7 @@ module Precious module Assets MANIFEST = %w(app.js app.css fileview.css ie7.css print.css *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2) - ASSET_URL = 'assets' + ASSET_URL = 'gollum/assets' def self.sprockets(dir = File.dirname(File.expand_path(__FILE__))) env = Sprockets::Environment.new @@ -12,6 +12,13 @@ module Precious env.js_compressor = :uglify env.css_compressor = :scss + + env.context_class.class_eval do + def base_url + self.class.class_variable_get(:@@base_url) + end + include ::Precious::Views::RouteHelpers + end env end end diff --git a/lib/gollum/public/gollum/javascript/app.js b/lib/gollum/public/gollum/javascript/app.js index 7f6f754f..9064b6c2 100644 --- a/lib/gollum/public/gollum/javascript/app.js +++ b/lib/gollum/public/gollum/javascript/app.js @@ -28,4 +28,4 @@ //= require ace-1.3.1/ext-textarea.js //= require ace-1.3.1/ext-themelist.js //= require ace-1.3.1/ext-whitespace.js -//= require jquery.resize +//= require jquery.resize \ No newline at end of file diff --git a/lib/gollum/public/gollum/javascript/editor/gollum.editor.js b/lib/gollum/public/gollum/javascript/editor/gollum.editor.js.erb similarity index 99% rename from lib/gollum/public/gollum/javascript/editor/gollum.editor.js rename to lib/gollum/public/gollum/javascript/editor/gollum.editor.js.erb index 3b9d86f9..ad46f548 100755 --- a/lib/gollum/public/gollum/javascript/editor/gollum.editor.js +++ b/lib/gollum/public/gollum/javascript/editor/gollum.editor.js.erb @@ -209,7 +209,7 @@ formData.append('file', file); $.ajax({ - url: baseUrl + '/uploadFile', + url: '<%= upload_file_path %>', data: formData, cache: false, contentType: false, diff --git a/lib/gollum/public/gollum/javascript/gollum.js b/lib/gollum/public/gollum/javascript/gollum.js.erb similarity index 95% rename from lib/gollum/public/gollum/javascript/gollum.js rename to lib/gollum/public/gollum/javascript/gollum.js.erb index 51d5a788..b3dd8161 100755 --- a/lib/gollum/public/gollum/javascript/gollum.js +++ b/lib/gollum/public/gollum/javascript/gollum.js.erb @@ -47,7 +47,7 @@ $(document).ready(function() { $('#delete-link').click( function(e) { var ok = confirm($(this).data('confirm')); if ( ok ) { - var loc = baseUrl + '/delete/' + pageFullPath; + var loc = '<%= delete_path %>/' + pageFullPath; window.location = loc; } // Don't navigate on cancel. @@ -162,7 +162,7 @@ $(document).ready(function() { { type: 'file', context: 'Your uploaded file will be accessible at
/'+uploadDest+'/[filename]', - action: baseUrl + '/uploadFile' + action: '<%= upload_file_path %>' } ], OK: function( res ) { @@ -226,10 +226,14 @@ $(document).ready(function() { // In the pages view, pageFullPath isn't defined. // The new button will still expect a value however. // So we try to figure one out from window.location - path = baseUrl == '' ? window.location.pathname.substr(1) - : window.location.pathname.substr(baseUrl.length + 1); + path = window.location.pathname.substr(1) // Remove the page viewer part of the url. - path = path.replace(/^pages\/?/,'') + <% + pages_path_uri = pages_path + pages_path_uri = pages_path_uri[1..-1] if pages_path_uri[0] == '/' + pages_path_uri = pages_path_uri.gsub('/','\/') + %> + path = path.replace(/^<%= pages_path_uri %>\/?/,'') // For consistency remove the trailing / path = path.replace(/\/$/,'') } @@ -260,7 +264,7 @@ $(document).ready(function() { for( var i=0; i < name_parts.length; i++ ){ name_encoded.push(encodeURIComponent(name_parts[i])); } - window.location = baseUrl + name_encoded.join('/'); + window.location = '<%= create_path %>' + name_encoded.join('/'); } }); }); @@ -315,7 +319,7 @@ $(document).ready(function() { if( $("#last-edit").length ) { $("#page-info-toggle").click ( function () { $.ajax({ - url: '/last-commit-info', + url: '<%= last_commit_info_path %>', data: {path: $("#page-info-toggle").data('pagepath')}, success: function ( data ) { $("#last-edit").html('Last edited by ' + data.author + ', ' + data.date); diff --git a/lib/gollum/public/gollum/stylesheets/editor.scss b/lib/gollum/public/gollum/stylesheets/editor.scss index 857e1652..af167e00 100644 --- a/lib/gollum/public/gollum/stylesheets/editor.scss +++ b/lib/gollum/public/gollum/stylesheets/editor.scss @@ -325,7 +325,7 @@ a { @include alt-box-model; } - + } /* @control title */ diff --git a/lib/gollum/templates/compare.mustache b/lib/gollum/templates/compare.mustache index da723978..11ac42a5 100644 --- a/lib/gollum/templates/compare.mustache +++ b/lib/gollum/templates/compare.mustache @@ -9,10 +9,10 @@
  • View Page
  • {{#allow_editing}} -
  • Edit Page
  • {{/allow_editing}} -
  • Page History
  • @@ -25,11 +25,11 @@ {{#show_revert}} @@ -21,7 +21,7 @@
    + action="{{compare_path}}/{{escaped_url_path}}">
    diff --git a/lib/gollum/templates/history_authors/identicon.mustache b/lib/gollum/templates/history_authors/identicon.mustache index ee57fad0..7ff1cbed 100644 --- a/lib/gollum/templates/history_authors/identicon.mustache +++ b/lib/gollum/templates/history_authors/identicon.mustache @@ -1,5 +1,5 @@ - avatar: {{author}} {{author}} \ No newline at end of file diff --git a/lib/gollum/templates/layout.mustache b/lib/gollum/templates/layout.mustache index 546fa114..c972591f 100644 --- a/lib/gollum/templates/layout.mustache +++ b/lib/gollum/templates/layout.mustache @@ -5,13 +5,13 @@ - {{#stylesheet_tag_mustache}}app media: :all{{/stylesheet_tag_mustache}} - {{#stylesheet_tag_mustache}}print media: :print{{/stylesheet_tag_mustache}} + {{#sprockets_stylesheet_tag}}app{{/sprockets_stylesheet_tag}} + {{#sprockets_stylesheet_tag}}print print{{/sprockets_stylesheet_tag}} {{#css}}{{/css}} {{#noindex}}{{/noindex}} - {{#javascript_tag_mustache}}app{{/javascript_tag_mustache}} + {{#sprockets_javascript_tag}}app{{/sprockets_javascript_tag}} {{#use_identicon}} - {{#javascript_tag_mustache}}identicon_canvas{{/javascript_tag_mustache}} + {{#sprockets_javascript_tag}}identicon_canvas{{/sprockets_javascript_tag}} {{/use_identicon}} {{#mathjax}} {{^mathjax_config}} diff --git a/lib/gollum/templates/page.mustache b/lib/gollum/templates/page.mustache index 110feb56..6853ff43 100644 --- a/lib/gollum/templates/page.mustache +++ b/lib/gollum/templates/page.mustache @@ -14,7 +14,7 @@ Mousetrap.bind(['e'], function( e ) {
  • Home
  • -
  • Overview
  • {{#allow_editing}}
  • @@ -34,13 +34,13 @@ Mousetrap.bind(['e'], function( e ) { {{/allow_editing}} {{#allow_editing}} {{#editable}} -
  • Edit
  • {{/editable}} {{/allow_editing}} -
  • History
  • -
  • Latest Changes
  • @@ -91,7 +91,7 @@ Mousetrap.bind(['e'], function( e ) { - + diff --git a/lib/gollum/templates/searchbar.mustache b/lib/gollum/templates/searchbar.mustache index 768fcbf0..48b428b5 100644 --- a/lib/gollum/templates/searchbar.mustache +++ b/lib/gollum/templates/searchbar.mustache @@ -1,5 +1,5 @@