Canapin
(Coin-coin le Canapin)
17 Settembre 2020, 1:46pm
1
Hi!
I’d like to try to modify the buildQuote function so it adds a new line before the opening [quote] tag.
Basically, modifying this:
return `[quote="${params.join(", ")}"]\n${contents.trim()}\n[/quote]\n\n`;
to this:
return `\n[quote="${params.join(", ")}"]\n${contents.trim()}\n[/quote]\n\n`;
Is it possible to do such a thing with a theme component? How do I override this function?
Canapin
(Coin-coin le Canapin)
17 Settembre 2020, 4:03pm
2
I’ve managed to achieve it, but is there a prettier solution?
<script type="text/discourse-plugin" version="0.8.23">
function buildQuote(post, contents, opts = {}) {
if (!post || !contents) {
return "";
}
const params = [
opts.username || post.username,
`post:${opts.post || post.post_number}`,
`topic:${opts.topic || post.topic_id}`
];
if (opts.full) params.push("full:true");
return `\n[quote="${params.join(", ")}"]\n${contents.trim()}\n[/quote]\n\n`;
}
api.modifyClass('controller:composer', {
actions: {
importQuote(toolbarEvent) {
const postStream = this.get("topic.postStream");
let postId = this.get("model.post.id");
// If there is no current post, use the first post id from the stream
if (!postId && postStream) {
postId = postStream.get("stream.firstObject");
}
// If we're editing a post, fetch the reply when importing a quote
if (this.get("model.editingPost")) {
const replyToPostNumber = this.get("model.post.reply_to_post_number");
if (replyToPostNumber) {
const replyPost = postStream.posts.findBy(
"post_number",
replyToPostNumber
);
if (replyPost) {
postId = replyPost.id;
}
}
}
if (postId) {
this.set("model.loading", true);
return this.store.find("post", postId).then(post => {
const quote = buildQuote(post, post.raw, {
full: true
});
toolbarEvent.addText(quote);
this.set("model.loading", false);
});
}
}
}
});
</script>
2 Mi Piace
asc
27 Febbraio 2023, 11:10pm
3
Mi dispiace per aver riaperto un vecchio argomento, ma funziona ancora per te/hai dovuto aggiornarlo? Sto cercando di farlo funzionare e non riesco a farlo partire affatto, ma ho avuto un brutto periodo con qualsiasi cosa abbia a che fare con modifyClass.
Canapin
(Coin-coin le Canapin)
28 Febbraio 2023, 8:05am
4
L’ho appena provato e funziona ancora
L’ho letteralmente copiato e incollato nel mio tema e ha funzionato senza alcuna modifica.
1 Mi Piace
merefield
(Robert)
28 Febbraio 2023, 8:42am
5
2 Mi Piace
asc
28 Febbraio 2023, 2:10pm
6
Grazie @merefield e @Canapin . Stavo cercando di imparare l’API dei plugin di Discourse armeggiando con quelle che mi sembravano cose semplici come questa, ma modifyClass è così incoerente quando funziona e quando non funziona. Ho un piccolo componente tema (quello in cui sei stato menzionato @merefield ) in cui due chiamate a modifyClass funzionano ma una terza no, è molto frustrante cercare di capire se ho sbagliato qualcosa io o se è solo modifyClass.
Scusa per l’OT sul tuo argomento e grazie per la rapida risposta @Canapin .
Aggiornamento:
1 Mi Piace
Canapin
(Coin-coin le Canapin)
28 Febbraio 2023, 2:16pm
7
Non preoccuparti, non so cosa significhi OT ma siamo qui per aiutarti!
1 Mi Piace
Canapin
(Coin-coin le Canapin)
Chiuso
30 Marzo 2023, 2:16pm
8
Questo argomento è stato chiuso automaticamente 30 giorni dopo l’ultima risposta. Non sono più consentite nuove risposte.