-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
f96c7d8
commit ecab2e7
Showing
1 changed file
with
21 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,41 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
# Ask immediately to avoid "lag" | ||
print 'Describe your changes: ' | ||
reason = gets.chomp | ||
|
||
require 'bundler/setup' | ||
require 'dotenv' | ||
require 'redd' | ||
require 'sass' | ||
|
||
# Load environment variables | ||
Dotenv.load | ||
|
||
options = {} | ||
if ENV['SUBREDDIT'].casecmp('redd').zero? | ||
options['readers-word'] = '"programmers"' | ||
options['page-accent-color'] = '#B10DC9' | ||
end | ||
# Get the main file and its contents | ||
path = File.join(__dir__, '../theme/main.scss') | ||
scss = File.read(path) | ||
options.each { |option, value| scss.prepend("$#{option}: #{value};\n") } | ||
|
||
# Subreddit specific tweaks | ||
case ENV['SUBREDDIT'].downcase | ||
when 'redd' | ||
scss.prepend <<-EOF | ||
$readers-word: "programmers"; | ||
$page-accent-color: #B10DC9; | ||
EOF | ||
end | ||
|
||
# Parse SCSS into CSS | ||
begin | ||
parsed = Sass::Engine.new(scss, syntax: :scss, filename: path).render | ||
rescue Sass::SyntaxError => e | ||
puts e.message | ||
exit 1 | ||
end | ||
|
||
subreddit = Redd.it( | ||
user_agent: 'Redd:Theme Publisher:v0.1.0 (by /u/Mustermind)', | ||
client_id: ENV.fetch('CLIENT_ID'), | ||
secret: ENV.fetch('SECRET'), | ||
username: ENV.fetch('USERNAME'), | ||
password: ENV.fetch('PASSWORD') | ||
).subreddit(ENV.fetch('SUBREDDIT')) | ||
|
||
subreddit.update_stylesheet(parsed, reason: reason) | ||
# Login and upload the stylesheet | ||
Redd | ||
.it(user_agent: 'Redd:Theme Publisher:v0.1.0 (by /u/Mustermind)', | ||
client_id: ENV.fetch('CLIENT_ID'), | ||
secret: ENV.fetch('SECRET'), | ||
username: ENV.fetch('USERNAME'), | ||
password: ENV.fetch('PASSWORD')) | ||
.subreddit(ENV.fetch('SUBREDDIT')) | ||
.update_stylesheet(parsed) |