about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2020-06-09 10:39:20 +0200
committerThibaut Girka <thib@sitedethib.com>2020-06-09 10:39:20 +0200
commit12c8ac9e1443d352eca3538ed1558de8ccdd9434 (patch)
treeed480d77b29f0d571ad219190288bde3b0c09b32 /lib
parentf328f2faa3fbdb182921366c6a20e745c069b840 (diff)
parent89f40b6c3ec525b09d02f21e9b45276084167d8d (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
- `app/controllers/activitypub/collections_controller.rb`:
  Conflict due to glitch-soc having to take care of local-only
  pinned toots in that controller.
  Took upstream's changes and restored the local-only special
  handling.
- `app/controllers/auth/sessions_controller.rb`:
  Minor conflicts due to the theming system, applied upstream
  changes, adapted the following two files for glitch-soc's
  theming system:
  - `app/controllers/concerns/sign_in_token_authentication_concern.rb`
  - `app/controllers/concerns/two_factor_authentication_concern.rb`
- `app/services/backup_service.rb`:
  Minor conflict due to glitch-soc having to handle local-only
  toots specially. Applied upstream changes and restored
  the local-only special handling.
- `app/views/admin/custom_emojis/index.html.haml`:
  Minor conflict due to the theming system.
- `package.json`:
  Upstream dependency updated, too close to a glitch-soc-only
  dependency in the file.
- `yarn.lock`:
  Upstream dependency updated, too close to a glitch-soc-only
  dependency in the file.
Diffstat (limited to 'lib')
-rw-r--r--lib/paperclip/blurhash_transcoder.rb2
-rw-r--r--lib/tasks/emojis.rake44
-rw-r--r--lib/tasks/mastodon.rake7
3 files changed, 47 insertions, 6 deletions
diff --git a/lib/paperclip/blurhash_transcoder.rb b/lib/paperclip/blurhash_transcoder.rb
index 5c33c98b0..1c3a6df02 100644
--- a/lib/paperclip/blurhash_transcoder.rb
+++ b/lib/paperclip/blurhash_transcoder.rb
@@ -3,7 +3,7 @@
 module Paperclip
   class BlurhashTranscoder < Paperclip::Processor
     def make
-      return @file unless options[:style] == :small
+      return @file unless options[:style] == :small || options[:blurhash]
 
       pixels   = convert(':source RGB:-', source: File.expand_path(@file.path)).unpack('C*')
       geometry = options.fetch(:file_geometry_parser).from_file(@file)
diff --git a/lib/tasks/emojis.rake b/lib/tasks/emojis.rake
index 70919fbdb..0e7921ffc 100644
--- a/lib/tasks/emojis.rake
+++ b/lib/tasks/emojis.rake
@@ -1,5 +1,35 @@
 # frozen_string_literal: true
 
+def gen_border(codepoint)
+  input = Rails.root.join('public', 'emoji', "#{codepoint}.svg")
+  dest = Rails.root.join('public', 'emoji', "#{codepoint}_border.svg")
+  doc = File.open(input) { |f| Nokogiri::XML(f) }
+  svg = doc.at_css('svg')
+  if svg.key?('viewBox')
+    view_box = svg['viewBox'].split(' ').map(&:to_i)
+    view_box[0] -= 2
+    view_box[1] -= 2
+    view_box[2] += 4
+    view_box[3] += 4
+    svg['viewBox'] = view_box.join(' ')
+  end
+  g = Nokogiri::XML::Node.new 'g', doc
+  doc.css('svg > *').each do |elem|
+    border_elem = elem.dup
+
+    border_elem.delete('fill')
+
+    border_elem['stroke'] = 'white'
+    border_elem['stroke-linejoin'] = 'round'
+    border_elem['stroke-width'] = '4px'
+
+    g.add_child(border_elem)
+  end
+  svg.prepend_child(g)
+  File.write(dest, doc.to_xml)
+  puts "Wrote bordered #{codepoint}.svg to #{dest}!"
+end
+
 def codepoints_to_filename(codepoints)
   codepoints.downcase.gsub(/\A[0]+/, '').tr(' ', '-')
 end
@@ -23,8 +53,10 @@ namespace :emojis do
 
     HTTP.get(source).to_s.split("\n").each do |line|
       next if line.start_with? '#'
+
       parts = line.split(';').map(&:strip)
       next if parts.size < 2
+
       codes << [parts[0], parts[1].start_with?('fully-qualified')]
     end
 
@@ -55,4 +87,16 @@ namespace :emojis do
     File.write(dest, Oj.dump(map))
     puts "Wrote emojo to destination! (#{dest})"
   end
+
+  desc 'Generate emoji variants with white borders'
+  task :generate_borders do
+    src = Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_map.json')
+    emojis = '🎱🐜⚫🖤⬛◼️◾◼️✒️▪️💣🎳📷📸♣️🕶️✴️🔌💂‍♀️📽️🍳🦍💂🔪🕳️🕹️🕋🖊️🖋️💂‍♂️🎤🎓🎥🎼♠️🎩🦃📼📹🎮🐃🏴👽⚾🐔☁️💨🕊️👀🍥👻🐐❕❔⛸️🌩️🔊🔇📃🌧️🐏🍚🍙🐓🐑💀☠️🌨️🔉🔈💬💭🏐🏳️⚪⬜◽◻️▫️'
+
+    map = Oj.load(File.read(src))
+
+    emojis.each_grapheme_cluster do |emoji|
+      gen_border map[emoji]
+    end
+  end
 end
diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake
index a873335d4..9e80989ef 100644
--- a/lib/tasks/mastodon.rake
+++ b/lib/tasks/mastodon.rake
@@ -1,6 +1,5 @@
 # frozen_string_literal: true
 
-require 'tty-command'
 require 'tty-prompt'
 
 namespace :mastodon do
@@ -334,8 +333,6 @@ namespace :mastodon do
       prompt.say 'This configuration will be written to .env.production'
 
       if prompt.yes?('Save configuration?')
-        cmd = TTY::Command.new(printer: :quiet)
-
         env_contents = env.each_pair.map do |key, value|
           if value.is_a?(String) && value =~ /[\s\#\\"]/
             if value =~ /[']/
@@ -367,7 +364,7 @@ namespace :mastodon do
           prompt.say 'Running `RAILS_ENV=production rails db:setup` ...'
           prompt.say "\n\n"
 
-          if cmd.run!({ RAILS_ENV: 'production', SAFETY_ASSURED: 1 }, :rails, 'db:setup').failure?
+          if !system(env.transform_values(&:to_s).merge({ 'RAILS_ENV' => 'production', 'SAFETY_ASSURED' => '1' }), 'rails db:setup')
             prompt.error 'That failed! Perhaps your configuration is not right'
           else
             prompt.ok 'Done!'
@@ -382,7 +379,7 @@ namespace :mastodon do
           prompt.say 'Running `RAILS_ENV=production rails assets:precompile` ...'
           prompt.say "\n\n"
 
-          if cmd.run!({ RAILS_ENV: 'production' }, :rails, 'assets:precompile').failure?
+          if !system(env.transform_values(&:to_s).merge({ 'RAILS_ENV' => 'production' }), 'rails assets:precompile')
             prompt.error 'That failed! Maybe you need swap space?'
           else
             prompt.say 'Done!'