Sha256: c836958c0c6af7ad46ead0047ca5b21df945b7c7de1df0f9923de7daeee958e3

Contents?: true

Size: 1.13 KB

Versions: 170

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'avm/files/formatter/formats/generic_plain'
require 'htmlbeautifier'

module Avm
  module Files
    class Formatter
      module Formats
        class Html < ::Avm::Files::Formatter::Formats::GenericPlain
          VALID_BASENAMES = %w[*.html *.html.erb].freeze
          VALID_TYPES = ['html'].freeze

          def file_apply(path)
            input = ::File.read(path)
            temppath = tempfile_path
            ::File.open(temppath, 'w') do |output|
              beautify path, input, output
            end
            ::FileUtils.mv(temppath, path)
            super(path)
          end

          private

          def beautify(name, input, output)
            output.puts ::HtmlBeautifier.beautify(input, htmlbeautify_options)
          rescue StandardError => e
            raise "Error parsing #{name}: #{e}"
          end

          def htmlbeautify_options
            @htmlbeautify_options ||= { indent: '  ' }
          end

          def tempfile_path
            tempfile = ::Tempfile.new
            tempfile.close
            tempfile.path
          end
        end
      end
    end
  end
end

Version data entries

170 entries across 170 versions & 4 rubygems

Version Path
eac_tools-0.37.1 sub/avm-files/lib/avm/files/formatter/formats/html.rb
eac_tools-0.37.0 sub/avm-files/lib/avm/files/formatter/formats/html.rb
eac_tools-0.36.1 sub/avm-files/lib/avm/files/formatter/formats/html.rb
eac_tools-0.36.0 sub/avm-files/lib/avm/files/formatter/formats/html.rb
eac_tools-0.35.0 sub/avm-files/lib/avm/files/formatter/formats/html.rb
eac_tools-0.34.0 sub/avm-files/lib/avm/files/formatter/formats/html.rb
eac_tools-0.33.0 sub/avm-files/lib/avm/files/formatter/formats/html.rb
eac_tools-0.32.0 sub/avm-files/lib/avm/files/formatter/formats/html.rb
eac_tools-0.31.1 sub/avm-files/lib/avm/files/formatter/formats/html.rb
avm-files-0.4.1 lib/avm/files/formatter/formats/html.rb
eac_tools-0.31.0 sub/avm-files/lib/avm/files/formatter/formats/html.rb
eac_tools-0.30.0 sub/avm-files/lib/avm/files/formatter/formats/html.rb
avm-tools-0.129.0 sub/avm-files/lib/avm/files/formatter/formats/html.rb
eac_tools-0.16.0 sub/avm-tools/sub/avm-files/lib/avm/files/formatter/formats/html.rb
avm-tools-0.128.0 sub/avm-files/lib/avm/files/formatter/formats/html.rb
eac_tools-0.15.0 sub/avm-tools/sub/avm-files/lib/avm/files/formatter/formats/html.rb
eac_tools-0.14.0 sub/avm-tools/sub/avm-files/lib/avm/files/formatter/formats/html.rb
eac_tools-0.13.0 sub/avm-tools/sub/avm-files/lib/avm/files/formatter/formats/html.rb
avm-tools-0.127.0 sub/avm-files/lib/avm/files/formatter/formats/html.rb
eac_tools-0.12.0 sub/avm-tools/sub/avm-files/lib/avm/files/formatter/formats/html.rb