discourse_theme 0.3.0 → 0.3.5
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 +12 -1
- data/lib/discourse_theme/client.rb +9 -12
- data/lib/discourse_theme/config.rb +8 -0
- data/lib/discourse_theme/uploader.rb +5 -4
- data/lib/discourse_theme/version.rb +2 -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: 5277924c1a14b59cf66cc403616680f3c980743c657a3cd7613d6236f3c1073e
|
4
|
+
data.tar.gz: 2fee23e13d30c6401ce95d6519f5fe98390002a1829c4bdc7b7bad1cc98493e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1323a77a6cd64fb095def5d735b673ad9be3cd9f7c55d6a3a2bb3eb8842024a0055926a650f64ea1ddac46656f8de32266b3dc205cafe0904f781ce7d69eade6
|
7
|
+
data.tar.gz: a24107efa821c1ab3b3c387aef80152c0ee13b675a3261aa2efc38e86ccc3e37f29e5e4f058d50a1e98dc36249082f0ed57d7bc1458c385b7701898b915d3d2e
|
@@ -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,9 +88,19 @@ 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
|
+
if !theme || theme["component"] == false
|
95
|
+
options = {}
|
96
|
+
options["Yes"] = :sync
|
97
|
+
options["No"] = :none
|
98
|
+
options = options.sort_by { |_, b| b == components.to_sym ? 0 : 1 }.to_h if components
|
99
|
+
choice = Cli.select('Would you like to update child theme components?', options.keys)
|
100
|
+
settings.components = components = options[choice].to_s
|
101
|
+
end
|
102
|
+
|
103
|
+
uploader = DiscourseTheme::Uploader.new(dir: dir, client: client, theme_id: theme_id, components: components)
|
93
104
|
|
94
105
|
Cli.progress "Uploading theme from #{dir}"
|
95
106
|
settings.theme_id = theme_id = uploader.upload_full_theme
|
@@ -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,30 +79,25 @@ 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"]
|
@@ -134,6 +129,8 @@ module DiscourseTheme
|
|
134
129
|
def add_headers(request)
|
135
130
|
if @is_theme_creator
|
136
131
|
request["User-Api-Key"] = @api_key
|
132
|
+
else
|
133
|
+
request["Api-Key"] = @api_key
|
137
134
|
end
|
138
135
|
end
|
139
136
|
|
@@ -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)
|
@@ -15,8 +16,8 @@ module DiscourseTheme
|
|
15
16
|
|
16
17
|
Dir.chdir(dir + "/../") do
|
17
18
|
Find.find(File.basename(dir)) do |x|
|
18
|
-
|
19
|
-
Find.prune if
|
19
|
+
bn = File.basename(x)
|
20
|
+
Find.prune if bn == "node_modules" || bn == "src" || bn[0] == ?.
|
20
21
|
next if File.directory?(x)
|
21
22
|
|
22
23
|
Minitar.pack_file(x, tar)
|
@@ -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"]
|
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.3.
|
4
|
+
version: 0.3.5
|
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-06-10 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
|
- - ">="
|