discourse_theme 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/discourse_theme/client.rb +23 -3
- data/lib/discourse_theme/uploader.rb +61 -62
- data/lib/discourse_theme/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eda4efafe48fc1beeff142e2688d5c51faa2b5dd1d77baff286d19efb984d3a2
|
4
|
+
data.tar.gz: bcd2ad344cd37b116f7e499c941679256e48fa3dd95f82f8a51cd374de1f8168
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b466e0a9d50fcd6476645a6093e454d7bb2b6add37810c14f7ad40034e9877bc771afb7f4699b8058b61c9b1dd34c4ace50ed83e5ab10851b2b66d69ee026b0
|
7
|
+
data.tar.gz: d87e7931724b2b74a9d6a6bef786522edc564e5cbe727ab578bdc43d99d7ab52bc4cca20a76fc7a07f03c40cf1394f3853078342451c9981b9b4aa6bc4ec4043
|
@@ -12,13 +12,33 @@ module DiscourseTheme
|
|
12
12
|
|
13
13
|
@is_theme_creator = !!(THEME_CREATOR_REGEX =~ @url)
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
Cli.info "discourse_theme is designed for Discourse 2.2.0.beta10 or above"
|
15
|
+
if !self.class.has_needed_version?(discourse_version, "2.3.0.beta1")
|
16
|
+
Cli.info "discourse_theme is designed for Discourse 2.3.0.beta1 or above"
|
18
17
|
Cli.info "download will not function, and syncing destination will be unpredictable"
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
21
|
+
# From https://github.com/discourse/discourse/blob/master/lib/version.rb
|
22
|
+
def self.has_needed_version?(current, needed)
|
23
|
+
current_split = current.split('.')
|
24
|
+
needed_split = needed.split('.')
|
25
|
+
|
26
|
+
(0..[current_split.size, needed_split.size].max).each do |idx|
|
27
|
+
current_str = current_split[idx] || ''
|
28
|
+
|
29
|
+
c0 = (needed_split[idx] || '').sub('beta', '').to_i
|
30
|
+
c1 = (current_str || '').sub('beta', '').to_i
|
31
|
+
|
32
|
+
# beta is less than stable
|
33
|
+
return false if current_str.include?('beta') && (c0 == 0) && (c1 > 0)
|
34
|
+
|
35
|
+
return true if c1 > c0
|
36
|
+
return false if c0 > c1
|
37
|
+
end
|
38
|
+
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
22
42
|
def get_themes_list
|
23
43
|
endpoint = root +
|
24
44
|
if @is_theme_creator
|
@@ -1,84 +1,83 @@
|
|
1
|
-
|
1
|
+
module DiscourseTheme
|
2
|
+
class Uploader
|
2
3
|
|
3
|
-
|
4
|
+
THEME_CREATOR_REGEX = /^https:\/\/theme-creator.discourse.org$/i
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def initialize(dir:, client:, theme_id: nil)
|
7
|
+
@dir = dir
|
8
|
+
@client = client
|
9
|
+
@theme_id = theme_id
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def compress_dir(gzip, dir)
|
13
|
+
sgz = Zlib::GzipWriter.new(File.open(gzip, 'wb'))
|
14
|
+
tar = Archive::Tar::Minitar::Output.new(sgz)
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
Dir.chdir(dir + "/../") do
|
17
|
+
Find.find(File.basename(dir)) do |x|
|
18
|
+
Find.prune if File.basename(x) == "src"
|
19
|
+
Find.prune if File.basename(x)[0] == ?.
|
20
|
+
next if File.directory?(x)
|
20
21
|
|
21
|
-
|
22
|
+
Minitar.pack_file(x, tar)
|
23
|
+
end
|
22
24
|
end
|
25
|
+
ensure
|
26
|
+
tar.close
|
27
|
+
sgz.close
|
23
28
|
end
|
24
|
-
ensure
|
25
|
-
tar.close
|
26
|
-
sgz.close
|
27
|
-
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
def diagnose_errors(json)
|
31
|
+
count = 0
|
32
|
+
json["theme"]["theme_fields"].each do |row|
|
33
|
+
if (error = row["error"]) && error.length > 0
|
34
|
+
count += 1
|
35
|
+
Cli.error ""
|
36
|
+
Cli.error "Error in #{row["target"]} #{row["name"]}: #{row["error"]}"
|
37
|
+
Cli.error ""
|
35
38
|
end
|
36
|
-
count += 1
|
37
|
-
Cli.error
|
38
|
-
Cli.error "Error in #{row["target"]} #{row["name"]}: #{row["error"]}"
|
39
|
-
Cli.error
|
40
39
|
end
|
40
|
+
count
|
41
41
|
end
|
42
|
-
count
|
43
|
-
end
|
44
42
|
|
45
|
-
|
46
|
-
|
43
|
+
def upload_theme_field(target: , name: , type_id: , value:)
|
44
|
+
raise "expecting theme_id to be set!" unless @theme_id
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
46
|
+
args = {
|
47
|
+
theme: {
|
48
|
+
theme_fields: [{
|
49
|
+
name: name,
|
50
|
+
target: target,
|
51
|
+
type_id: type_id,
|
52
|
+
value: value
|
53
|
+
}]
|
54
|
+
}
|
56
55
|
}
|
57
|
-
}
|
58
56
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
57
|
+
response = @client.update_theme(@theme_id, args)
|
58
|
+
json = JSON.parse(response.body)
|
59
|
+
if diagnose_errors(json) != 0
|
60
|
+
Cli.error "(end of errors)"
|
61
|
+
end
|
62
|
+
end
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
def upload_full_theme
|
65
|
+
filename = "#{Pathname.new(Dir.tmpdir).realpath}/bundle_#{SecureRandom.hex}.tar.gz"
|
66
|
+
compress_dir(filename, @dir)
|
69
67
|
|
70
|
-
|
71
|
-
|
68
|
+
File.open(filename) do |tgz|
|
69
|
+
response = @client.upload_full_theme(tgz, theme_id: @theme_id)
|
72
70
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
71
|
+
json = JSON.parse(response.body)
|
72
|
+
@theme_id = json["theme"]["id"]
|
73
|
+
if diagnose_errors(json) != 0
|
74
|
+
Cli.error "(end of errors)"
|
75
|
+
end
|
76
|
+
@theme_id
|
77
77
|
end
|
78
|
-
|
78
|
+
ensure
|
79
|
+
FileUtils.rm_f filename
|
79
80
|
end
|
80
|
-
ensure
|
81
|
-
FileUtils.rm_f filename
|
82
|
-
end
|
83
81
|
|
82
|
+
end
|
84
83
|
end
|
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|