Sha256: 296d4c947c2604e81d054f884b48696250c0e1a7ba10746d9885e640148f0dde

Contents?: true

Size: 757 Bytes

Versions: 36

Compression:

Stored size: 757 Bytes

Contents

#!/usr/bin/ruby
# frozen_string_literal: true

PROG1 = %w[htmlbeautifier clang-format][1]
PROG2 = "rufo"

require "tempfile"
str = ARGV[0]
str or abort "Need file to change in place, can use /dev/stdin"

str = File.read str
DEBUG = false

def format(txt)
  txt.gsub(/(<<[~-]?([a-zA-Z]+)\n)(.*?)(\n\s*\2)/m) do
    c = Regexp.last_match(3)

    Tempfile.open do |file|
      IO.popen("#{PROG1} > #{file.path} ", "w") do |i|
        i << c
      end
      c = File.read(file.path)
    end
    val = "#{Regexp.last_match(1)}#{c}#{Regexp.last_match(4)}"
  end
end

require "shellwords"
IO.popen("#{PROG2}>#{ARGV[0].shellescape}", "w") do |i|
  i << format(str)
end

f = File.read ARGV[0]

s = "\n  "
f.gsub!(/\s+(?=<(!DOCTYPE|html))/, s)

File.write ARGV[0], f

Version data entries

36 entries across 35 versions & 6 rubygems

Version Path
ufos-1.0.87 ./other/beautify_html_in_heredocs
aliens-1.0.87 ./other/beautify_html_in_heredocs
freespeech-1.0.87 ./other/beautify_html_in_heredocs
elonmusk-1.0.87 ./other/beautify_html_in_heredocs
politics-1.0.87 ./other/beautify_html_in_heredocs
ufos-1.0.88 ./other/beautify_html_in_heredocs
aliens-1.0.88 ./other/beautify_html_in_heredocs
freespeech-1.0.88 ./other/beautify_html_in_heredocs
elonmusk-1.0.88 ./other/beautify_html_in_heredocs
politics-1.0.88 ./other/beautify_html_in_heredocs
democracy-1.0.86 ./other/beautify_html_in_heredocs
politics-1.0.82 ./other/beautify_html_in_heredocs
freespeech-1.0.82 ./other/beautify_html_in_heredocs
elonmusk-1.0.82 ./other/beautify_html_in_heredocs
ufos-1.0.82 ./other/beautify_html_in_heredocs
aliens-1.0.82 ./other/beautify_html_in_heredocs
politics-1.0.81 ./other/beautify_html_in_heredocs
ufos-1.0.79 ./other/beautify_html_in_heredocs
aliens-1.0.79 ./other/beautify_html_in_heredocs
freespeech-1.0.79 ./other/beautify_html_in_heredocs