1
0

branding.rake 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. Rails.root.glob('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. 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. apple_icon_sizes.each do |size|
  46. rsvg_convert.run(size: size, input: app_icon_source, output: output_dest.join("apple-touch-icon-#{size}x#{size}.png"))
  47. end
  48. android_icon_sizes.each do |size|
  49. rsvg_convert.run(size: size, input: app_icon_source, output: output_dest.join("android-chrome-#{size}x#{size}.png"))
  50. end
  51. end
  52. desc 'Generate badge icon from SVG source files'
  53. task generate_app_badge: :environment do
  54. rsvg_convert = Terrapin::CommandLine.new('rsvg-convert', '--stylesheet :stylesheet -w :size -h :size --keep-aspect-ratio :input -o :output')
  55. badge_source = Rails.root.join('app', 'javascript', 'images', 'logo-symbol-icon.svg')
  56. output_dest = Rails.public_path
  57. stylesheet = Rails.root.join('lib', 'assets', 'wordmark.light.css')
  58. rsvg_convert.run(stylesheet: stylesheet, input: badge_source, size: 192, output: output_dest.join('badge.png'))
  59. end
  60. end