Class: Polytrix::Command::Generate::Code2Doc

Inherits:
Thor::Group
  • Object
show all
Includes:
DefaultLogger, Logging, Util::FileSystem, Thor::Actions
Defined in:
lib/polytrix/command/generators/code2doc.rb

Instance Method Summary collapse

Methods included from Util::FileSystem

#find_file, #relativize

Methods included from Util::String

included

Methods included from Util::String::ClassMethods

#ansi2html, #escape_html, #highlight, #slugify

Methods included from DefaultLogger

included

Methods included from DefaultLogger::ClassMethods

#logger

Instance Method Details

#code2docObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/polytrix/command/generators/code2doc.rb', line 51

def code2doc
  @scenarios.each do | scenario |
    source_file = scenario.source_file
    if source_file.nil?
      warn "No code sample available for #{scenario.slug}, no documentation will be generated."
      next
    end

    target_file_name = scenario.slug + ".#{options[:format]}"

    begin
      doc = Polytrix::DocumentationGenerator.new.code2doc(scenario.absolute_source_file)
      create_file(target_file_name, doc)
    rescue Polytrix::Documentation::CommentStyles::UnknownStyleError
      warn "Could not generated documentation for #{source_file}, because the language couldn't be detected."
    end
  end
end

#set_destination_rootObject



47
48
49
# File 'lib/polytrix/command/generators/code2doc.rb', line 47

def set_destination_root
  self.destination_root = options[:destination]
end

#setupObject



37
38
39
40
41
42
43
44
45
# File 'lib/polytrix/command/generators/code2doc.rb', line 37

def setup
  # HACK: Need to make Command setup/parse_subcommand easily re-usable in Thor::Group actions
  command_options = {
    shell: shell
  }.merge(options)
  command = Polytrix::Command::Base.new(args, options, command_options)
  command.send(:setup)
  @scenarios = command.send(:parse_subcommand, args.pop)
end