Sha256: 6ac110f67e669cdeb2ff3bdc00e33494d32fbf625ede98c9b8145a7de5e1f6f2

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require "tocer"

module Rubysmith
  module Builders
    module Documentation
      # Builds project skeleton README documentation.
      class Readme
        def self.call(...) = new(...).call

        def initialize configuration, builder: Builder, tocer: Tocer::Writer.new
          @configuration = configuration
          @builder = builder
          @tocer = tocer
        end

        def call
          return unless configuration.build_readme

          private_methods.sort.grep(/render_/).each { |method| __send__ method }
        end

        private

        attr_reader :configuration, :builder, :tocer

        def render_content
          builder.call(configuration.with(template_path: "%project_name%/README.#{kind}.erb"))
                 .render
                 .replace("\n\n\n", "\n\n")
        end

        def render_table_of_contents
          configuration.project_root
                       .join("README.md")
                       .then { |path| tocer.call path if path.exist? }
        end

        def kind = configuration.documentation_format || "md"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubysmith-0.16.1 lib/rubysmith/builders/documentation/readme.rb
rubysmith-0.16.0 lib/rubysmith/builders/documentation/readme.rb
rubysmith-0.15.0 lib/rubysmith/builders/documentation/readme.rb
rubysmith-0.14.0 lib/rubysmith/builders/documentation/readme.rb