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



69
70
71
# File 'lib/sdoc_all.rb', line 69

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

.current_sdoc_versionObject



65
66
67
# File 'lib/sdoc_all.rb', line 65

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

.last_build_sdoc_versionObject



61
62
63
# File 'lib/sdoc_all.rb', line 61

def last_build_sdoc_version
  last_build_sdoc_version_path.read rescue nil
end

.last_build_sdoc_version_pathObject



57
58
59
# File 'lib/sdoc_all.rb', line 57

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

.read_configObject



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/sdoc_all.rb', line 146

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({'d' => :days, 'h' => :hours, 'm' => :minutes}[$2[0, 1].downcase] || :seconds)
  else
    1.hour
  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



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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/sdoc_all.rb', line 73

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.each do |task|
          to_delete -= task.occupied_doc_pathes
        end
        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?
            File.symlink(Base.docs_path, Base.public_path + 'docs')
            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



53
54
55
# File 'lib/sdoc_all.rb', line 53

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

.update?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/sdoc_all.rb', line 49

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