epuber 0.9.4 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/epuber.gemspec +1 -1
- data/lib/epuber/checker/text_checker.rb +1 -2
- data/lib/epuber/checker.rb +3 -7
- data/lib/epuber/command/build.rb +43 -7
- data/lib/epuber/command/init.rb +5 -5
- data/lib/epuber/command/server.rb +1 -1
- data/lib/epuber/command.rb +24 -19
- data/lib/epuber/compiler/compilation_context.rb +8 -4
- data/lib/epuber/compiler/file_resolver.rb +1 -1
- data/lib/epuber/compiler/file_types/source_file.rb +2 -2
- data/lib/epuber/compiler/file_types/xhtml_file.rb +7 -15
- data/lib/epuber/compiler/xhtml_processor.rb +2 -2
- data/lib/epuber/compiler.rb +13 -10
- data/lib/epuber/config.rb +35 -14
- data/lib/epuber/epubcheck.rb +77 -2
- data/lib/epuber/from_file/from_file_executor.rb +9 -9
- data/lib/epuber/plugin.rb +1 -1
- data/lib/epuber/server.rb +5 -5
- data/lib/epuber/transformer/book_transformer.rb +30 -12
- data/lib/epuber/user_interface.rb +13 -218
- data/lib/epuber/utils/location.rb +14 -0
- data/lib/epuber/utils/logger/abstract_logger.rb +214 -0
- data/lib/epuber/utils/logger/console_logger.rb +122 -0
- data/lib/epuber/version.rb +1 -1
- metadata +8 -5
| @@ -0,0 +1,122 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative 'abstract_logger'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module Epuber
         | 
| 6 | 
            +
              module Logger
         | 
| 7 | 
            +
                class ConsoleLogger < AbstractLogger
         | 
| 8 | 
            +
                  def _log(level, message, location: nil, backtrace: nil, sticky: false)
         | 
| 9 | 
            +
                    prev_line = _remove_sticky_message
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                    # save sticky message
         | 
| 12 | 
            +
                    @sticky_message = message if sticky
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                    formatted_message = _format_message(level, message, location: location, backtrace: backtrace)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    # print the message
         | 
| 17 | 
            +
                    if sticky
         | 
| 18 | 
            +
                      $stdout.print(formatted_message)
         | 
| 19 | 
            +
                    else
         | 
| 20 | 
            +
                      $stdout.puts(formatted_message)
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                      # reprint previous sticky message when this message is not sticky
         | 
| 23 | 
            +
                      if prev_line
         | 
| 24 | 
            +
                        @sticky_message = prev_line
         | 
| 25 | 
            +
                        $stdout.print(prev_line)
         | 
| 26 | 
            +
                      end
         | 
| 27 | 
            +
                    end
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  private
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  # @param [Symbol] level color of the output
         | 
| 33 | 
            +
                  #
         | 
| 34 | 
            +
                  # @return [Symbol] color
         | 
| 35 | 
            +
                  #
         | 
| 36 | 
            +
                  def _color_from_level(level)
         | 
| 37 | 
            +
                    case level
         | 
| 38 | 
            +
                    when :error then   :red
         | 
| 39 | 
            +
                    when :warning then :yellow
         | 
| 40 | 
            +
                    when :info then    :white
         | 
| 41 | 
            +
                    when :debug then   :blue
         | 
| 42 | 
            +
                    else
         | 
| 43 | 
            +
                      raise "Unknown output level #{level}"
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                  # @param [Symbol] level color of the output
         | 
| 48 | 
            +
                  # @param [String] message message of the error
         | 
| 49 | 
            +
                  # @param [Thread::Backtrace::Location] location location of the error
         | 
| 50 | 
            +
                  #
         | 
| 51 | 
            +
                  # @return [String] formatted message
         | 
| 52 | 
            +
                  #
         | 
| 53 | 
            +
                  def _format_message(level, message, location: nil, backtrace: nil)
         | 
| 54 | 
            +
                    location = _location_from_obj(location)
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    comps = []
         | 
| 57 | 
            +
                    comps << message.to_s
         | 
| 58 | 
            +
                    message_already_formatted =
         | 
| 59 | 
            +
                      message.is_a?(Epuber::Compiler::Problem) || message.is_a?(Epuber::Checker::TextChecker::MatchProblem)
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                    should_add_location = if message_already_formatted || location.nil?
         | 
| 62 | 
            +
                                            false
         | 
| 63 | 
            +
                                          else
         | 
| 64 | 
            +
                                            %i[error warning].include?(level)
         | 
| 65 | 
            +
                                          end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                    # add location
         | 
| 68 | 
            +
                    if should_add_location
         | 
| 69 | 
            +
                      path = location.path
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                      # calculate relative path when path is absolute and in project
         | 
| 72 | 
            +
                      path = path[Config.instance.project_path.size + 1..-1] if path.start_with?(Config.instance.project_path)
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                      line_parts = [
         | 
| 75 | 
            +
                        "  (in file #{path}",
         | 
| 76 | 
            +
                      ]
         | 
