Class: Kramdown::Man::Task

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/kramdown/man/task.rb

Overview

Defines a man rake task that generates man-pages within the man/ directory from .md files.

Constant Summary collapse

FILES =

Markdown file glob pattern

'man/{**/}*.{markdown,mkd,md}'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Task

Initializes the tasks.

Parameters:

  • options (Hash) (defaults to: {})

    Additional options.



30
31
32
33
34
35
36
# File 'lib/kramdown/man/task.rb', line 30

def initialize(options={})
  @options   = options
  @markdown  = FileList[FILES]
  @man_pages = @markdown.pathmap('%X')

  define
end

Instance Attribute Details

#optionsHash (readonly)

Additional options

Returns:

  • (Hash)


22
23
24
# File 'lib/kramdown/man/task.rb', line 22

def options
  @options
end

Instance Method Details

#defineObject (protected)

Defines the man tasks.



43
44
45
46
47
48
49
50
51
52
# File 'lib/kramdown/man/task.rb', line 43

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

#render(markdown, man_page) ⇒ Object (protected)

Renders a man_page from a markdown file.

Parameters:

  • markdown (String)

    The path to the input markdown file.

  • man_page (String)

    The path to the output man_page file.



63
64
65
66
67
68
69
# File 'lib/kramdown/man/task.rb', line 63

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