Class: SdocAll

Inherits:
Object
  • Object
show all
Defined in:
lib/sdoc_all.rb,
lib/sdoc_all/base.rb,
lib/sdoc_all/task.rb,
lib/sdoc_all/file_list.rb,
lib/sdoc_all/parts/gems.rb,
lib/sdoc_all/parts/ruby.rb,
lib/sdoc_all/parts/paths.rb,
lib/sdoc_all/parts/rails.rb,
lib/sdoc_all/config_error.rb,
lib/sdoc_all/parts/plugins.rb

Defined Under Namespace

Classes: Base, BaseTask, ConfigError, FileList, Gems, MergeTask, Paths, Plugins, Rails, Ruby, Task

Class Method Summary collapse

Class Method Details

.config_hash_pathObject



40
41
42
# File 'lib/sdoc_all.rb', line 40

def config_hash_path
  Base.public_path + 'config.hash'
end

.current_sdoc_versionObject



36
37
38
# File 'lib/sdoc_all.rb', line 36

def current_sdoc_version
  Gem.searcher.find('sdoc').version.to_s
end

.last_build_sdoc_versionObject



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

def last_build_sdoc_version
  last_build_sdoc_version_path.read rescue nil
end

.last_build_sdoc_version_pathObject



28
29
30
# File 'lib/sdoc_all.rb', line 28

def last_build_sdoc_version_path
  Base.base_path + 'sdoc.version'
end

.read_configObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/sdoc_all.rb', line 122

def read_config
  Base.clear
  config = YAML.load_file('config.yml').symbolize_keys rescue {}

  min_update_interval = if config[:min_update_interval].to_s[/(\d+)\s*(.*)/]
    $1.to_i.send({'m' => :months, 'w' => :weeks, 'd' => :days, 'h' => :hours, 'm' => :minutes}[$2[0, 1].downcase] || :days)
  else
    1.week
  end

  created = last_build_sdoc_version_path.mtime rescue nil
  @update = created.nil? || created < min_update_interval.ago

  @title = config[:title]

  if config[:sdoc] && config[:sdoc].is_a?(Array) && config[:sdoc].length > 0
    errors = []
    config[:sdoc].with_progress('reading config').each do |entry|
      begin
        if entry.is_a?(Hash)
          if entry.length == 1
            Base.to_document(*entry.shift)
          else
            raise ConfigError.new("config entry #{entry.inspect} can not be understood - watch ident")
          end
        else
          Base.to_document(entry, {})
        end
      rescue ConfigError => e
        errors << e
      end
    end
    if errors.present?
      raise ConfigError.new(errors.join("\n"))
    end
  else
    raise ConfigError.new("config did not specify what to document")
  end
end

.run(options = {}) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/sdoc_all.rb', line 44

def run(options = {})
  message = 'WARNING: sdoc_all is no longer maintained, try doc gem'
  $stderr.puts message
  run!(options)
ensure
  $stderr.puts message
end

.run!(options = {}) ⇒ Object



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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/sdoc_all.rb', line 52

def run!(options = {})
  Base.dry_run! if options[:dry_run]
  Base.verbose_level = options[:verbose_level]
  Progress.lines = true if Base.verbose_level >= 1
  begin
    read_config
    tasks = Base.tasks(:update => update? || options[:update])

    if last_build_sdoc_version.nil? || last_build_sdoc_version != current_sdoc_version
      puts "sdoc version changed - rebuilding all docs".red unless last_build_sdoc_version.nil?
      Base.remove_if_present(Base.docs_path)
    else
      Base.chdir(Base.docs_path) do
        to_delete = Dir.glob('*') - tasks.map(&:occupied_doc_pathes).flatten
        to_delete.each do |path|
          Base.remove_if_present(path)
        end
      end
    end

    tasks.with_progress('sdoc').each do |task|
      Progress.start(task.title) do
        task.run(options)
      end
    end

    config_hash = Digest::SHA1.hexdigest(tasks.map(&:config_hash).inspect + title.to_s)
    created_hash = config_hash_path.read rescue nil

    if config_hash != created_hash
      Base.chdir(Base.docs_path) do
        paths = []
        titles = []
        urls = []
        tasks.each do |task|
          doc_path = Base.docs_path + task.doc_path
          if File.file?(doc_path + 'index.html')
            paths << task.doc_path
            titles << task.title
            urls << "docs/#{task.doc_path}"
          end
        end

        if paths.present?
          Base.remove_if_present(Base.public_path)

          cmd = %w(sdoc-merge)
          cmd << '-o' << Base.public_path
          cmd << '-t' << title
          cmd << '-n' << titles.join(',')
          cmd << '-u' << urls.join(' ')
          Base.system(*cmd + paths)

          if Base.public_path.directory?
            (Base.public_path + 'docs').make_symlink(Base.docs_path.relative_path_from(Base.public_path))
            config_hash_path.open('w') do |f|
              f.write(config_hash)
            end
            last_build_sdoc_version_path.open('w') do |f|
              f.write(current_sdoc_version)
            end
          end
        end
      end
    end
  rescue ConfigError => e
    abort e.to_s.red.bold
  end
end

.titleObject



24
25
26
# File 'lib/sdoc_all.rb', line 24

def title
  @title.present? ? @title : 'ruby related reference'
end

.update?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/sdoc_all.rb', line 20

def update?
  @update.nil? || @update
end