Class: PDoc::Runner
- Inherits:
-
Object
- Object
- PDoc::Runner
- Defined in:
- lib/pdoc/runner.rb
Instance Method Summary collapse
- #deserialize(files) ⇒ Object
-
#initialize(*source_files) ⇒ Runner
constructor
A new instance of Runner.
- #new_files ⇒ Object
- #run ⇒ Object
- #serialize(files) ⇒ Object
Constructor Details
#initialize(*source_files) ⇒ Runner
Returns a new instance of Runner.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/pdoc/runner.rb', line 5 def initialize(*source_files) = source_files.last.is_a?(Hash) ? source_files.pop : {} @source_files = source_files.empty? ? [:source_files] : source_files @output_directory = File.(.delete(:destination) || OUTPUT_DIR) @generator = .delete(:generator) || Generators::Html::Website @parser = Parser @serializer = Serializer @bust_cache = .delete(:bust_cache) || false Models.src_code_href = .delete(:src_code_href) Models.doc_href = .delete(:doc_href) @generator_options = end |
Instance Method Details
#deserialize(files) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pdoc/runner.rb', line 26 def deserialize(files) results = [] files.each do |file| file = pdoc_file(file) File.open(file) do |y| YAML.load_documents(y) { |doc| results << doc } end end results end |
#new_files ⇒ Object
37 38 39 40 41 42 |
# File 'lib/pdoc/runner.rb', line 37 def new_files @source_files.select do |path| pdoc = pdoc_file(path) !File.exist?(pdoc) || File.mtime(path) > File.mtime(pdoc) end end |
#run ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/pdoc/runner.rb', line 44 def run opts = @generator_options puts puts " Markdown parser: #{opts[:markdown_parser]}" if opts[:markdown_parser] puts " Syntax highlighter: #{opts[:syntax_highlighter]}" if opts[:syntax_highlighter] puts " Pretty urls: #{opts[:pretty_urls]}" if opts[:pretty_urls] puts " Index page: #{opts[:index_page]}" if opts[:index_page] puts " Output directory: #{@output_directory}\n\n" files = @bust_cache ? @source_files : new_files if files.empty? puts " Restoring serialized documentation from cache.\n\n" else puts " Parsing JS files for PDoc comments:" start_time = Time.new serialize(files) puts " Finished parsing files in #{Time.new - start_time} seconds.\n\n" end start_time = Time.new data = deserialize(@source_files) root = Treemaker.new(data).root puts " Building documentation tree. Finished in #{Time.new - start_time} seconds.\n\n" start_time = Time.new puts " Generating documentation:" @generator.new(root, @generator_options).render(@output_directory) puts "\n Finished generating documentation in #{Time.new - start_time} seconds.\n\n" end |
#serialize(files) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/pdoc/runner.rb', line 18 def serialize(files) files.each do |path| File.open(pdoc_file(path), "w+") do |f| f << serialize_file(path) end end end |