FEATURE: Support additional metadata in theme about.json (#6944)

New `about.json` fields (all optional):
 - `authors`: An arbitrary string describing the theme authors
 - `theme_version`: An arbitrary string describing the theme version
 - `minimum_discourse_version`: Theme will be auto-disabled for lower versions. Must be a valid version descriptor.
 - `maximum_discourse_version`: Theme will be auto-disabled for lower versions. Must be a valid version descriptor.

A localized description for a theme can be provided in the language files under the `theme_metadata.description` key

The admin UI has been re-arranged to display this new information, and give more prominence to the remote theme options.
This commit is contained in:
David Taylor
2019-01-25 14:19:01 +00:00
committed by GitHub
parent 2d6aa2aea2
commit a48731e359
16 changed files with 261 additions and 149 deletions

View File

@ -3,6 +3,14 @@ require_dependency 'theme_store/tgz_importer'
require_dependency 'upload_creator'
class RemoteTheme < ActiveRecord::Base
METADATA_PROPERTIES = %i{
license_url
about_url
authors
theme_version
minimum_discourse_version
maximum_discourse_version
}
class ImportError < StandardError; end
@ -16,6 +24,8 @@ class RemoteTheme < ActiveRecord::Base
joins("JOIN themes ON themes.remote_theme_id = remote_themes.id").where.not(remote_url: "")
}
validates_format_of :minimum_discourse_version, :maximum_discourse_version, with: Discourse::VERSION_REGEXP, allow_nil: true
def self.extract_theme_info(importer)
JSON.parse(importer["about.json"])
rescue TypeError, JSON::ParserError
@ -123,8 +133,12 @@ class RemoteTheme < ActiveRecord::Base
end
end
self.license_url = theme_info["license_url"]
self.about_url = theme_info["about_url"]
METADATA_PROPERTIES.each do |property|
self.public_send(:"#{property}=", theme_info[property.to_s])
end
if !self.valid?
raise ImportError, I18n.t("themes.import_error.about_json_values", errors: self.errors.full_messages.join(","))
end
importer.all_files.each do |filename|
next unless opts = ThemeField.opts_from_file_path(filename)