diff --git a/Rakefile b/Rakefile index b6bae187..1559ad6f 100644 --- a/Rakefile +++ b/Rakefile @@ -177,3 +177,23 @@ task :validate do exit! end end + +desc 'Precompile assets' +task :precompile do + require './lib/gollum/views/helpers.rb' + require './lib/gollum/assets.rb' + require 'sprockets' + require 'sprockets-helpers' + require 'sass' + env = Precious::Assets.sprockets + manifest = Sprockets::Manifest.new(env, './public/assets') + Sprockets::Helpers.configure do |config| + config.environment = env + config.prefix = Precious::Assets::ASSET_URL + config.digest = true + config.public_path = ENV.fetch('GOLLUM_ASSETS_PATH', './public/assets') + config.manifest = manifest + end + puts "Precompiling assets to #{::File.expand_path('./public/assets')}..." + manifest.compile(Precious::Assets::MANIFEST) +end diff --git a/bin/gollum b/bin/gollum index e28e37f5..dc8aeea4 100755 --- a/bin/gollum +++ b/bin/gollum @@ -104,9 +104,6 @@ MSG opts.on("--assets [PATH]", "Set the path to look for static assets. Only used if --static is set to true, or environment is production/staging. Default: ./public/assets") do |path| wiki_options[:static_assets_path] = path end - opts.on("--precompile-assets [PATH]", "Precompile static assets to PATH.") do |path| - options[:precompile] = path || './public/assets' - end opts.on("--css", "Inject custom CSS into each page. The '/custom.css' file is used (must be committed).") do wiki_options[:css] = true end @@ -262,20 +259,6 @@ if options[:irb] puts "Invalid Gollum wiki at #{File.expand_path(gollum_path).inspect}" exit 0 end -elsif options[:precompile] - require 'gollum/app' - env = Precious::Assets.sprockets - manifest = Sprockets::Manifest.new(env, options[:precompile]) - Sprockets::Helpers.configure do |config| - config.environment = env - config.environment.context_class.class_variable_set(:@@base_url, wiki_options[:base_path]) - config.prefix = "#{wiki_options[:base_path]}/#{Precious::Assets::ASSET_URL}" - config.digest = true - config.public_path = options[:precompile] - config.manifest = manifest - end - puts "Precompiling assets to #{::File.expand_path(options[:precompile])}..." - manifest.compile(Precious::Assets::MANIFEST) else require 'gollum/app' Precious::App.set(:gollum_path, gollum_path) diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index e2caa6ec..a5547a77 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -8,7 +8,6 @@ require 'stringex' require 'json' require 'sprockets' require 'sprockets-helpers' -require 'uglifier' require 'sass' require 'gollum' diff --git a/lib/gollum/public/gollum/javascript/editor/gollum.editor.js.erb b/lib/gollum/public/gollum/javascript/editor/gollum.editor.js.erb index 8992691f..4a5f545d 100755 --- a/lib/gollum/public/gollum/javascript/editor/gollum.editor.js.erb +++ b/lib/gollum/public/gollum/javascript/editor/gollum.editor.js.erb @@ -151,7 +151,7 @@ // get form fields var oldAction = $('#gollum-editor form').attr('action'); var $form = $($('#gollum-editor form').get(0)); - $form.attr('action', this.href || '/preview'); + $form.attr('action', this.href || routePath('preview')); $form.attr('target', '_blank'); var paths = window.location.pathname.split('/'); $form.attr('page', paths[ paths.length - 1 ] || '') @@ -208,7 +208,7 @@ formData.append('file', file); $.ajax({ - url: '<%= upload_file_path %>', + url: routePath('upload_file'), data: formData, cache: false, contentType: false, @@ -316,26 +316,20 @@ } if ( !LanguageDefinition.isLoadedFor(name) ) { LanguageDefinition._ACTIVE_LANG = null; - LanguageDefinition.loadFor( name, function(x, t) { - if ( t != 'success' ) { - debug('Failed to load language definition for ' + name); - // well, fake it and turn everything off for this one - LanguageDefinition.define( name, {} ); - } - // update features that rely on the language definition - if ( EditorHas.functionBar() ) { - FunctionBar.refresh(); - } + // update features that rely on the language definition + if ( EditorHas.functionBar() ) { + FunctionBar.refresh(); + } - if ( LanguageDefinition.isValid() && EditorHas.formatSelector() ) { - FormatSelector.updateSelected(); - } + if ( LanguageDefinition.isValid() && EditorHas.formatSelector() ) { + FormatSelector.updateSelected(); + } + + if(LanguageDefinition.getHookFunctionFor("activate")) { + LanguageDefinition.getHookFunctionFor("activate")(); + } - if(LanguageDefinition.getHookFunctionFor("activate")) { - LanguageDefinition.getHookFunctionFor("activate")(); - } - } ); } else { LanguageDefinition._ACTIVE_LANG = name; FunctionBar.refresh(); @@ -416,43 +410,6 @@ return null; }, - - /** - * loadFor - * Asynchronously loads a definition file for the current markup. - * Definition files are necessary to use the code editor. - * - * @param string markup_name The markup name you want to load - * @return void - */ - loadFor: function( markup_name, on_complete ) { - // Keep us from hitting 404s on our site, check the definition blacklist - if ( ActiveOptions.NoDefinitionsFor.length ) { - for ( var i=0; i < ActiveOptions.NoDefinitionsFor.length; i++ ) { - if ( markup_name == ActiveOptions.NoDefinitionsFor[i] ) { - // we don't have this. get out. - if ( typeof on_complete == 'function' ) { - on_complete( null, 'error' ); - return; - } - } - } - } - - // attempt to load the definition for this language - var script_uri = baseUrl + '/assets/editor/langs/' + markup_name + '.js'; - $.ajax({ - url: script_uri, - dataType: 'script', - complete: function( xhr, textStatus ) { - if ( typeof on_complete == 'function' ) { - on_complete( xhr, textStatus ); - } - } - }); - }, - - /** * isLoadedFor * Checks to see if a definition file has been loaded for the diff --git a/lib/gollum/public/gollum/javascript/gollum.dialog.js b/lib/gollum/public/gollum/javascript/gollum.dialog.js.erb similarity index 99% rename from lib/gollum/public/gollum/javascript/gollum.dialog.js rename to lib/gollum/public/gollum/javascript/gollum.dialog.js.erb index b2e9ec7f..33414a2a 100755 --- a/lib/gollum/public/gollum/javascript/gollum.dialog.js +++ b/lib/gollum/public/gollum/javascript/gollum.dialog.js.erb @@ -101,7 +101,7 @@ var id = fieldAttributes.id || 'upload'; var name = fieldAttributes.name || 'file'; - var action = fieldAttributes.action || '/upload_file'; + var action = fieldAttributes.action || routePath('upload_file'); html += '
'; diff --git a/lib/gollum/public/gollum/javascript/gollum.js.erb b/lib/gollum/public/gollum/javascript/gollum.js.erb index e87278a7..d881849b 100755 --- a/lib/gollum/public/gollum/javascript/gollum.js.erb +++ b/lib/gollum/public/gollum/javascript/gollum.js.erb @@ -1,4 +1,27 @@ // Helpers + +// Get path for named route, prefixing baseUrl if necessary +// Uses the route definitions in /lib/gollum/views/helpers.rb. +// For example, routePath('delete') is equivalent to 'delete_path' in the mustache templates. +function routePath(name){ + var routes = $.parseJSON('<%= routes_to_json %>') + path = routes[name] + if (baseUrl == undefined ) { + console.log('Gollum error: baseUrl undefined') + } else if (path == undefined ) { + console.log('Could not find route with name: ' + name) + } else { + if ( baseUrl == "") { + return path; + } else if (baseUrl.charAt(baseUrl.length -1) == '/') { + result = baseUrl + path; + } else { + result = baseUrl + '/' + path; + } + return result.replace(/\/{2}/g, '/') + } +} + function pageName(){ // "my/dir/file.md" => "file" if (typeof(pageFullPath) == 'undefined') { @@ -48,7 +71,7 @@ $(document).ready(function() { $('#delete-link').click( function(e) { var ok = confirm($(this).data('confirm')); if ( ok ) { - $.post('<%=delete_path %>/' + pageFullPath, + $.post(routePath('delete') + '/' + pageFullPath, {}, function (result) { // page successfully deleted, return to landing page @@ -63,7 +86,7 @@ $(document).ready(function() { var ok = confirm($(this).data('confirm')); if ( ok ) { var element = $(this); - $.post('<%=delete_path %>' + $(this).data('file-path'), + $.post(routePath('delete') + '/' + $(this).data('file-path'), {}, function (result) { // file successfully deleted, stay on overview but remove element from DOM @@ -184,7 +207,7 @@ $(document).ready(function() { { type: 'file', context: 'Your uploaded file will be accessible at
/'+uploadDest+'/[filename]', - action: '<%= upload_file_path %>' + action: routePath('upload_file') } ], OK: function( res ) { @@ -279,14 +302,7 @@ $(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 = window.location.pathname.substr(1) - // Remove the page viewer part of the url. - <% - 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 %>\/?/,'') + path = window.location.pathname.replace(routePath('pages'), '') // For consistency remove the trailing / path = path.replace(/\/$/,'') } @@ -317,7 +333,7 @@ $(document).ready(function() { for( var i=0; i < name_parts.length; i++ ){ name_encoded.push(encodeURIComponent(name_parts[i])); } - window.location = '<%= create_path %>' + name_encoded.join('/'); + window.location = routePath('create') + name_encoded.join('/'); } }); }); @@ -400,7 +416,7 @@ $(document).ready(function() { if( $("#last-edit").length ) { $("#page-info-toggle").click ( function () { $.ajax({ - url: '<%= last_commit_info_path %>', + url: routePath('last_commit_info'), 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/_base.scss b/lib/gollum/public/gollum/stylesheets/_base.scss index a1fbe32d..2d5d22ba 100644 --- a/lib/gollum/public/gollum/stylesheets/_base.scss +++ b/lib/gollum/public/gollum/stylesheets/_base.scss @@ -46,10 +46,10 @@ $editor-button-img-width: 27px; $editor-button-img-height: 28px; //urls -$img_fileview_doc: image-url('fileview/document.png'); -$img_fileview_trash: image-url('fileview/trashcan.png'); -$img_fileview_toggle_small: image-url('fileview/toggle-small.png'); -$img_fileview_toggle_small_expand: image-url('fileview/toggle-small-expand.png'); -$img_fileview_folder: image-url('fileview/folder-horizontal.png'); -$img_icon_sprite: image-url('icon-sprite.png'); -$img_dirty_shade: image-url('dirty-shade.png'); \ No newline at end of file +$img_fileview_doc: url('../images/fileview/document.png'); +$img_fileview_trash: url('../images/fileview/trashcan.png'); +$img_fileview_toggle_small: url('../images/fileview/toggle-small.png'); +$img_fileview_toggle_small_expand: url('../images/fileview/toggle-small-expand.png'); +$img_fileview_folder: url('../images/fileview/folder-horizontal.png'); +$img_icon_sprite: url('../images/icon-sprite.png'); +$img_dirty_shade: url('../images/dirty-shade.png'); \ No newline at end of file diff --git a/lib/gollum/templates/page.mustache b/lib/gollum/templates/page.mustache index a7bc84e4..a1d33733 100644 --- a/lib/gollum/templates/page.mustache +++ b/lib/gollum/templates/page.mustache @@ -1,7 +1,7 @@ diff --git a/lib/gollum/views/helpers.rb b/lib/gollum/views/helpers.rb index 223b4381..b328914d 100644 --- a/lib/gollum/views/helpers.rb +++ b/lib/gollum/views/helpers.rb @@ -1,10 +1,11 @@ -require 'yaml' +require 'json' module Precious module Views module RouteHelpers ROUTES = { 'gollum' => { + assets: 'assets', last_commit_info: 'last_commit_info', latest_changes: 'latest_changes', upload_file: 'upload_file', @@ -25,15 +26,21 @@ module Precious if path.respond_to?(:keys) self.parse_routes(path, "#{prefix}/#{name}") else + route_path = "#{prefix}/#{path}" + @@route_methods[name.to_s] = route_path define_method :"#{name.to_s}_path" do - "#{base_url}/#{prefix}/#{path}".gsub(/\/{2,}/, '/') # remove double slashes + "#{base_url}/#{route_path}".gsub(/\/{2,}/, '/') # remove double slashes end end end end def self.included(base) + @@route_methods = {} self.parse_routes(ROUTES) + define_method :routes_to_json do + @@route_methods.to_json + end end end diff --git a/lib/gollum/views/pages.rb b/lib/gollum/views/pages.rb index 49745a1c..51efe802 100644 --- a/lib/gollum/views/pages.rb +++ b/lib/gollum/views/pages.rb @@ -57,7 +57,7 @@ module Precious klass = (defined? result.format) ? "page" : "file" url = "#{@base_url}/#{result.escaped_url_path}" - file_link = %{
  • #{result.filename}#{delete_file(url) if @allow_editing}
  • } + file_link = %{
  • #{result.filename}#{delete_file(result.escaped_url_path) if @allow_editing}
  • } files[result.name] = file_link end end