Sha256: d5a814cf91f05efc5d53306be384b8f4c7904c29f9ec006e1ceae70b036a589b

Contents?: true

Size: 1.5 KB

Versions: 4

Compression:

Stored size: 1.5 KB

Contents

require 'kramdown'
require 'kramdown/converter/man'

require 'rake/tasklib'

module Kramdown
  module Man
    #
    # Defines a `man` rake task that generates man-pages within the `man/`
    # directory from `.md` files.
    #
    class Task < Rake::TaskLib

      # Markdown file glob pattern
      FILES = 'man/{**/}*.{markdown,mkd,md}'

      # Additional options
      #
      # @return [Hash]
      attr_reader :options

      #
      # Initializes the tasks.
      #
      # @param [Hash] options
      #   Additional options.
      #
      def initialize(options={})
        @options   = options
        @markdown  = FileList[FILES]
        @man_pages = @markdown.pathmap('%X')

        define
      end

      protected

      #
      # Defines the `man` tasks.
      #
      def define
        desc 'Build UNIX manual pages from Markdown files in man/'
        task 'man' => @man_pages

        @markdown.zip(@man_pages).each do |markdown,man_page|
          file(man_page => markdown) do
            render(markdown,man_page)
          end
        end
      end

      #
      # Renders a man_page from a markdown file.
      #
      # @param [String] markdown
      #   The path to the input markdown file.
      #
      # @param [String] man_page
      #   The path to the output man_page file.
      #
      def render(markdown,man_page)
        doc = Kramdown::Document.new(File.read(markdown),@options)

        File.open(man_page,'w') do |output|
          output.write doc.to_man
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kramdown-man-0.1.6 lib/kramdown/man/task.rb
kramdown-man-0.1.5 lib/kramdown/man/task.rb
kramdown-man-0.1.4 lib/kramdown/man/task.rb
kramdown-man-0.1.3 lib/kramdown/man/task.rb