Hmmmm. That’s a tricky one, because the symlink needed to be deleted, otherwise the Docker mount fails (as it cannot overwrite the existing file).
I had a bit of a google around for solutions, and found an interesting solution which would dereference the symlink and copy the symlink’s target into the specified directory, but couldn’t find anything that would create a Docker volume mount, thus preserving the dynamic link and bi-directional synchronisation. Happy to be steered towards a solution as this would be a neat feature to have.
Dev_Work
(Aleksandr)
2019 年12 月 26 日 08:31
111
请告诉我如何将您的验证添加到 app/models/user.rb 模型中?
validates_presence_of :username
validate :username_validator, if: :will_save_change_to_username?
validate :password_validator
validate :name_validator, if: :will_save_change_to_name?
validates :name, user_full_name: true, if: :will_save_change_to_name?, length: { maximum: 255 }
validates :ip_address, allowed_ip_address: { on: :create, message: :signup_not_allowed }
validates :primary_email, presence: true
validates_associated :primary_email, message: -> (_, user_email) { user_email[:value]&.errors[:email]&.first }
after_initialize :add_trust_level
before_validation :set_skip_validate_email
1 个赞
eviltrout
(Robin Ward)
2019 年12 月 27 日 14:15
112
您可以在 plugin.rb 中使用常规 Ruby 代码来实现此功能:
class ::User < ActiveRecord::Base
validates_presence_of :your_attribute
end
6 个赞
AstonJ
(AstonJ)
2020 年1 月 29 日 03:25
113
刚开始开发我的第一个小插件 我有几个问题,希望能有人帮忙解答…
eviltrout:
2018 年 8 月更新 ,请查看 Rails 插件生成器 ,在您的插件目录中快速创建完整的 Discourse 插件骨架
第一个问题是:我们是应该使用本指南中的内容,还是真的应该使用插件生成器?
本指南中未涵盖这一点,但我们如何从 plugin.rb 文件中将数据提供给模板?
例如,假设我想在用户访问主题时,于插件出口 topic-above-posts 显示一条随机欢迎消息,该消息从 plugin.rb 中的一个数组里随机选取……我该如何将数据发送到模板?我推测模板文件也应该放在这里:
plugins/my_new_plugin/assets/javascripts/discourse/templates/connectors/topic-above-posts/my_new_plugin.hbs(这样对吗?)
非常感谢您的任何建议
2 个赞
eviltrout
(Robin Ward)
2020 年1 月 29 日 15:42
114
使用插件生成器通常是入门并了解插件应如何构建的绝佳方式。我推荐使用它。
现在,关于如何将 Ruby 代码集成到前端:这是两个不同的应用程序。前端应用(Ember)需要通过某种方式从服务器(Rails)请求数据。通常我们通过 AJAX 调用来实现这一点,但你也可以选择在 SiteSerializer 中添加内容,使其作为论坛数据的一部分自动发送。
否则,你需要查阅如何在 Rails 中添加路由和控制器,并将消息以 JSON 格式发送。
8 个赞
AstonJ
(AstonJ)
2020 年1 月 29 日 19:24
115
谢谢 Robin!
您是否知道有关这方面的教程?或者,有没有一个简单的插件(甚至是一个示例插件)可以参考,能给我们指明正确的方向?(如果没有,您能否方便地为我们发布一个?我想这会帮助很多人 )
另外,关于写书您还有什么想法吗?如果您有兴趣,我可以帮您联系相关人员
1 个赞
eviltrout
(Robin Ward)
2020 年1 月 30 日 15:06
116
谢谢你的夸奖,但我确实太忙了,没法考虑写书。而且技术类书籍的受众非常有限。我认识的那些写过书的人都说,写书是为了自己,不是为了赚钱:slight_smile:
我想不出一个简单的插件能从服务器端返回内容。discourse-tooltips 添加了一个路由,然后利用它来获取主题的预览,当你将鼠标悬停在上面时就会显示,这或许会有所帮助。
8 个赞
neounix
(Dark Matter)
2020 年3 月 19 日 14:37
118
很快,我将开始插件开发……
问题:
是否有我们可以实际插入 plugin 的 hooks 列表?
例如,假设我们想编写一个插件,在帖子显示之前处理 cooked 数据,我们期望至少有一个开始 hook 和一个结束 hook,例如:
display_post_start
display_post_complex
然后,我们的 plugin 将在上述我们选择的 hook location 处 hook 到代码中。
是否有这些 plugin hooks 的列表?在 DiscourseWorld 中这些 plugin hooks 被称为什么?
更新:找到了这个:
git grep "plugin-outlet" -- "*.hbs"
但我没看到用于修改 cooked 帖子内容的 outlet。
是否有关于创建自定义 outlet 的教程?例如,用于修改帖子 cooked 部分的 outlet?
2 个赞
riking
(Kane York)
2020 年3 月 19 日 18:11
119
您正在寻找本指南的 decorateCooked() 部分:
Discourse 主题(Themes)和主题组件(Theme Components)可用于自定义 Discourse 前端的观感和功能。本开发者指南部分旨在提供您所需的所有参考资料,以便开发简单的单站点主题,直至复杂的开源主题组件。
本介绍旨在提供主题开发所有工具和 API 的概览。如果您更喜欢主题开发的循序渐进教程,请直接跳转至:
主题与主题组件
Discourse 主题 可用于使用 CSS 和 JavaScript 自定义前端用户体验。每个主题都有自己的 Git 仓库,社区管理员通常可以通过 Discourse 管理面板安装和管理它们,即使在共享主机平台上也是如此。
主题组件 是旨在与其他主题组件一起作为整体主题一部分的主题。从开发角度来看,主题组件和主题几乎是相同的。在本指南中,“主题”和“主题组件”一词可互换使用。
先决条件
首先,请确保您了解 如何在 Discourse 中使用现有主题和主题组件 。使用现成的(ready-made)主题是定制社区最快、最安全的方法。如果您需要更多功能,那么就该考虑编写自己的主题了。
作为 Discourse 整体架构 的一部分,…
5 个赞
我为自定义插件使用了这个骨架。我需要为即将到来的 Ember 5 过渡做任何更改吗?
Discourse will soon be upgrading our version of the Ember Javascript framework from version 3 to version 5. The vast majority of the preparation work is done, and many sites are already running on Ember 5 (including Meta!).
This upgrade is available behind a feature flag right now! This is the default for self-hosted Discourse installations starting 10th January. Initially, Ember 3 support will remain available via a flag, but will be removed within the first quarter of 2024.
On our ma…
我猜不用?虽然这只是一个 linter?
{
"name": "discourse-plugin-name",
"version": "0.0.1",
"repository": "TODO",
"author": "Discourse",
"license": "MIT",
"devDependencies": {
"@discourse/lint-configs": "^1.2.0",
"ember-template-lint": "^5.13.0",
"eslint": "^8.54.0",
"prettier": "^2.8.8"
}
}
1 个赞
david
(David Taylor)
2023 年12 月 8 日 10:18
134
该骨架与 Ember 5 兼容。但如果您添加了任何 JavaScript 代码或 hbs 模板,则需要按照公告中的说明检查弃用情况。
AquaL1te:
虽然这只是一个 linter?
是的,package.json 中的内容仅与 linting 相关,它不会影响插件的功能或兼容性。
3 个赞
pfaffman
(Jay Pfaffman)
2024 年9 月 24 日 18:11
136
请添加到这个
rake plugin:create[plugin-name]
我今天花了太长时间才找到 Automating Discourse Plugin Setup with `create-discourse-plugin` gem (不知道为什么我记不起这是 rake 任务的名称?! )
5 个赞
我也想在 Docker 设置中添加一个注释,因为上面的说明在尝试创建插件时会因类似以下错误而失败:
ambientimpact:~/.../Discourse/discourse$ d/rake plugin:create[neurocracy-date-rewrite]
Cloning 'https://github.com/discourse/discourse-plugin-skeleton' to '/src/plugins/neurocracy-date-rewrite'...
Initializing git repository...
Initialized empty Git repository in /src/plugins/neurocracy-date-rewrite/.git/
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: empty ident name (for <discourse@localhost>) not allowed
rake aborted!
Command failed with exit 128: git
/src/lib/tasks/plugin.rake:354:in `system'
/src/lib/tasks/plugin.rake:354:in `block (2 levels) in <main>'
/src/lib/tasks/plugin.rake:344:in `chdir'
/src/lib/tasks/plugin.rake:344:in `block in <main>'
Tasks: TOP => plugin:create
(See full trace by running task with --trace)
在尝试创建插件之前,您需要先在容器中设置您的 .gitconfig(根据需要更改电子邮件和姓名):
d/exec git config --global user.email "you@example.com"
d/exec git config --global user.name "Your Name"
d/rake plugin:create[plugin-name]
1 个赞