Sha256: 16a0527ef8364e9534c4f1a654aa810f32d24a9550e33fd6a615c651b6633584

Contents?: true

Size: 1.14 KB

Versions: 13

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

require "refinements/pathname"

module Milestoner
  module Builders
    # Builds ASCII Doc output.
    class ASCIIDoc
      include Milestoner::Import[:settings, :logger]

      using Refinements::Pathname

      def initialize(tagger: Commits::Tagger.new, view: Views::Milestones::Show.new, **)
        @tagger = tagger
        @view = view
        super(**)
      end

      def call
        tagger.call
              .fmap { |tags| build tags }
              .alt_map { |message| failure message }
      end

      private

      attr_reader :tagger, :view

      def build tags
        tags.each { |tag| write tag }
        settings.build_root
      end

      def write tag
        path = make_path tag

        path.write view.call(tag:, layout: settings.build_layout, format: :adoc)
        logger.info { "Built: #{path}." }
      end

      def make_path tag
        version = settings.build_max == 1 ? "" : tag.version
        settings.build_root.join(version, settings.build_basename).make_ancestors.sub_ext ".adoc"
      end

      def failure message
        logger.error { message }
        message
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
milestoner-18.11.0 lib/milestoner/builders/ascii_doc.rb
milestoner-18.10.0 lib/milestoner/builders/ascii_doc.rb
milestoner-18.9.0 lib/milestoner/builders/ascii_doc.rb
milestoner-18.8.0 lib/milestoner/builders/ascii_doc.rb
milestoner-18.7.0 lib/milestoner/builders/ascii_doc.rb
milestoner-18.6.0 lib/milestoner/builders/ascii_doc.rb
milestoner-18.5.0 lib/milestoner/builders/ascii_doc.rb
milestoner-18.4.0 lib/milestoner/builders/ascii_doc.rb
milestoner-18.3.0 lib/milestoner/builders/ascii_doc.rb
milestoner-18.2.0 lib/milestoner/builders/ascii_doc.rb
milestoner-18.1.0 lib/milestoner/builders/ascii_doc.rb
milestoner-18.0.1 lib/milestoner/builders/ascii_doc.rb
milestoner-18.0.0 lib/milestoner/builders/ascii_doc.rb