discourse_theme 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +10 -0
- data/bin/discourse_theme +5 -0
- data/discourse_theme.gemspec +35 -0
- data/lib/discourse_theme.rb +21 -0
- data/lib/discourse_theme/cli.rb +112 -0
- data/lib/discourse_theme/scaffold.rb +74 -0
- data/lib/discourse_theme/uploader.rb +108 -0
- data/lib/discourse_theme/version.rb +3 -0
- data/lib/discourse_theme/watcher.rb +53 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f39560cfe4f927edff0919dc9c325d0288982107
|
4
|
+
data.tar.gz: ad749d7d12462e0eb5b217a1bab3ad19e0398e72
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c4cc9c5149385f35616b8f0f6aade9320b1eb2fdb0c77fb3d8dcc4fe457301ee9a7082d3e90b28ecc553cc3b07fa74c67729780946ad0de76ede02474b2a48e
|
7
|
+
data.tar.gz: 538a23533f1e9eebaad4a1decd9e388bfd782c4d0c38e49072eaf98d18b8392c82c93511bf18a206de904c18d44e43fcd937ff877af65b53acc2723c8fd9e367
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at sam.saffron@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Civilized Discourse Construction Kit
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Discourse Theme
|
2
|
+
|
3
|
+
This CLI contains helpers for creating [Discourse themes](https://meta.discourse.org/c/theme).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
To install the CLI use:
|
8
|
+
|
9
|
+
$ gem install discourse_theme
|
10
|
+
|
11
|
+
## Why this gem exists?
|
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!
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
For help run:
|
18
|
+
|
19
|
+
```
|
20
|
+
discourse_theme
|
21
|
+
```
|
22
|
+
|
23
|
+
it contains two helpers:
|
24
|
+
|
25
|
+
You can use `discourse_theme new PATH` to crate a new blank theme, the CLI will guide you through the process.
|
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.
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome at [Meta Discourse](https://meta.discourse.org). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
36
|
+
|
37
|
+
## Code of Conduct
|
38
|
+
|
39
|
+
Everyone interacting in the DiscourseTheme project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/SamSaffron/discourse_theme/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/discourse_theme
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "discourse_theme/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "discourse_theme"
|
9
|
+
spec.version = DiscourseTheme::VERSION
|
10
|
+
spec.authors = ["Sam Saffron"]
|
11
|
+
spec.email = ["sam.saffron@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{CLI helper for creating Discourse themes}
|
14
|
+
spec.description = %q{CLI helper for creating Discourse themes}
|
15
|
+
spec.homepage = "https://github.com/discourse/discourse_theme"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.bindir = "bin"
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
29
|
+
|
30
|
+
spec.add_dependency "minitar", "~> 0.5"
|
31
|
+
spec.add_dependency "listen", "~> 3.1"
|
32
|
+
spec.add_dependency "multipart-post", "~> 2.0"
|
33
|
+
|
34
|
+
spec.required_ruby_version = '>= 2.2.0'
|
35
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'pathname'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'securerandom'
|
5
|
+
require 'minitar'
|
6
|
+
require 'zlib'
|
7
|
+
require 'find'
|
8
|
+
require 'net/http'
|
9
|
+
require 'net/http/post/multipart'
|
10
|
+
require 'uri'
|
11
|
+
require 'listen'
|
12
|
+
require 'json'
|
13
|
+
|
14
|
+
require 'discourse_theme/version'
|
15
|
+
require 'discourse_theme/cli'
|
16
|
+
require 'discourse_theme/uploader'
|
17
|
+
require 'discourse_theme/watcher'
|
18
|
+
require 'discourse_theme/scaffold'
|
19
|
+
|
20
|
+
module DiscourseTheme
|
21
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
class DiscourseTheme::Cli
|
2
|
+
|
3
|
+
WATCHER_SETTINGS_FILE = File.expand_path("~/.discourse-theme-watcher")
|
4
|
+
|
5
|
+
def usage
|
6
|
+
puts "Usage: discourse-theme COMMAND"
|
7
|
+
puts
|
8
|
+
puts "discourse-theme new DIR : Creates a new theme in the designated directory"
|
9
|
+
puts "discourse-theme watch DIR : Watches the theme directory and synchronizes with Discourse"
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
|
13
|
+
def guess_api_key
|
14
|
+
api_key = ENV['DISCOURSE_API_KEY']
|
15
|
+
if api_key
|
16
|
+
puts "Using api_key provided by DISCOURSE_API_KEY"
|
17
|
+
end
|
18
|
+
|
19
|
+
if !api_key && File.exist?(WATCHER_SETTINGS_FILE)
|
20
|
+
api_key = File.read(WATCHER_SETTINGS_FILE).strip
|
21
|
+
puts "Using previously stored api key in #{WATCHER_SETTINGS_FILE}"
|
22
|
+
end
|
23
|
+
|
24
|
+
if !api_key
|
25
|
+
puts "No API key found in DISCOURSE_API_KEY env var enter your API key: "
|
26
|
+
api_key = STDIN.gets.strip
|
27
|
+
puts "Would you like me to store this API key in #{WATCHER_SETTINGS_FILE}? (Yes|No)"
|
28
|
+
answer = STDIN.gets.strip
|
29
|
+
if answer =~ /y(es)?/i
|
30
|
+
File.write WATCHER_SETTINGS_FILE, api_key
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
api_key
|
35
|
+
end
|
36
|
+
|
37
|
+
def guess_site(dir)
|
38
|
+
site = ENV['DISCOURSE_SITE']
|
39
|
+
if site
|
40
|
+
puts "Site provided by DISCOURSE_SITE"
|
41
|
+
end
|
42
|
+
|
43
|
+
site_conf = dir + "/.discourse-site"
|
44
|
+
|
45
|
+
if !site && File.exist?(site_conf)
|
46
|
+
site = File.read(site_conf).strip
|
47
|
+
puts "Using #{site} defined in #{site_conf}"
|
48
|
+
end
|
49
|
+
|
50
|
+
if !site
|
51
|
+
puts "No site found, where would you like to synchronize the theme to: "
|
52
|
+
site = STDIN.gets.strip
|
53
|
+
puts "Would you like me to store this site name at: #{site_conf}? (Yes|No)"
|
54
|
+
answer = STDIN.gets.strip
|
55
|
+
if answer =~ /y(es)?/i
|
56
|
+
File.write site_conf, site
|
57
|
+
# got to make sure this is in .gitignore
|
58
|
+
|
59
|
+
gitignore = File.read(dir + "/.gitignore") rescue ""
|
60
|
+
if gitignore !~ /^.discourse-site/
|
61
|
+
gitignore.strip!
|
62
|
+
gitignore += "\n.discourse-site"
|
63
|
+
File.write(dir + '/.gitignore', gitignore)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
site
|
69
|
+
end
|
70
|
+
|
71
|
+
def run
|
72
|
+
usage unless ARGV[1]
|
73
|
+
|
74
|
+
command = ARGV[0].to_s.downcase
|
75
|
+
dir = File.expand_path(ARGV[1])
|
76
|
+
|
77
|
+
dir_exists = File.exist?(dir)
|
78
|
+
|
79
|
+
if command == "new" && !dir_exists
|
80
|
+
DiscourseTheme::Scaffold.generate(dir)
|
81
|
+
elsif command == "watch" && dir_exists
|
82
|
+
if !File.exist?("#{dir}/about.json")
|
83
|
+
puts "No about.json file found in #{dir}!"
|
84
|
+
puts
|
85
|
+
usage
|
86
|
+
end
|
87
|
+
|
88
|
+
api_key = guess_api_key
|
89
|
+
site = guess_site(dir)
|
90
|
+
|
91
|
+
if !site
|
92
|
+
puts "Missing site!"
|
93
|
+
usage
|
94
|
+
end
|
95
|
+
|
96
|
+
if !api_key
|
97
|
+
puts "Missing api key!"
|
98
|
+
usage
|
99
|
+
end
|
100
|
+
|
101
|
+
uploader = DiscourseTheme::Uploader.new(dir: dir, api_key: api_key, site: site)
|
102
|
+
print "Uploading theme from #{dir} to #{site} : "
|
103
|
+
uploader.upload_full_theme
|
104
|
+
|
105
|
+
watcher = DiscourseTheme::Watcher.new(dir: dir, uploader: uploader)
|
106
|
+
|
107
|
+
watcher.watch
|
108
|
+
else
|
109
|
+
usage
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
class DiscourseTheme::Scaffold
|
2
|
+
|
3
|
+
BLANK_FILES = %w{
|
4
|
+
common/common.scss
|
5
|
+
common/header.html
|
6
|
+
common/after_header.html
|
7
|
+
common/footer.html
|
8
|
+
common/head_tag.html
|
9
|
+
common/body_tag.html
|
10
|
+
common/embedded.scss
|
11
|
+
|
12
|
+
desktop/desktop.scss
|
13
|
+
desktop/header.html
|
14
|
+
desktop/after_header.html
|
15
|
+
desktop/footer.html
|
16
|
+
desktop/head_tag.html
|
17
|
+
desktop/body_tag.html
|
18
|
+
|
19
|
+
mobile/mobile.scss
|
20
|
+
mobile/header.html
|
21
|
+
mobile/after_header.html
|
22
|
+
mobile/footer.html
|
23
|
+
mobile/head_tag.html
|
24
|
+
mobile/body_tag.html
|
25
|
+
}
|
26
|
+
|
27
|
+
ABOUT_JSON = <<~STR
|
28
|
+
{
|
29
|
+
"name": "#NAME#",
|
30
|
+
"about_url": "URL",
|
31
|
+
"license_url": "URL",
|
32
|
+
"assets": {
|
33
|
+
},
|
34
|
+
"color_schemes": {
|
35
|
+
}
|
36
|
+
}
|
37
|
+
STR
|
38
|
+
|
39
|
+
HELP = <<~STR
|
40
|
+
Are you a bit lost? Be sure to read https://meta.discourse.org/t/how-to-develop-custom-themes/60848
|
41
|
+
STR
|
42
|
+
|
43
|
+
GIT_IGNORE = <<~STR
|
44
|
+
.discourse-site
|
45
|
+
HELP
|
46
|
+
STR
|
47
|
+
|
48
|
+
def self.generate(dir)
|
49
|
+
puts "Generating a scaffold theme at #{dir}"
|
50
|
+
|
51
|
+
puts "What would you like to call your theme? "
|
52
|
+
name = STDIN.gets.strip
|
53
|
+
if name.length == 0
|
54
|
+
puts "Please pick a name"
|
55
|
+
exit 1
|
56
|
+
end
|
57
|
+
|
58
|
+
FileUtils.mkdir_p dir
|
59
|
+
Dir.chdir dir do
|
60
|
+
File.write('about.json', ABOUT_JSON.sub("#NAME#", name))
|
61
|
+
File.write('HELP', HELP)
|
62
|
+
File.write('.gitignore', GIT_IGNORE)
|
63
|
+
|
64
|
+
BLANK_FILES.each do |f|
|
65
|
+
puts "#{f}"
|
66
|
+
FileUtils.mkdir_p File.dirname(f)
|
67
|
+
FileUtils.touch f
|
68
|
+
end
|
69
|
+
|
70
|
+
puts "Initializing git repo"
|
71
|
+
puts `git init .`
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
class DiscourseTheme::Uploader
|
2
|
+
|
3
|
+
def initialize(dir:, api_key:, site:)
|
4
|
+
@dir = dir
|
5
|
+
@api_key = api_key
|
6
|
+
@site = site
|
7
|
+
@theme_id = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def compress_dir(gzip, dir)
|
11
|
+
sgz = Zlib::GzipWriter.new(File.open(gzip, 'wb'))
|
12
|
+
tar = Archive::Tar::Minitar::Output.new(sgz)
|
13
|
+
|
14
|
+
Dir.chdir(dir + "/../") do
|
15
|
+
Find.find(File.basename(dir)) do |x|
|
16
|
+
Find.prune if File.basename(x)[0] == ?.
|
17
|
+
next if File.directory?(x)
|
18
|
+
|
19
|
+
Minitar.pack_file(x, tar)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
ensure
|
23
|
+
tar.close
|
24
|
+
sgz.close
|
25
|
+
end
|
26
|
+
|
27
|
+
def diagnose_errors(json)
|
28
|
+
count = 0
|
29
|
+
json["theme"]["theme_fields"].each do |row|
|
30
|
+
if (error = row["error"]) && error.length > 0
|
31
|
+
if count == 0
|
32
|
+
puts
|
33
|
+
end
|
34
|
+
count += 1
|
35
|
+
puts
|
36
|
+
puts "Error in #{row["target"]} #{row["name"]}: #{row["error"]}"
|
37
|
+
puts
|
38
|
+
end
|
39
|
+
end
|
40
|
+
count
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def upload_theme_field(target: , name: , type_id: , value:)
|
45
|
+
|
46
|
+
raise "expecting theme_id to be set!" unless @theme_id
|
47
|
+
|
48
|
+
args = {
|
49
|
+
theme: {
|
50
|
+
theme_fields: [{
|
51
|
+
name: name,
|
52
|
+
target: target,
|
53
|
+
type_id: type_id,
|
54
|
+
value: value
|
55
|
+
}]
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
uri = URI.parse(@site + "/admin/themes/#{@theme_id}?api_key=#{@api_key}")
|
60
|
+
|
61
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
62
|
+
request = Net::HTTP::Put.new(uri.request_uri, 'Content-Type' => 'application/json')
|
63
|
+
request.body = args.to_json
|
64
|
+
|
65
|
+
http.start do |h|
|
66
|
+
response = h.request(request)
|
67
|
+
if response.code.to_i == 200
|
68
|
+
json = JSON.parse(response.body)
|
69
|
+
if diagnose_errors(json) == 0
|
70
|
+
puts "(done)"
|
71
|
+
end
|
72
|
+
else
|
73
|
+
puts "Error importing field status: #{response.code}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def upload_full_theme
|
79
|
+
filename = "#{Pathname.new(Dir.tmpdir).realpath}/bundle_#{SecureRandom.hex}.tar.gz"
|
80
|
+
compress_dir(filename, @dir)
|
81
|
+
|
82
|
+
# new full upload endpoint
|
83
|
+
uri = URI.parse(@site + "/admin/themes/import.json?api_key=#{@api_key}")
|
84
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
85
|
+
File.open(filename) do |tgz|
|
86
|
+
|
87
|
+
request = Net::HTTP::Post::Multipart.new(
|
88
|
+
uri.request_uri,
|
89
|
+
"bundle" => UploadIO.new(tgz, "application/tar+gzip", "bundle.tar.gz"),
|
90
|
+
)
|
91
|
+
response = http.request(request)
|
92
|
+
if response.code.to_i == 201
|
93
|
+
json = JSON.parse(response.body)
|
94
|
+
@theme_id = json["theme"]["id"]
|
95
|
+
if diagnose_errors(json) == 0
|
96
|
+
puts "(done)"
|
97
|
+
end
|
98
|
+
else
|
99
|
+
puts "Error importing theme status: #{response.code}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
ensure
|
104
|
+
FileUtils.rm_f filename
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class DiscourseTheme::Watcher
|
2
|
+
def initialize(dir:, uploader:)
|
3
|
+
@dir = dir
|
4
|
+
@uploader = uploader
|
5
|
+
end
|
6
|
+
|
7
|
+
def watch
|
8
|
+
listener = Listen.to(@dir) do |modified, added, removed|
|
9
|
+
if modified.length == 1 &&
|
10
|
+
added.length == 0 &&
|
11
|
+
removed.length == 0 &&
|
12
|
+
(resolved = resolve_file(modified[0]))
|
13
|
+
|
14
|
+
target, name, type_id = resolved
|
15
|
+
print "Updating #{target} #{name}: "
|
16
|
+
|
17
|
+
@uploader.upload_theme_field(
|
18
|
+
target: target,
|
19
|
+
name: name,
|
20
|
+
value: File.read(modified[0]),
|
21
|
+
type_id: type_id
|
22
|
+
)
|
23
|
+
else
|
24
|
+
print "Full re-sync is required, re-uploading theme: "
|
25
|
+
@uploader.upload_full_theme
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
listener.start
|
30
|
+
sleep
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def resolve_file(path)
|
37
|
+
dir_len = File.expand_path(@dir).length
|
38
|
+
name = File.expand_path(path)[dir_len + 1..-1]
|
39
|
+
|
40
|
+
target, file = name.split("/")
|
41
|
+
|
42
|
+
if ["common", "desktop", "mobile"].include?(target)
|
43
|
+
if file = "#{target}.scss"
|
44
|
+
# a CSS file
|
45
|
+
return [target, "scss", 1]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
nil
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: discourse_theme
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam Saffron
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitar
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.5'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: listen
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: multipart-post
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
97
|
+
description: CLI helper for creating Discourse themes
|
98
|
+
email:
|
99
|
+
- sam.saffron@gmail.com
|
100
|
+
executables:
|
101
|
+
- discourse_theme
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CODE_OF_CONDUCT.md
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/discourse_theme
|
113
|
+
- discourse_theme.gemspec
|
114
|
+
- lib/discourse_theme.rb
|
115
|
+
- lib/discourse_theme/cli.rb
|
116
|
+
- lib/discourse_theme/scaffold.rb
|
117
|
+
- lib/discourse_theme/uploader.rb
|
118
|
+
- lib/discourse_theme/version.rb
|
119
|
+
- lib/discourse_theme/watcher.rb
|
120
|
+
homepage: https://github.com/discourse/discourse_theme
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 2.2.0
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.6.13
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: CLI helper for creating Discourse themes
|
144
|
+
test_files: []
|