lib/milestoner/builders/ascii_doc.rb in milestoner-17.11.0 vs lib/milestoner/builders/ascii_doc.rb in milestoner-18.0.0
- old
+ new
@@ -2,31 +2,51 @@
require "refinements/pathname"
module Milestoner
module Builders
- # Builds Markdown page output.
+ # Builds ASCII Doc output.
class ASCIIDoc
- include Milestoner::Import[:input]
+ include Milestoner::Import[:settings, :logger]
using Refinements::Pathname
- def initialize(view: Views::Milestones::Show.new, enricher: Commits::Enricher.new, **)
+ def initialize(tagger: Commits::Tagger.new, view: Views::Milestones::Show.new, **)
+ @tagger = tagger
@view = view
- @enricher = enricher
super(**)
end
- def call = input.build_root.join("index.adoc").make_ancestors.tap { |path| write path }
+ def call
+ tagger.call
+ .fmap { |tags| build tags }
+ .alt_map { |message| failure message }
+ end
private
- attr_reader :view, :enricher
+ attr_reader :tagger, :view
- def write path
- enricher.call.fmap do |commits|
- path.write view.call commits:, layout: input.build_layout, format: :adoc
- end
+ 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