Class: SdocAll::Task
Instance Attribute Summary collapse
-
#doc_path ⇒ Object
readonly
Returns the value of attribute doc_path.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#main ⇒ Object
readonly
Returns the value of attribute main.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#src_path ⇒ Object
readonly
Returns the value of attribute src_path.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #clobber? ⇒ Boolean
- #for_hash ⇒ Object
-
#initialize(options = {}) ⇒ Task
constructor
A new instance of Task.
- #occupied_doc_pathes ⇒ Object
- #run(options = {}) ⇒ Object
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( = {}) [:paths] ||= [] [/^readme$/i, /^readme\.(?:txt|rdoc|markdown)$/i, /^readme\./i].each do |readme_r| [:main] ||= [:paths].grep(readme_r).first end @src_path = Pathname.new([:src_path]). @doc_path = [:doc_path] @paths = [:paths] @main = [:main] @title = [:title] @index = [:index] end |
Instance Attribute Details
#doc_path ⇒ Object (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 |
#index ⇒ Object (readonly)
Returns the value of attribute index.
46 47 48 |
# File 'lib/sdoc_all/task.rb', line 46 def index @index end |
#main ⇒ Object (readonly)
Returns the value of attribute main.
46 47 48 |
# File 'lib/sdoc_all/task.rb', line 46 def main @main end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
46 47 48 |
# File 'lib/sdoc_all/task.rb', line 46 def paths @paths end |
#src_path ⇒ Object (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 |
#title ⇒ Object (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
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_hash ⇒ Object
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_pathes ⇒ Object
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( = {}) 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 |