discourse_theme 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +21 -0
- data/README.md +3 -3
- data/discourse_theme.gemspec +1 -1
- data/lib/discourse_theme/cli.rb +23 -1
- data/lib/discourse_theme/client.rb +15 -14
- data/lib/discourse_theme/config.rb +8 -0
- data/lib/discourse_theme/uploader.rb +3 -2
- data/lib/discourse_theme/version.rb +2 -1
- data/lib/discourse_theme/watcher.rb +9 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de1cb65ed52d9dd44bbe0039b0a40f00f55897e68106d5193cfb0717937b4ff9
|
4
|
+
data.tar.gz: 8192308474973266925422876401c974c3daf0ffb331d7423ac06d2368c3db68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dcbaf4918cf88082c27270a05e1fb888d5d2e462160834c7a2b82ab79acfb3eaf62d0732ea5da840f83d1656f36d6aadda4633cdec86b77149d57c5188c0514
|
7
|
+
data.tar.gz: 3c095bcfcc224691d30405353a06eb6ccf64446331175dc28e7f8eebf1347b8b2707c37313e1c29668a35937a4a550c8ef81bc2701201674a5baf8b525d72211
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
tags:
|
8
|
+
- v*
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
publish:
|
12
|
+
if: contains(github.ref, 'refs/tags/v')
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
|
18
|
+
- name: Release Gem
|
19
|
+
uses: CvX/publish-rubygems-action@master
|
20
|
+
env:
|
21
|
+
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Discourse Theme
|
2
2
|
|
3
|
-
This CLI contains helpers for creating [Discourse themes](https://meta.discourse.org/c/theme).
|
3
|
+
This CLI contains helpers for creating [Discourse themes](https://meta.discourse.org/c/theme) and theme components.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -10,7 +10,7 @@ To install the CLI use:
|
|
10
10
|
|
11
11
|
## Why this gem exists?
|
12
12
|
|
13
|
-
This gem allows you to use your editor of choice when developing Discourse themes. As you save files the CLI will update the remote theme and changes to it will appear live!
|
13
|
+
This gem 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!
|
14
14
|
|
15
15
|
## Usage
|
16
16
|
|
@@ -24,7 +24,7 @@ it contains two helpers:
|
|
24
24
|
|
25
25
|
You can use `discourse_theme new PATH` to crate a new blank theme, the CLI will guide you through the process.
|
26
26
|
|
27
|
-
You can use `discourse_theme watch PATH` to monitor your theme for changes, when changed the program will synchronize the theme to your Discourse of choice.
|
27
|
+
You can use `discourse_theme watch PATH` to monitor your theme or component for changes, when changed the program will synchronize the theme or component to your Discourse of choice.
|
28
28
|
|
29
29
|
## Contributing
|
30
30
|
|
data/discourse_theme.gemspec
CHANGED
data/lib/discourse_theme/cli.rb
CHANGED
@@ -57,6 +57,7 @@ module DiscourseTheme
|
|
57
57
|
settings = config[dir]
|
58
58
|
|
59
59
|
theme_id = settings.theme_id
|
60
|
+
components = settings.components
|
60
61
|
|
61
62
|
if command == "new"
|
62
63
|
raise DiscourseTheme::ThemeError.new "'#{dir} is not empty" if Dir.exists?(dir) && !Dir.empty?(dir)
|
@@ -87,14 +88,35 @@ module DiscourseTheme
|
|
87
88
|
themes = render_theme_list(theme_list)
|
88
89
|
choice = Cli.select('Which theme would you like to sync with?', themes)
|
89
90
|
theme_id = extract_theme_id(choice)
|
91
|
+
theme = theme_list.find { |t| t["id"] == theme_id }
|
90
92
|
end
|
91
93
|
|
92
|
-
|
94
|
+
about_json = JSON.parse(File.read(File.join(dir, 'about.json'))) rescue nil
|
95
|
+
already_uploaded = !!theme
|
96
|
+
is_component = theme&.[]("component")
|
97
|
+
component_count = about_json&.[]("components")&.length || 0
|
98
|
+
|
99
|
+
if !already_uploaded && !is_component && component_count > 0
|
100
|
+
options = {}
|
101
|
+
options["Yes"] = :sync
|
102
|
+
options["No"] = :none
|
103
|
+
options = options.sort_by { |_, b| b == components.to_sym ? 0 : 1 }.to_h if components
|
104
|
+
choice = Cli.select('Would you like to update child theme components?', options.keys)
|
105
|
+
settings.components = components = options[choice].to_s
|
106
|
+
end
|
107
|
+
|
108
|
+
uploader = DiscourseTheme::Uploader.new(dir: dir, client: client, theme_id: theme_id, components: components)
|
93
109
|
|
94
110
|
Cli.progress "Uploading theme from #{dir}"
|
95
111
|
settings.theme_id = theme_id = uploader.upload_full_theme
|
96
112
|
|
97
113
|
Cli.success "Theme uploaded (id:#{theme_id})"
|
114
|
+
Cli.info "Preview: #{client.root}/?preview_theme_id=#{theme_id}"
|
115
|
+
if client.is_theme_creator
|
116
|
+
Cli.info "Manage: #{client.root}/my/themes"
|
117
|
+
else
|
118
|
+
Cli.info "Manage: #{client.root}/admin/customize/themes/#{theme_id}"
|
119
|
+
end
|
98
120
|
watcher = DiscourseTheme::Watcher.new(dir: dir, uploader: uploader)
|
99
121
|
|
100
122
|
Cli.progress "Watching for changes in #{dir}..."
|
@@ -44,7 +44,7 @@ module DiscourseTheme
|
|
44
44
|
if @is_theme_creator
|
45
45
|
"/user_themes.json"
|
46
46
|
else
|
47
|
-
"/admin/customize/themes.json
|
47
|
+
"/admin/customize/themes.json"
|
48
48
|
end
|
49
49
|
|
50
50
|
response = request(Net::HTTP::Get.new(endpoint), never_404: true)
|
@@ -57,7 +57,7 @@ module DiscourseTheme
|
|
57
57
|
if @is_theme_creator
|
58
58
|
"/user_themes/#{id}/export"
|
59
59
|
else
|
60
|
-
"/admin/customize/themes/#{id}/export
|
60
|
+
"/admin/customize/themes/#{id}/export"
|
61
61
|
end
|
62
62
|
|
63
63
|
response = request(Net::HTTP::Get.new endpoint)
|
@@ -71,7 +71,7 @@ module DiscourseTheme
|
|
71
71
|
if @is_theme_creator
|
72
72
|
"/user_themes/#{id}"
|
73
73
|
else
|
74
|
-
"/admin/themes/#{id}
|
74
|
+
"/admin/themes/#{id}"
|
75
75
|
end
|
76
76
|
|
77
77
|
put = Net::HTTP::Put.new(endpoint, 'Content-Type' => 'application/json')
|
@@ -79,41 +79,40 @@ module DiscourseTheme
|
|
79
79
|
request(put)
|
80
80
|
end
|
81
81
|
|
82
|
-
def upload_full_theme(tgz, theme_id:)
|
82
|
+
def upload_full_theme(tgz, theme_id:, components:)
|
83
83
|
endpoint = root +
|
84
84
|
if @is_theme_creator
|
85
85
|
"/user_themes/import.json"
|
86
86
|
else
|
87
|
-
"/admin/themes/import.json
|
87
|
+
"/admin/themes/import.json"
|
88
88
|
end
|
89
89
|
|
90
90
|
post = Net::HTTP::Post::Multipart.new(
|
91
91
|
endpoint,
|
92
92
|
"theme_id" => theme_id,
|
93
|
+
"components" => components,
|
93
94
|
"bundle" => UploadIO.new(tgz, "application/tar+gzip", "bundle.tar.gz")
|
94
95
|
)
|
95
96
|
request(post)
|
96
97
|
end
|
97
98
|
|
98
99
|
def discourse_version
|
99
|
-
endpoint = root
|
100
|
-
if @is_theme_creator
|
101
|
-
"/about.json"
|
102
|
-
else
|
103
|
-
"/about.json?api_key=#{@api_key}"
|
104
|
-
end
|
105
|
-
|
100
|
+
endpoint = "#{root}/about.json"
|
106
101
|
response = request(Net::HTTP::Get.new(endpoint), never_404: true)
|
107
102
|
json = JSON.parse(response.body)
|
108
103
|
json["about"]["version"]
|
109
104
|
end
|
110
105
|
|
111
|
-
private
|
112
|
-
|
113
106
|
def root
|
114
107
|
@url
|
115
108
|
end
|
116
109
|
|
110
|
+
def is_theme_creator
|
111
|
+
@is_theme_creator
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
117
116
|
def request(request, never_404: false)
|
118
117
|
uri = URI.parse(@url)
|
119
118
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -134,6 +133,8 @@ module DiscourseTheme
|
|
134
133
|
def add_headers(request)
|
135
134
|
if @is_theme_creator
|
136
135
|
request["User-Api-Key"] = @api_key
|
136
|
+
else
|
137
|
+
request["Api-Key"] = @api_key
|
137
138
|
end
|
138
139
|
end
|
139
140
|
|
@@ -3,10 +3,11 @@ module DiscourseTheme
|
|
3
3
|
|
4
4
|
THEME_CREATOR_REGEX = /^https:\/\/theme-creator.discourse.org$/i
|
5
5
|
|
6
|
-
def initialize(dir:, client:, theme_id: nil)
|
6
|
+
def initialize(dir:, client:, theme_id: nil, components: nil)
|
7
7
|
@dir = dir
|
8
8
|
@client = client
|
9
9
|
@theme_id = theme_id
|
10
|
+
@components = components
|
10
11
|
end
|
11
12
|
|
12
13
|
def compress_dir(gzip, dir)
|
@@ -66,7 +67,7 @@ module DiscourseTheme
|
|
66
67
|
compress_dir(filename, @dir)
|
67
68
|
|
68
69
|
File.open(filename) do |tgz|
|
69
|
-
response = @client.upload_full_theme(tgz, theme_id: @theme_id)
|
70
|
+
response = @client.upload_full_theme(tgz, theme_id: @theme_id, components: @components)
|
70
71
|
|
71
72
|
json = JSON.parse(response.body)
|
72
73
|
@theme_id = json["theme"]["id"]
|
@@ -1,5 +1,13 @@
|
|
1
1
|
module DiscourseTheme
|
2
2
|
class Watcher
|
3
|
+
def self.return_immediately!
|
4
|
+
@return_immediately = true
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.return_immediately?
|
8
|
+
!!@return_immediately
|
9
|
+
end
|
10
|
+
|
3
11
|
def initialize(dir:, uploader:)
|
4
12
|
@dir = dir
|
5
13
|
@uploader = uploader
|
@@ -40,7 +48,7 @@ module DiscourseTheme
|
|
40
48
|
end
|
41
49
|
|
42
50
|
listener.start
|
43
|
-
sleep
|
51
|
+
sleep unless self.class.return_immediately?
|
44
52
|
end
|
45
53
|
|
46
54
|
protected
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discourse_theme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -172,6 +172,7 @@ executables:
|
|
172
172
|
extensions: []
|
173
173
|
extra_rdoc_files: []
|
174
174
|
files:
|
175
|
+
- ".github/workflows/ci.yml"
|
175
176
|
- ".gitignore"
|
176
177
|
- ".rubocop.yml"
|
177
178
|
- ".travis.yml"
|
@@ -204,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
204
205
|
requirements:
|
205
206
|
- - ">="
|
206
207
|
- !ruby/object:Gem::Version
|
207
|
-
version: 2.
|
208
|
+
version: 2.6.0
|
208
209
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
210
|
requirements:
|
210
211
|
- - ">="
|