Sha256: 09920c41d39e85dc9464e37bede1f080a09e4b2b241d77d6bc109f431a350df3

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

#!/usr/bin/env ruby
# encoding: UTF-8
# frozen_string_literal: true

require 'bundler/setup'

require 'image_optim'

README_FILE = File.expand_path('../../README.markdown', __FILE__)
BEGIN_MARKER = '<!---<worker-options>-->'
END_MARKER = '<!---</worker-options>-->'

def write_worker_options(io, klass)
  io.puts "### #{klass.bin_sym}:"
  if klass.option_definitions.empty?
    io.puts 'Worker has no options'
  else
    klass.option_definitions.each do |option_definition|
      line = "* `:#{option_definition.name}` — #{option_definition.description}"
      unless line['(defaults']
        line += " *(defaults to #{option_definition.default_description})*"
      end
      io.puts line
    end
  end
  io.puts
end

def write_marked(io)
  io.puts BEGIN_MARKER
  io.puts '<!-- markdown for worker options is generated by ' \
          "`#{Pathname($PROGRAM_NAME).cleanpath}` -->"
  io.puts

  ImageOptim::Worker.klasses.sort_by(&:name).each do |klass|
    write_worker_options(io, klass)
  end

  io.puts END_MARKER
end

def update_readme(text)
  marked_reg = /#{Regexp.escape(BEGIN_MARKER)}.*#{Regexp.escape(END_MARKER)}/m
  text.clone.sub!(marked_reg) do
    StringIO.open do |io|
      write_marked(io)

      io.string.strip
    end
  end
end

readme = File.read(README_FILE)
if (readme = update_readme(readme))
  File.write(README_FILE, readme)
else
  abort 'Did not update worker options'
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
image_optim-0.31.3 script/update_worker_options_in_readme
image_optim-0.31.2 script/update_worker_options_in_readme