branding.rake 3.9 KB

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