Sha256: 1fe49e72d661bb8fdcba41e8c785836d0ec95d78e72a0105c65508ef48b070cc

Contents?: true

Size: 1.05 KB

Versions: 98

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require 'avm/eac_generic_base0/file_formats/base'
require 'htmlbeautifier'

module Avm
  module EacWebappBase0
    module FileFormats
      class Html < ::Avm::EacGenericBase0::FileFormats::Base
        VALID_BASENAMES = %w[*.html *.html.erb].freeze
        VALID_TYPES = [].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

Version data entries

98 entries across 98 versions & 2 rubygems

Version Path
avm-eac_webapp_base0-0.17.0 lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.64.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
avm-eac_webapp_base0-0.16.0 lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.63.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
avm-eac_webapp_base0-0.15.1 lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.62.1 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.62.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.61.1 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.61.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.60.3 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.60.2 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
avm-eac_webapp_base0-0.15.0 lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.60.1 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.60.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.59.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.58.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.57.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.56.1 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
avm-eac_webapp_base0-0.14.0 lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.56.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb