Sha256: c876084191fd174cadc6169a7aa316230d2444a7a4f6b4d4d78974aab0924a1e
Contents?: true
Size: 1.38 KB
Versions: 5
Compression:
Stored size: 1.38 KB
Contents
#!/usr/bin/env ruby # encoding: UTF-8 $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'image_optim' README_FILE = File.expand_path('../../README.markdown', __FILE__) BEGIN_MARKER = '<!---<worker-options>-->' END_MARKER = '<!---</worker-options>-->' GENERATED_NOTE = '<!-- markdown for worker options is generated by '\ "`#{$PROGRAM_NAME}` -->" 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| io.puts %W[ * `:#{option_definition.name}` — #{option_definition.description} *(defaults to `#{option_definition.default.inspect}`)* ].join(' ') end end io.puts end def write_marked(io) io.puts BEGIN_MARKER io.puts GENERATED_NOTE 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.open(README_FILE, 'w') do |f| f.write readme end else abort 'Did not update worker options' end
Version data entries
5 entries across 5 versions & 1 rubygems