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.19.0 lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.87.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
avm-eac_webapp_base0-0.18.4 lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.86.8 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.84.2 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
avm-eac_webapp_base0-0.18.3 lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.84.1 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.84.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.83.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.82.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.81.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.80.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.79.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.78.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.77.1 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.77.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.76.1 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.76.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.75.2 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.75.1 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb