Method: RDoc::Generator::JsonIndex#generate_gzipped

Defined in:
lib/rdoc/generator/json_index.rb

#generate_gzippedObject

Compress the search_index.js file using gzip



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/rdoc/generator/json_index.rb', line 166

def generate_gzipped
  return if @options.dry_run or not defined?(Zlib)

  debug_msg "Compressing generated JSON index"
  out_dir = @base_dir + @options.op_dir

  search_index_file = out_dir + SEARCH_INDEX_FILE
  outfile           = out_dir + "#{search_index_file}.gz"

  debug_msg "Reading the JSON index file from %s" % search_index_file
  search_index = search_index_file.read(mode: 'r:utf-8')

  debug_msg "Writing gzipped search index to %s" % outfile

  Zlib::GzipWriter.open(outfile) do |gz|
    gz.mtime = File.mtime(search_index_file)
    gz.orig_name = search_index_file.basename.to_s
    gz.write search_index
    gz.close
  end

  # GZip the rest of the js files
  Dir.chdir @template_dir do
    Dir['**/*.js'].each do |source|
      dest = out_dir + source
      outfile = out_dir + "#{dest}.gz"

      debug_msg "Reading the original js file from %s" % dest
      data = dest.read

      debug_msg "Writing gzipped file to %s" % outfile

      Zlib::GzipWriter.open(outfile) do |gz|
        gz.mtime = File.mtime(dest)
        gz.orig_name = dest.basename.to_s
        gz.write data
        gz.close
      end
    end
  end
end