安装 Discourse Theme CLI 控制台应用程序,帮助你构建主题

The discourse Discourse Theme CLI is a ruby gem that allows you to use your editor of choice when developing Discourse themes and theme components. As you save files the CLI will update the remote theme or component and changes to it will appear live!

Installing

To play with it, make sure you have Ruby 2.5 or up installed.

If you are on Windows, you have 2 options:

Option 1: Windows Subsystem for Linux.

Windows 10 has access to a full Linux environment, you can use it to install ruby simply with sudo apt-get install ruby, this will give you Ruby 2.3.

Options 2: Older Windows

Older versions of Windows have no access to WSL, you can easily install Ruby with Ruby Installer, go for the recommended version and default settings for the install.

Mac OS version 10.13.3 ship with Ruby 2.3 out of the box, nothing special is needed. If you are running an earlier version of Mac OS consider using rvm, rbenv or homebrew to install a recent ruby.


Once Ruby 2.2 or later is running, open a terminal or command shell and run:

gem install discourse_theme

Once installed, to learn more about it:

discourse_theme

Upgrading

gem update discourse_theme

Features

The CLI provides 3 main functions:

discourse_theme new

You can use it to quickly create a new theme with discourse_theme new YOUR_DIR_NAME

discourse_theme watch

You can use it to monitor a theme and synchronize with a discourse site (with live refresh) using discourse_theme watch YOUR_DIR_NAME

What this means is that you can use your own editor to edit you theme and site will magically :unicorn: update with the changes!

discourse_theme download

You can download an existing theme from Discourse using discourse_theme download YOUR_DIR_NAME. You will then be given the option to start “watching” straight away!

Credentials

You will need to generate an API Key. Go to the admin area and generate a key there.

  • :exclamation: Select a “User Level” of Single User when generating the key, not All Users.
  • :exclamation: Make sure to check Global Key or you will receive 403 forbidden errors.

Credentials are (optionally) stored at ~/.discourse_theme. API keys are stored per-site, and the URL/theme_id for each directory is also tracked. If you ever need to change your settings, just add --reset to any command and you will be prompted for all values again.

Testimonials

“This tool is truly a GEM!” @awole20
“This is very very good.” @awesomerobot
“It’s working :slight_smile: And it’s pretty dosh garn cool. Nice!” @angus
“OMG. It’s unbelievable.” @pfaffman


This document is version controlled - suggest changes on github.

79 个赞

Admin > Customize > Themes 中的 Uploads 在保存了已关注的主题后消失。

我们如何将图像资源包含在主题中,以便在保存后不会被清除?

2 个赞

您好,欢迎!

您需要直接在主题组件中包含资源。
在根目录,创建一个 assets 目录。
然后,在 about.json 中声明它们

"assets": {
  "<your_identifier>": "assets/<your_asset_filename>",
}

您可以在此处看到一个示例 https://github.com/MeghnaAJ/discourse-christmas-decorations。

3 个赞

使用此工具生成主题组件的开发者请注意:

建议您升级它! :+1:

最近的 PRdiscourse-theme-skeleton 仓库设为默认模板。它将为您提供最新的配置文件!

9 个赞

谢谢!

在主题中添加一个“更新”部分会很棒……

是 --reset 还是 rubygem update?

4 个赞

好主意!我已将“升级”部分添加到 OP 中

gem update discourse_theme
5 个赞

要在WSL上安装gem,我必须运行sudo apt-get install rubysudo apt-get install ruby-dev。也许可以将这些添加到安装说明中。

如果你不安装 ruby-dev,是否会收到错误?安装 ruby-dev 应该不是必需的,因为 ruby 本身就足够了。

4 个赞

我相当确定我收到了一个错误提示我安装 ruby-dev,否则我不会知道这个包的存在。
但我尝试重新安装时却无法重现它。也许第一次的时候我做了什么奇怪的操作。

2 个赞

嗯,这确实很奇怪。如果您能再次重现问题,请随时告知我。

2 个赞

我昨天已将服务器更新到 3.5.0.beta9-dev,但自此 discourse 主题 gem 不再提供实时重新加载。Gem 版本为 2.1.6。

我没有看到任何错误等信息,所以想先问问是否有人遇到同样的问题?

1 个赞

样式表的实时重新加载已在生产实例中禁用,因为它们在更新主题和/或 Discourse 核心时会导致问题。

根本原因:样式表的更改通常与 JS/HTML 的更改相关联,因此仅对样式表进行实时加载存在风险。用户最终会使用“新”样式表针对“旧” HTML 进行操作,这可能导致一些非常奇怪的体验。

实时重新加载在开发模式的 Discourse 实例中仍然启用。理想情况下,您应该在开发环境中使用它,而不是生产站点。除了样式表重新加载之外,开发模式的 Ember 比生产模式的 Ember 提供更友好的错误消息。

3 个赞

这是一个很大的改变。我很惊讶竟然没有公告。我之前主要是在生产站点上进行主题开发。

也许可以添加一个站点设置来恢复旧的行为。

4 个赞

同意,这让我很惊讶,尽管搜索了,但我找不到这个当前的主题,或者我看到了旧的 OP 日期并忽略了它。