class SdocAll::Task

Attributes

doc_path[R]
index[R]
main[R]
paths[R]
src_path[R]
title[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/sdoc_all/task.rb, line 47
def initialize(options = {})
  options[:paths] ||= []
  [/^readme$/i, /^readme\.(?:txt|rdoc|markdown)$/i, /^readme\./i].each do |readme_r|
    options[:main] ||= options[:paths].grep(readme_r).first
  end

  @src_path = Pathname.new(options[:src_path]).expand_path
  @doc_path = options[:doc_path]
  @paths = options[:paths]
  @main = options[:main]
  @title = options[:title]
  @index = options[:index]
end

Public Instance Methods

clobber?() click to toggle source
Calls superclass method SdocAll::BaseTask#clobber?
# File lib/sdoc_all/task.rb, line 93
def clobber?
  return true if super

  latest = [src_path.mtime, src_path.ctime].max
  created = last_build_time
  if created && latest < created
    src_path.find do |path|
      Find.prune if path.directory? && path.basename.to_s[0] == ?.
      latest = [latest, path.mtime, path.ctime].max
      break if latest >= created
    end
  end
  if created && latest >= created
    puts "#{title}: files changed since last build".red
  end
  created.nil? || latest >= created
end
for_hash() click to toggle source
# File lib/sdoc_all/task.rb, line 87
def for_hash
  for_hash = [src_path.to_s, doc_path.to_s, paths, main, title, last_build_time]
  for_hash << index if index
  for_hash
end
occupied_doc_pathes() click to toggle source
# File lib/sdoc_all/task.rb, line 111
def occupied_doc_pathes
  [doc_path]
end
run(options = {}) click to toggle source
# File lib/sdoc_all/task.rb, line 61
def run(options = {})
  run_if_clobber do
    cmd = %w(sdoc)
    cmd << '-o' << Base.docs_path + doc_path
    cmd << '-t' << title
    cmd << '-T' << 'direct'

    if src_path.directory?
      Base.chdir(src_path) do
        cmd << '-m' << main if main
        Base.system(*cmd + paths)
      end
      if index
        custom_index_dir_name = 'custom_index'
        custom_index_path = Base.docs_path + doc_path + custom_index_dir_name
        Base.remove_if_present(custom_index_path)
        FileUtils.cp_r(index, custom_index_path)
        index_html = Base.docs_path + doc_path + 'index.html'
        index_html.write index_html.read.sub(/(<frame src=")[^"]+(" name="docwin" \/>)/, "\\1#{custom_index_dir_name}/index.html\\2")
      end
    else
      Base.system(*cmd + [src_path])
    end
  end
end