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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c652f5407703115888ee2c75b3e1caf69b1aa526fcaf124ab54a0024fc471fcf
4
- data.tar.gz: ee147aaef2475063959ba39f3025bc27257dc9dd5bd4f4d89b89dde0e4bcb4ed
3
+ metadata.gz: 5277924c1a14b59cf66cc403616680f3c980743c657a3cd7613d6236f3c1073e
4
+ data.tar.gz: 2fee23e13d30c6401ce95d6519f5fe98390002a1829c4bdc7b7bad1cc98493e0
5
5
  SHA512:
6
- metadata.gz: 225b2d921edf71526a2b552dedfa5e5ace15cba32f4ab050d3ba5d4f22efe8fc156d597af1e92afabe63671f66357af9618e37f2a7d7ac5f29d515ee52469656
7
- data.tar.gz: 75fbb8dd55a4effd2c99938bb76f6ad38ea4e687bc8461297146036cc9f4d2ef30d408260d963ab5fc175edd73e8e55e668c9c83c02a96a8a46ae70c9daf6607
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
 
@@ -36,5 +36,5 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "tty-prompt", "~> 0.18"
37
37
  spec.add_dependency "rubyzip", "~> 1.2"
38
38
 
39
- spec.required_ruby_version = '>= 2.2.0'
39
+ spec.required_ruby_version = '>= 2.6.0'
40
40
  end
@@ -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
- uploader = DiscourseTheme::Uploader.new(dir: dir, client: client, theme_id: theme_id)
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?api_key=#{@api_key}"
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?api_key=#{@api_key}"
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}?api_key=#{@api_key}"
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?api_key=#{@api_key}"
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
 
@@ -30,6 +30,14 @@ class DiscourseTheme::Config
30
30
  set("theme_id", theme_id.to_i)
31
31
  end
32
32
 
33
+ def components
34
+ safe_config["components"]
35
+ end
36
+
37
+ def components=(val)
38
+ set("components", val)
39
+ end
40
+
33
41
  protected
34
42
 
35
43
  def set(name, val)
@@ -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
- Find.prune if File.basename(x) == "src"
19
- Find.prune if File.basename(x)[0] == ?.
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"]
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DiscourseTheme
2
- VERSION = "0.3.0"
3
+ VERSION = "0.3.5"
3
4
  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.3.0
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: 2019-07-28 00:00:00.000000000 Z
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.2.0
208
+ version: 2.6.0
208
209
  required_rubygems_version: !ruby/object:Gem::Requirement
209
210
  requirements:
210
211
  - - ">="