branding.rake 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # frozen_string_literal: true
  2. namespace :branding do
  3. desc 'Generate necessary graphic assets for branding from source SVG files'
  4. task generate: :environment do
  5. Rake::Task['branding:generate_app_icons'].invoke
  6. Rake::Task['branding:generate_app_badge'].invoke
  7. Rake::Task['branding:generate_github_assets'].invoke
  8. Rake::Task['branding:generate_mailer_assets'].invoke
  9. end
  10. desc 'Generate PNG icons and logos for e-mail templates'
  11. task generate_mailer_assets: :environment do
  12. rsvg_convert = Terrapin::CommandLine.new('rsvg-convert', '-h :size --keep-aspect-ratio :input -o :output')
  13. output_dest = Rails.root.join('app', 'javascript', 'images', 'mailer')
  14. # Displayed size is 64px, at 3x it's 192px
  15. Dir[Rails.root.join('app', 'javascript', 'images', 'icons', '*.svg')].each do |path|
  16. rsvg_convert.run(input: path, size: 192, output: output_dest.join("#{File.basename(path, '.svg')}.png"))
  17. end
  18. # Displayed size is 34px, at 3x it's 102px
  19. rsvg_convert.run(input: Rails.root.join('app', 'javascript', 'images', 'logo-symbol-wordmark.svg'), size: 102, output: output_dest.join('wordmark.png'))
  20. # Displayed size is 24px, at 3x it's 72px
  21. rsvg_convert.run(input: Rails.root.join('app', 'javascript', 'images', 'logo-symbol-icon.svg'), size: 72, output: output_dest.join('logo.png'))
  22. end
  23. desc 'Generate light/dark logotypes for GitHub'
  24. task generate_github_assets: :environment do
  25. rsvg_convert = Terrapin::CommandLine.new('rsvg-convert', '--stylesheet :stylesheet -h :size --keep-aspect-ratio :input -o :output')
  26. output_dest = Rails.root.join('lib', 'assets')
  27. rsvg_convert.run(stylesheet: Rails.root.join('lib', 'assets', 'wordmark.dark.css'), input: Rails.root.join('app', 'javascript', 'images', 'logo-symbol-wordmark.svg'), size: 102, output: output_dest.join('wordmark.dark.png'))
  28. rsvg_convert.run(stylesheet: Rails.root.join('lib', 'assets', 'wordmark.light.css'), input: Rails.root.join('app', 'javascript', 'images', 'logo-symbol-wordmark.svg'), size: 102, output: output_dest.join('wordmark.light.png'))
  29. end
  30. desc 'Generate favicons and app icons from SVG source files'
  31. task generate_app_icons: :environment do
  32. favicon_source = Rails.root.join('app', 'javascript', 'images', 'logo.svg')
  33. app_icon_source = Rails.root.join('app', 'javascript', 'images', 'app-icon.svg')
  34. output_dest = Rails.root.join('app', 'javascript', 'icons')
  35. rsvg_convert = Terrapin::CommandLine.new('rsvg-convert', '-w :size -h :size --keep-aspect-ratio :input -o :output')
  36. convert = Terrapin::CommandLine.new('convert', ':input :output', environment: { 'MAGICK_CONFIGURE_PATH' => nil })
  37. favicon_sizes = [16, 32, 48]
  38. apple_icon_sizes = [57, 60, 72, 76, 114, 120, 144, 152, 167, 180, 1024]
  39. android_icon_sizes = [36, 48, 72, 96, 144, 192, 256, 384, 512]
  40. favicons = []
  41. favicon_sizes.each do |size|
  42. output_path = output_dest.join("favicon-#{size}x#{size}.png")
  43. favicons << output_path
  44. rsvg_convert.run(size: size, input: favicon_source, output: output_path)
  45. end
  46. convert.run(input: favicons, output: Rails.public_path.join('favicon.ico'))
  47. apple_icon_sizes.each do |size|
  48. rsvg_convert.run(size: size, input: app_icon_source, output: output_dest.join("apple-touch-icon-#{size}x#{size}.png"))
  49. end
  50. android_icon_sizes.each do |size|
  51. rsvg_convert.run(size: size, input: app_icon_source, output: output_dest.join("android-chrome-#{size}x#{size}.png"))
  52. end
  53. end
  54. desc 'Generate badge icon from SVG source files'
  55. task generate_app_badge: :environment do
  56. rsvg_convert = Terrapin::CommandLine.new('rsvg-convert', '--stylesheet :stylesheet -w :size -h :size --keep-aspect-ratio :input -o :output')
  57. badge_source = Rails.root.join('app', 'javascript', 'images', 'logo-symbol-icon.svg')
  58. output_dest = Rails.public_path
  59. stylesheet = Rails.root.join('lib', 'assets', 'wordmark.light.css')
  60. rsvg_convert.run(stylesheet: stylesheet, input: badge_source, size: 192, output: output_dest.join('badge.png'))
  61. end
  62. end