Class: SdocAll::Task

Inherits:
BaseTask show all
Defined in:
lib/sdoc_all/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseTask

#config_hash, #config_hash_path, #created_rid_path, #last_build_time

Constructor Details

#initialize(options = {}) ⇒ Task

Returns a new instance of Task.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sdoc_all/task.rb', line 32

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

Instance Attribute Details

#doc_pathObject (readonly)

Returns the value of attribute doc_path.



31
32
33
# File 'lib/sdoc_all/task.rb', line 31

def doc_path
  @doc_path
end

#indexObject (readonly)

Returns the value of attribute index.



31
32
33
# File 'lib/sdoc_all/task.rb', line 31

def index
  @index
end

#mainObject (readonly)

Returns the value of attribute main.



31
32
33
# File 'lib/sdoc_all/task.rb', line 31

def main
  @main
end

#pathsObject (readonly)

Returns the value of attribute paths.



31
32
33
# File 'lib/sdoc_all/task.rb', line 31

def paths
  @paths
end

#src_pathObject (readonly)

Returns the value of attribute src_path.



31
32
33
# File 'lib/sdoc_all/task.rb', line 31

def src_path
  @src_path
end

#titleObject (readonly)

Returns the value of attribute title.



31
32
33
# File 'lib/sdoc_all/task.rb', line 31

def title
  @title
end

Instance Method Details

#clobber?Boolean

Returns:

  • (Boolean)


86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/sdoc_all/task.rb', line 86

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 unless latest < created
    end
  end
  created.nil? || latest >= created
end

#for_hashObject



80
81
82
83
84
# File 'lib/sdoc_all/task.rb', line 80

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_pathesObject



101
102
103
# File 'lib/sdoc_all/task.rb', line 101

def occupied_doc_pathes
  [doc_path]
end

#run(options = {}) ⇒ Object



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
74
75
76
77
78
# File 'lib/sdoc_all/task.rb', line 46

def run(options = {})
  if clobber?
    Base.remove_if_present(Base.docs_path + doc_path)

    cmd = %w(sdoc)
    cmd << '-o' << Base.docs_path + doc_path
    cmd << '-t' << title
    cmd << '-T' << 'direct'

    if src_path.directory?
      Dir.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

    if (Base.docs_path + doc_path).directory?
      config_hash_path.open('w') do |f|
        f.write(config_hash)
      end
    end
  end
end