| 77 | 
            +
                      line_parts << "line #{location.lineno}" if location.lineno
         | 
| 78 | 
            +
                      line_parts << "column #{location.column}" if location.column
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                      comps << "#{line_parts.join(' ')})"
         | 
| 81 | 
            +
                    end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                    # add backtrace
         | 
| 84 | 
            +
                    comps += _format_backtrace(backtrace, location: location) if backtrace && @verbose && level == :error
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                    comps.join("\n").ansi.send(_color_from_level(level))
         | 
| 87 | 
            +
                  end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                  # @param [Array<Thread::Backtrace::Location>] locations locations of the error (only for verbose output)
         | 
| 90 | 
            +
                  # @param [Thread::Backtrace::Location] location location of the error
         | 
| 91 | 
            +
                  #
         | 
| 92 | 
            +
                  # @return [Array<String>] formatted message
         | 
| 93 | 
            +
                  #
         | 
| 94 | 
            +
                  def _format_backtrace(locations, location: nil)
         | 
| 95 | 
            +
                    index = locations.index(location) || 0
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                    formatted = []
         | 
| 98 | 
            +
                    formatted << '' # empty line
         | 
| 99 | 
            +
                    formatted << 'Full backtrace:'
         | 
| 100 | 
            +
                    formatted += locations[index, locations.size].map do |loc|
         | 
| 101 | 
            +
                      "  #{loc}"
         | 
| 102 | 
            +
                    end
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                    formatted
         | 
| 105 | 
            +
                  end
         | 
| 106 | 
            +
             | 
| 107 | 
            +
                  # @return [String, nil] last line
         | 
| 108 | 
            +
                  #
         | 
| 109 | 
            +
                  def _remove_sticky_message
         | 
| 110 | 
            +
                    last_line = @sticky_message
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                    unless @sticky_message.nil?
         | 
| 113 | 
            +
                      $stdout.print("\033[2K") # remove line, but without moving cursor
         | 
| 114 | 
            +
                      $stdout.print("\r") # go to beginning of line
         | 
| 115 | 
            +
                      @sticky_message = nil
         | 
| 116 | 
            +
                    end
         | 
| 117 | 
            +
             | 
| 118 | 
            +
                    last_line
         | 
| 119 | 
            +
                  end
         | 
| 120 | 
            +
                end
         | 
| 121 | 
            +
              end
         | 
| 122 | 
            +
            end
         | 
    
        data/lib/epuber/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: epuber
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.10.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Roman Kříž
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024- | 
| 11 | 
            +
            date: 2024-06-06 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         | 
| @@ -211,7 +211,7 @@ dependencies: | |
| 211 211 | 
             
                    version: '4.2'
         | 
| 212 212 | 
             
                - - "<"
         | 
| 213 213 | 
             
                  - !ruby/object:Gem::Version
         | 
| 214 | 
            -
                    version: ' | 
| 214 | 
            +
                    version: '7.0'
         | 
| 215 215 | 
             
              type: :runtime
         | 
| 216 216 | 
             
              prerelease: false
         | 
| 217 217 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| @@ -221,7 +221,7 @@ dependencies: | |
| 221 221 | 
             
                    version: '4.2'
         | 
| 222 222 | 
             
                - - "<"
         | 
| 223 223 | 
             
                  - !ruby/object:Gem::Version
         | 
| 224 | 
            -
                    version: ' | 
| 224 | 
            +
                    version: '7.0'
         | 
| 225 225 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 226 226 | 
             
              name: rubyzip
         | 
| 227 227 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -568,6 +568,9 @@ files: | |
| 568 568 | 
             
            - lib/epuber/transformer/book_transformer.rb
         | 
| 569 569 | 
             
            - lib/epuber/transformer/text_transformer.rb
         | 
| 570 570 | 
             
            - lib/epuber/user_interface.rb
         | 
| 571 | 
            +
            - lib/epuber/utils/location.rb
         | 
| 572 | 
            +
            - lib/epuber/utils/logger/abstract_logger.rb
         | 
| 573 | 
            +
            - lib/epuber/utils/logger/console_logger.rb
         | 
| 571 574 | 
             
            - lib/epuber/vendor/hash_binding.rb
         | 
| 572 575 | 
             
            - lib/epuber/vendor/nokogiri_extensions.rb
         | 
| 573 576 | 
             
            - lib/epuber/vendor/ruby_templater.rb
         | 
| @@ -594,7 +597,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 594 597 | 
             
                - !ruby/object:Gem::Version
         | 
| 595 598 | 
             
                  version: '0'
         | 
| 596 599 | 
             
            requirements: []
         | 
| 597 | 
            -
            rubygems_version: 3.5. | 
| 600 | 
            +
            rubygems_version: 3.5.11
         | 
| 598 601 | 
             
            signing_key:
         | 
| 599 602 | 
             
            specification_version: 4
         | 
| 600 603 | 
             
            summary: Epuber is simple tool to compile and pack source files into EPUB format.
         |