Provide JS with correct exts via template (#1437)

This commit is contained in:
Dawa Ometto
2019-10-10 16:36:06 +02:00
committed by GitHub
parent c619920452
commit c8fed4d50d
5 changed files with 5 additions and 14 deletions
-2
View File
@@ -181,8 +181,6 @@ end
desc 'Precompile assets' desc 'Precompile assets'
task :precompile do task :precompile do
require 'gollum'
require 'gollum-lib'
require './lib/gollum/views/helpers.rb' require './lib/gollum/views/helpers.rb'
require './lib/gollum/assets.rb' require './lib/gollum/assets.rb'
require 'sprockets' require 'sprockets'
@@ -82,12 +82,6 @@ function abspath(path, name){
return [newPath, newName]; return [newPath, newName];
} }
var gollumFormats = $.parseJSON('<%= format_extensions %>');
function formatToExt(format) {
// 'markdown' -> .md, 'asciidoc' -> .asciidoc
return gollumFormats[format];
}
function setTextDirection () { function setTextDirection () {
$('.markdown-body p, .markdown-body span, .markdown-body pre, .markdown-body table').attr('dir','auto'); $('.markdown-body p, .markdown-body span, .markdown-body pre, .markdown-body table').attr('dir','auto');
} }
@@ -444,7 +438,8 @@ $(document).ready(function() {
$(this).attr('disabled', true); $(this).attr('disabled', true);
var formData = new FormData($('#gollum-editor-form').get(0)); var formData = new FormData($('#gollum-editor-form').get(0));
var newPath = cleanPath(prefixBaseUrl(pagePath() + '/' + pageName() + formatToExt($('#wiki_format')[0].value))); var newExt = '.' + $('#wiki_format option:selected').attr('data-ext');
var newPath = cleanPath(prefixBaseUrl(pagePath() + '/' + pageName() + newExt));
var endpoint = $('#gollum-editor-form').attr("action"); var endpoint = $('#gollum-editor-form').attr("action");
$.ajax({ $.ajax({
+2 -2
View File
@@ -59,14 +59,14 @@
<select id="wiki_format" name="format" class="form-select"> <select id="wiki_format" name="format" class="form-select">
{{#formats}} {{#formats}}
{{#enabled}} {{#enabled}}
<option {{#selected}}selected="selected" {{/selected}}value="{{id}}"> <option {{#selected}}selected="selected" {{/selected}}value="{{id}}" data-ext="{{ext}}">
{{name}} {{name}}
</option> </option>
{{/enabled}} {{/enabled}}
{{/formats}} {{/formats}}
{{#formats}} {{#formats}}
{{^enabled}} {{^enabled}}
<option class="disabled" {{#selected}}selected="selected" {{/selected}}value="{{id}}"> <option class="disabled" {{#selected}}selected="selected" {{/selected}}value="{{id}}" data-ext="{{ext}}">
{{name}} {{name}}
</option> </option>
{{/enabled}} {{/enabled}}
+1
View File
@@ -9,6 +9,7 @@ module Precious
{ :name => val[:name], { :name => val[:name],
:id => key.to_s, :id => key.to_s,
:enabled => val.fetch(:enabled, true), :enabled => val.fetch(:enabled, true),
:ext => Gollum::Page.format_to_ext(key),
:selected => selected == key } :selected => selected == key }
end.sort do |a, b| end.sort do |a, b|
a[:name].downcase <=> b[:name].downcase a[:name].downcase <=> b[:name].downcase
-3
View File
@@ -51,9 +51,6 @@ module Precious
define_method :routes_to_json do define_method :routes_to_json do
@@route_methods.to_json @@route_methods.to_json
end end
define_method :format_extensions do
Hash[Gollum::Markup.formats.to_a.map{|fmt| [fmt[0], ".#{Gollum::Page.format_to_ext(fmt[0])}"]}].to_json
end
end end
def page_route(page) def page_route(page)