discourse_theme 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd8c45032d2c2499afcecc28d16ccee1fa98e8b2652080ab47736a900fa44d33
4
- data.tar.gz: c4524cebcdfa477449c5419511ca9e39e8008b01cb6fef210705ffa851097ed8
3
+ metadata.gz: eda4efafe48fc1beeff142e2688d5c51faa2b5dd1d77baff286d19efb984d3a2
4
+ data.tar.gz: bcd2ad344cd37b116f7e499c941679256e48fa3dd95f82f8a51cd374de1f8168
5
5
  SHA512:
6
- metadata.gz: a2670a5a54f209ed6819d5692dd492e7286110939a0add8dfc1b0510d9a25c1c4d619bcb2b9443ccb993e8c137073f53a673ea911ecef1f32058eca75b83119d
7
- data.tar.gz: b51ae8876fbfbec7d49ea62246b76b40971eb25ed71b0aba631a9ec080c2e835f23eb1ae9795495820e6c755ddf54a24db9c03e4bb830e71b6fdde0c346827e7
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
- parts = discourse_version.split(".").map { |s| s.sub('beta', '').to_i }
16
- if parts[0] < 2 || parts[1] < 2 || parts[2] < 0 || (!parts[3].nil? && parts[3] < 10)
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
- class DiscourseTheme::Uploader
1
+ module DiscourseTheme
2
+ class Uploader
2
3
 
3
- THEME_CREATOR_REGEX = /^https:\/\/theme-creator.discourse.org$/i
4
+ THEME_CREATOR_REGEX = /^https:\/\/theme-creator.discourse.org$/i
4
5
 
5
- def initialize(dir:, client:, theme_id: nil)
6
- @dir = dir
7
- @client = client
8
- @theme_id = theme_id
9
- end
6
+ def initialize(dir:, client:, theme_id: nil)
7
+ @dir = dir
8
+ @client = client
9
+ @theme_id = theme_id
10
+ end
10
11
 
11
- def compress_dir(gzip, dir)
12
- sgz = Zlib::GzipWriter.new(File.open(gzip, 'wb'))
13
- tar = Archive::Tar::Minitar::Output.new(sgz)
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
- Dir.chdir(dir + "/../") do
16
- Find.find(File.basename(dir)) do |x|
17
- Find.prune if File.basename(x) == "src"
18
- Find.prune if File.basename(x)[0] == ?.
19
- next if File.directory?(x)
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
- Minitar.pack_file(x, tar)
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
- def diagnose_errors(json)
30
- count = 0
31
- json["theme"]["theme_fields"].each do |row|
32
- if (error = row["error"]) && error.length > 0
33
- if count == 0
34
- puts
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
- def upload_theme_field(target: , name: , type_id: , value:)
46
- raise "expecting theme_id to be set!" unless @theme_id
43
+ def upload_theme_field(target: , name: , type_id: , value:)
44
+ raise "expecting theme_id to be set!" unless @theme_id
47
45
 
48
- args = {
49
- theme: {
50
- theme_fields: [{
51
- name: name,
52
- target: target,
53
- type_id: type_id,
54
- value: value
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
- response = @client.update_theme(@theme_id, args)
60
- json = JSON.parse(response.body)
61
- if diagnose_errors(json) != 0
62
- Cli.error "(end of errors)"
63
- end
64
- end
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
- def upload_full_theme
67
- filename = "#{Pathname.new(Dir.tmpdir).realpath}/bundle_#{SecureRandom.hex}.tar.gz"
68
- compress_dir(filename, @dir)
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
- File.open(filename) do |tgz|
71
- response = @client.upload_full_theme(tgz, theme_id: @theme_id)
68
+ File.open(filename) do |tgz|
69
+ response = @client.upload_full_theme(tgz, theme_id: @theme_id)
72
70
 
73
- json = JSON.parse(response.body)
74
- @theme_id = json["theme"]["id"]
75
- if diagnose_errors(json) != 0
76
- Cli.error "(end of errors)"
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
- @theme_id
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
@@ -1,3 +1,3 @@
1
1
  module DiscourseTheme
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  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.1
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-04 00:00:00.000000000 Z
11
+ date: 2019-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler