diff options
author | ThibG <thib@sitedethib.com> | 2020-06-09 13:00:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-09 13:00:24 +0200 |
commit | 3287a10fe9658a6c370431a925abc50d4f68ea08 (patch) | |
tree | 88a408a943aa421a6ba844d309f673150cd92434 /lib | |
parent | f328f2faa3fbdb182921366c6a20e745c069b840 (diff) | |
parent | e9d7ca7645fc37534df1222e8d7ab8f3d533b852 (diff) |
Merge pull request #1350 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/paperclip/blurhash_transcoder.rb | 2 | ||||
-rw-r--r-- | lib/tasks/emojis.rake | 44 | ||||
-rw-r--r-- | lib/tasks/mastodon.rake | 7 |
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!' |