Sha256: 64e3f31a6cc8b121295ca10c4d2740b0a9a536e1126f4759b718a3804de69e7a

Contents?: true

Size: 1.9 KB

Versions: 7

Compression:

Stored size: 1.9 KB

Contents

# encoding: utf-8


module Epuber
  class Compiler
    class CompilationContext
      # @return [Epuber::Book]
      #
      attr_reader :book

      # @return [Epuber::Book::Target]
      #
      attr_reader :target

      # @return [Epuber::Compiler::FileResolver]
      #
      attr_accessor :file_resolver

      # @return [Array<Epuber::Plugin>]
      #
      def plugins
        @plugins ||= @target.plugins.map do |path|
          begin
            plugin = Plugin.new(File.expand_path(path, Config.instance.project_path))
            plugin.files.each do |file|
              file_resolver.add_file(file)
            end
            plugin
          rescue LoadError
            UI.error "Can't find plugin at path #{path}"
          end
        end.compact
      end

      # @param [Class] klass class of thing you want to perform (Checker or Transformer)
      # @param [Symbol] source_type source type of that thing (Checker or Transformer)
      #
      # @yield
      # @yieldparam [Epuber::CheckerTransformerBase] instance of checker or transformer
      #
      # @return nil
      #
      def perform_plugin_things(klass, source_type)
        plugins.each do |plugin|
          plugin.instances(klass).each do |instance|
            # @type [Epuber::CheckerTransformerBase] instance

            next if instance.source_type != source_type
            next if instance.options.include?(:run_only_before_release) && !release_build

            yield instance
          end
        end
      end


      #########

      # @return [Bool]
      #
      attr_accessor :should_check

      # @return [Bool]
      #
      attr_accessor :should_write

      # @return [Bool]
      #
      attr_accessor :release_build

      # @return [Bool]
      #
      attr_accessor :verbose

      def verbose?
        verbose
      end


      def initialize(book, target)
        @book = book
        @target = target
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
epuber-0.3.12 lib/epuber/compiler/compilation_context.rb
epuber-0.3.11 lib/epuber/compiler/compilation_context.rb
epuber-0.3.10 lib/epuber/compiler/compilation_context.rb
epuber-0.3.9 lib/epuber/compiler/compilation_context.rb
epuber-0.3.7 lib/epuber/compiler/compilation_context.rb
epuber-0.3.6 lib/epuber/compiler/compilation_context.rb
epuber-0.3.5 lib/epuber/compiler/compilation_context.rb