0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 17:30:29 +01:00

Update raw templating handling to new asset pipeline

Dieser Commit ist enthalten in:
Angus McLeod 2020-10-02 11:38:32 +10:00
Ursprung 39790bf11e
Commit 05f96beac1
5 geänderte Dateien mit 25 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -1,7 +1,5 @@
window.Discourse = {} window.Discourse = {}
window.Wizard = {}; window.Wizard = {};
Wizard.SiteSettings = {}; Wizard.SiteSettings = {};
Wizard.RAW_TEMPLATES = {};
Discourse.__widget_helpers = {}; Discourse.__widget_helpers = {};
window.__DISCOURSE_RAW_TEMPLATES = {};
Discourse.SiteSettings = Wizard.SiteSettings; Discourse.SiteSettings = Wizard.SiteSettings;

Datei anzeigen

@ -117,6 +117,7 @@
//= require discourse/app/templates/emoji-selector-autocomplete //= require discourse/app/templates/emoji-selector-autocomplete
//= require discourse/app/templates/user-selector-autocomplete //= require discourse/app/templates/user-selector-autocomplete
//= require discourse/app/initializers/jquery-plugins
//= require discourse/app/pre-initializers/sniff-capabilities //= require discourse/app/pre-initializers/sniff-capabilities
//= require ember-addons/decorator-alias //= require ember-addons/decorator-alias

Datei anzeigen

@ -8,25 +8,31 @@ Discourse.unofficial_plugins.each do |plugin|
files = [] files = []
plugin.each_globbed_asset do |f, is_dir| plugin.each_globbed_asset do |f, is_dir|
files.push(f) if f.include? "raw.hbs" files.push(f) if f.include? "hbr"
end end
Dir.glob("#{Rails.root}/app/assets/javascripts/discourse/templates/*.raw.hbs").each do |f| Dir.glob("#{Rails.root}/app/assets/javascripts/discourse/app/templates/*.hbr").each do |f|
files.push(f) files.push(f)
end end
files.each do |f| files.each do |f|
name = File.basename(f, ".raw.hbs") name = File.basename(f, ".hbr")
compiled = Barber::Precompiler.new().compile(File.read(f)) compiled = Barber::Precompiler.new().compile(File.read(f))
result << " result << "
(function() { (function() {
if ('Wizard' in window) { const { addRawTemplate } = requirejs('discourse-common/lib/raw-templates');
window.__DISCOURSE_RAW_TEMPLATES['javascripts/#{name}'] = requirejs('discourse-common/lib/raw-handlebars').template(#{compiled}); addRawTemplate(#{compiled});
} })();
"
end
result << "
(function() {
const rawTemplates = requirejs('discourse-common/lib/raw-templates');
window.__DISCOURSE_RAW_TEMPLATES = rawTemplates.__DISCOURSE_RAW_TEMPLATES;
})(); })();
" "
end end
end end
end
result result
%> %>

Datei anzeigen

@ -3,7 +3,11 @@ import { default as computed, on } from "discourse-common/utils/decorators";
import { findRawTemplate } from "discourse-common/lib/raw-templates"; import { findRawTemplate } from "discourse-common/lib/raw-templates";
import { throttle } from "@ember/runloop"; import { throttle } from "@ember/runloop";
import { scheduleOnce } from "@ember/runloop"; import { scheduleOnce } from "@ember/runloop";
import { safariHacksDisabled } from "discourse/lib/utilities"; import {
safariHacksDisabled,
caretPosition,
inCodeBlock,
} from "discourse/lib/utilities";
import highlightSyntax from "discourse/lib/highlight-syntax"; import highlightSyntax from "discourse/lib/highlight-syntax";
import { getToken } from "wizard/lib/ajax"; import { getToken } from "wizard/lib/ajax";
import { validateUploadedFiles } from "discourse/lib/uploads"; import { validateUploadedFiles } from "discourse/lib/uploads";
@ -29,14 +33,18 @@ export default ComposerEditor.extend({
const $preview = $(this.element.querySelector(".d-editor-preview-wrapper")); const $preview = $(this.element.querySelector(".d-editor-preview-wrapper"));
if (this.siteSettings.enable_mentions) { if (this.siteSettings.enable_mentions) {
console.log('initializing autocomplete', findRawTemplate("user-selector-autocomplete"))
$input.autocomplete({ $input.autocomplete({
template: findRawTemplate("user-selector-autocomplete"), template: findRawTemplate("user-selector-autocomplete"),
dataSource: (term) => this.userSearchTerm.call(this, term), dataSource: (term) => this.userSearchTerm.call(this, term),
key: "@", key: "@",
transformComplete: (v) => v.username || v.name, transformComplete: (v) => v.username || v.name,
afterComplete() { afterComplete: (value) => {
this.composer.set("reply", value);
scheduleOnce("afterRender", () => $input.blur().focus()); scheduleOnce("afterRender", () => $input.blur().focus());
}, },
triggerRule: (textarea) =>
!inCodeBlock(textarea.value, caretPosition(textarea))
}); });
} }

Datei anzeigen

@ -10,7 +10,8 @@
<%= preload_script "ember_jquery" %> <%= preload_script "ember_jquery" %>
<%= preload_script "wizard-vendor" %> <%= preload_script "wizard-vendor" %>
<%= preload_script "wizard-application" %> <%= preload_script "wizard-application" %>
<%= preload_script "wizard-custom-lib" %> <%= preload_script "wizard-custom-globals" %>
<%= preload_script "wizard-raw-templates" %>
<%= preload_script "wizard-custom" %> <%= preload_script "wizard-custom" %>
<%= preload_script "wizard-plugin" %> <%= preload_script "wizard-plugin" %>
<%= preload_script "pretty-text-bundle" %> <%= preload_script "pretty-text-bundle" %>
@ -41,7 +42,6 @@
<%- if current_user %> <%- if current_user %>
<%= preload_script 'wizard-custom-start' %> <%= preload_script 'wizard-custom-start' %>
<%= preload_script 'wizard-raw-templates' %>
<%- else %> <%- else %>
<%= preload_script 'wizard-custom-guest' %> <%= preload_script 'wizard-custom-guest' %>
<%- end %> <%- end %>