discourse_theme 0.3.2 → 0.3.3

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: 1ef711d0d73bc44d77980d883fd0ae32ce4cf14a71aa28f8e1d81ec0ec6f077b
4
- data.tar.gz: b63d4ce664f8c5243fc413d3eba9222502b52565d5f183b8154f747955ee1ded
3
+ metadata.gz: ed19147c8208315a736b690c90e072986604c9c4fd7c10b05b42dc7dfeb8b400
4
+ data.tar.gz: 75553d2685a0ee8c3083c73e11d449a6bedefc36b6212b432cd488b8882cbb1a
5
5
  SHA512:
6
- metadata.gz: 5c5af4afa4206257a58e3957533c47c5205454e465def3377e193fd46bb672882b5e761285e16394c0253ba873802c39072c213fabaeab4d658ad777f8b805ee
7
- data.tar.gz: 4e1872e14d330163a2bd23316d66593f5786e00e99689546ef3196513b066638d94ccec1519117e99e097e1b9f6534932da2f291837ebe105476765f738b2007
6
+ metadata.gz: 59603310b69ea2702828ac5a79ef74da0d091dfbd5cf7d5184b8f1943198a72446b9ebbcd243f9f05d6f89ea7de192f7f49c9a434cc4d95bff51a4794f1a286e
7
+ data.tar.gz: a45dc46ff96d8bd1a9fcffb6d4757e38908bd8e43e4a9e641c32c3458061ccfc15bc3855c65026c2b13fbff0b3e9b90f53c9243c80511c7c51a3877c7a9d02e2
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
 
@@ -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,20 @@ 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["Add missing but leave all extra components as is"] = :add
97
+ options["Add missing and remove superfluous"] = :sync
98
+ options["Do nothing"] = :none
99
+ options = options.sort_by { |_, b| b == components.to_sym ? 0 : 1 }.to_h if components
100
+ choice = Cli.select('How would you like to update child theme components?', options.keys)
101
+ settings.components = components = options[choice].to_s
102
+ end
103
+
104
+ uploader = DiscourseTheme::Uploader.new(dir: dir, client: client, theme_id: theme_id, components: components)
93
105
 
94
106
  Cli.progress "Uploading theme from #{dir}"
95
107
  settings.theme_id = theme_id = uploader.upload_full_theme
@@ -79,7 +79,7 @@ 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"
@@ -90,6 +90,7 @@ module DiscourseTheme
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)
@@ -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)
@@ -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.2"
3
+ VERSION = "0.3.3"
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.2
4
+ version: 0.3.3
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-11-14 00:00:00.000000000 Z
11
+ date: 2020-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler