class Boring::Favicon::BuildGenerator

Constants

APPLE_PRECOMPOSED_SIZES
APPLE_SIZES
DEFAULT_FAVICON_LETTER
DEFAULT_IMAGE_PATH
DEFAULT_PRIMARY_COLOR
FAVICON_DIR
FILE_FAVICO_DIR
ICO_SIZES
LARGE_BREAK
MS_TILE_SIZES
SMALL_BREAK

Public Instance Methods

add_favicon_partial() click to toggle source
# File lib/generators/boring/favicon/build/build_generator.rb, line 111
      def add_favicon_partial
        say "Copying favicon layout partial", :green
        template("favicon.html.erb", "app/views/layouts/shared/_favicon.html.erb")
        insert_into_file "app/views/layouts/application.html.erb", <<~RUBY, after: /head.*\n/
          \t\t<%= render 'layouts/shared/favicon' %>
        RUBY
      end
build_favicon() click to toggle source
# File lib/generators/boring/favicon/build/build_generator.rb, line 30
      def build_favicon
        @application_name = options[:application_name]
        @primary_color = options[:primary_color]

        unless /Version/m =~ (`convert -version`)
          say <<~WARNING, :red
            ERROR: You do not have ImageMagick installed.
          WARNING
        end
      end
build_favicon_for_existing_template_image() click to toggle source
# File lib/generators/boring/favicon/build/build_generator.rb, line 47
def build_favicon_for_existing_template_image
  return unless File.exist?(DEFAULT_IMAGE_PATH)

  say "Converting template image to favicons..."
  template_name = "#{FILE_FAVICO_DIR}/template.png"
  template_small_name = "#{FILE_FAVICO_DIR}/template-small.png"
  template_large_name = "#{FILE_FAVICO_DIR}/template-large.png"
  template_small_name = template_name unless File.file?(template_small_name)
  template_large_name = template_name unless File.file?(template_large_name)
  ICO_SIZES.each do |size|
    ico_template = template_name
    ico_template = template_small_name if size.to_i <= SMALL_BREAK
    ico_template = template_small_name if size.to_i >= LARGE_BREAK
    (`convert #{ico_template} -resize #{size}x#{size} #{FILE_FAVICO_DIR}/favicon-#{size}x#{size}.ico`)
  end
  APPLE_SIZES.each do |size|
    ico_template = template_name
    ico_template = template_small_name if size.to_i <= SMALL_BREAK
    ico_template = template_small_name if size.to_i >= LARGE_BREAK
    (`convert #{ico_template} -resize #{size}x#{size} #{FILE_FAVICO_DIR}/apple-touch-icon-#{size}x#{size}.png`)
  end
  APPLE_PRECOMPOSED_SIZES.each do |size|
    ico_template = template_name
    ico_template = template_small_name if size.to_i <= SMALL_BREAK
    ico_template = template_small_name if size.to_i >= LARGE_BREAK
    (`convert #{ico_template} -resize #{size}x#{size} #{FILE_FAVICO_DIR}/apple-touch-icon-#{size}x#{size}-precomposed.png`)
  end
  MS_TILE_SIZES.each do |size|
    ico_template = template_name
    ico_template = template_small_name if size.to_i <= SMALL_BREAK
    ico_template = template_small_name if size.to_i >= LARGE_BREAK
    (`convert #{ico_template} -resize #{size}x#{size} #{FILE_FAVICO_DIR}/mstile-#{size}x#{size}.png`)
  end
  ico_template = template_name
  ico_template = template_small_name if 152 <= SMALL_BREAK
  ico_template = template_small_name if 152 >= LARGE_BREAK
  (`convert #{ico_template} -resize 152x152 #{FILE_FAVICO_DIR}/apple-touch-icon.png`)
  (`convert #{ico_template} -resize 152x152 #{FILE_FAVICO_DIR}/apple-touch-icon-precomposed.png`)
end
create_favicon_directory() click to toggle source
# File lib/generators/boring/favicon/build/build_generator.rb, line 41
def create_favicon_directory
  unless File.exists?(FILE_FAVICO_DIR)
    Dir.mkdir FILE_FAVICO_DIR
  end
end
generate_new_favicon_using_favico_letter() click to toggle source
# File lib/generators/boring/favicon/build/build_generator.rb, line 87
def generate_new_favicon_using_favico_letter
  return if File.exist?(DEFAULT_IMAGE_PATH)
  say "Creating favicons from application...", :green

  favico_letter = options[:favico_letter] || @application_name.try(:first) || DEFAULT_FAVICON_LETTER
  font_file_path = options[:font_file_path]
  favicon_color = options[:primary_color] || DEFAULT_PRIMARY_COLOR

  ICO_SIZES.each do |size|
    (`convert -background "#{favicon_color}" -fill white -size #{size}x#{size} -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/favicon-#{size}x#{size}.ico`)
  end
  APPLE_SIZES.each do |size|
    (`convert -background "#{favicon_color}" -fill white -size #{size}x#{size} -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/apple-touch-icon-#{size}x#{size}.png`)
  end
  APPLE_PRECOMPOSED_SIZES.each do |size|
    (`convert -background "#{favicon_color}" -fill white -size #{size}x#{size} -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/apple-touch-icon-#{size}x#{size}-precomposed.png`)
  end
  MS_TILE_SIZES.each do |size|
    (`convert -background "#{favicon_color}" -fill white -size #{size}x#{size} -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/mstile-#{size}x#{size}.png`)
  end
  (`convert -background "#{favicon_color}" -fill white -size 152x152 -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/apple-touch-icon.png`)
  (`convert -background "#{favicon_color}" -fill white -size 152x152 -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/apple-touch-icon-precomposed.png`)
end