blob: 3265158af6d4f0559462f34b76dd62c9abab43eb [file] [log] [blame]
Christian Williams & Phil Goodwin7ce366c2010-11-03 10:31:04 -07001#!/usr/bin/env ruby
2
3DOWNLOADS_FILE = 'pages/download.html.md'
4
5def need_pages_submodule
6 unless File.exists?(DOWNLOADS_FILE)
7 raise "Jasmine pages submodule isn't present. Run git submodule update --init"
8 end
9end
10
11def doc
12 need_pages_submodule
13
14 puts 'Creating Jasmine Documentation'
15 require 'rubygems'
16 require 'jsdoc_helper'
17
18 FileUtils.rm_r "pages/jsdoc", :force => true
19
20 JsdocHelper::Rake::Task.new(:lambda_jsdoc) do |t|
21 t[:files] = jasmine_sources << jasmine_html_sources
22 t[:options] = "-a"
23 t[:out] = "pages/jsdoc"
24 # JsdocHelper bug: template must be relative to the JsdocHelper gem, ick
25 t[:template] = File.join("../".*(100), Dir::getwd, "jsdoc-template")
26 end
27 Rake::Task[:lambda_jsdoc].invoke
28end
29
30def fill_index_downloads
31 require 'digest/sha1'
32
33 download_html = "<!-- START_DOWNLOADS -->\n"
34 Dir.glob('pages/downloads/*.jar').sort.reverse.each do |f|
35 sha1 = Digest::SHA1.hexdigest File.read(f)
36
37 fn = f.sub(/^pages\//, '')
38 match = /robolectric(-all)?-([0-9].*).jar/.match(f)
39 version = "SNAPSHOT"
40 version = match[1] if match
41 prerelease = /\.rc/.match(f)
42 download_html += prerelease ? "<tr class=\"rc\">\n" : "<tr>\n"
43 download_html += " <td class=\"link\"><a href=\"#{fn}\">#{fn.sub(/downloads\//, '')}</a></td>\n"
44 download_html += " <td class=\"version\">#{version}</td>\n"
45 download_html += " <td class=\"size\">#{File.size(f) / 1024}k</td>\n"
46 download_html += " <td class=\"date\">#{File.mtime(f).strftime("%Y/%m/%d %H:%M:%S %Z")}</td>\n"
47 download_html += " <td class=\"sha\">#{sha1}</td>\n"
48 download_html += "</tr>\n"
49 end
50 download_html += "<!-- END_DOWNLOADS -->"
51
52 downloads_page = File.read(DOWNLOADS_FILE)
53 matcher = /<!-- START_DOWNLOADS -->.*<!-- END_DOWNLOADS -->/m
54 downloads_page = downloads_page.sub(matcher, download_html)
55 File.open(DOWNLOADS_FILE, 'w') {|f| f.write(downloads_page)}
56 puts "rewrote that file"
57end
58
59fill_index_downloads