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, #run_if_clobber

Constructor Details

#initialize(options = {}) ⇒ Task

Returns a new instance of Task.



47
48
49
50
51
52
53
54
55
56
57
58
59
# 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

Instance Attribute Details

#doc_pathObject (readonly)

Returns the value of attribute doc_path.



46
47
48
# File 'lib/sdoc_all/task.rb', line 46

def doc_path
  @doc_path
end

#indexObject (readonly)

Returns the value of attribute index.



46
47
48
# File 'lib/sdoc_all/task.rb', line 46

def index
  @index
end

#mainObject (readonly)

Returns the value of attribute main.



46
47
48
# File 'lib/sdoc_all/task.rb', line 46

def main
  @main
end

#pathsObject (readonly)

Returns the value of attribute paths.



46
47
48
# File 'lib/sdoc_all/task.rb', line 46

def paths
  @paths
end

#src_pathObject (readonly)

Returns the value of attribute src_path.



46
47
48
# File 'lib/sdoc_all/task.rb', line 46

def src_path
  @src_path
end

#titleObject (readonly)

Returns the value of attribute title.



46
47
48
# File 'lib/sdoc_all/task.rb', line 46

def title
  @title
end

Instance Method Details

#clobber?Boolean

Returns:

  • (Boolean)


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# 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_hashObject



87
88
89
90
91
# 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_pathesObject



111
112
113
# File 'lib/sdoc_all/task.rb', line 111

def occupied_doc_pathes
  [doc_path]
end

#run(options = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 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