Canapin
(Coin-coin le Canapin)
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)
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
asc
3
古いトピックをぶつけて申し訳ありませんが、これはまだ機能していますか/何か更新する必要がありましたか? 私はこれを機能させようとしていますが、まったく機能させることができません。しかし、modifyClass に関してはひどい時間を過ごしています。
Canapin
(Coin-coin le Canapin)
4
試してみましたが、まだ機能しています 
テーマにそのままコピー&ペーストしましたが、変更なしで機能しました。
「いいね!」 1
asc
6
@merefield と @Canapin 、ありがとうございます。Discourse プラグイン API を学習しようとして、単純なはずのことに手間取っています。modifyClass は、いつ機能し、いつ機能しないのかが非常に一貫性がありません。私が作成した小さなテーマコンポーネント(@merefield が言及していたもの)では、2 つの modifyClass 呼び出しは機能しますが、3 つ目は機能しません。自分が何か間違っているのか、それとも単に modifyClass の問題なのかを理解しようとすると、非常にイライラします。
トピックから逸れてすみません。そして、@Canapin 、迅速な返信ありがとうございます。
更新:
「いいね!」 1
Canapin
(Coin-coin le Canapin)
7
気にしないでください。OTが何を意味するのかは分かりませんが、お手伝いします!
「いいね!」 1
Canapin
(Coin-coin le Canapin)
クローズされました:
8
このトピックは、最後の返信から30日後に自動的にクローズされました。新しい返信は許可されていません。