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
eac_tools-0.55.7 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.55.6 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.55.5 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.55.4 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.55.3 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.55.2 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.55.1 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.55.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.54.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.53.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
avm-eac_webapp_base0-0.13.1 lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.52.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.51.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.50.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.49.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.48.1 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
avm-eac_webapp_base0-0.13.0 lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.48.0 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.47.2 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb
eac_tools-0.47.1 sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/html.rb