/
Rakefile
123 lines (105 loc) · 3.16 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
121
122
require "nokogiri"
require 'tmpdir'
require "erb"
require "ostruct"
require "sqlite3"
require "rake/clean"
require "rake/packagetask"
task :default => :create_package
desc "Create a release"
task :release => [:create_package, :package, :create_release]
DOCSET = "jasmine.docset"
CONTENTS = "#{DOCSET}/Contents"
RESOURCES = "#{CONTENTS}/Resources"
HTML = "#{RESOURCES}/Documents"
PUBLIC = "public"
VERSION = "1.3.1"
CLOBBER.include DOCSET
# [ ] upload to github pages
Rake::PackageTask.new("jasmine-docset", "1.3.1") do |p|
p.need_tar = true
p.package_dir = PUBLIC
p.package_files.include("#{DOCSET}/*")
p.package_files.include("#{DOCSET}/**/*")
end
task :create_release do
url = "http://sideshowcoder.github.io/jasmine-docset/public/jasmine-docset-#{VERSION}.tgz"
feed_variables = OpenStruct.new(version: VERSION, url: url)
feed_template = File.read("./templates/feed.xml.erb")
feed = ERB.new(feed_template).result(feed_variables.instance_eval { binding })
File.open("#{PUBLIC}/Jasmine.xml", "w") { |f| f.write feed }
end
task :publish do
Dir.mktmpdir { |dir|
cp "public/jasmine-docset-#{VERSION}.tgz", dir
cp "public/Jasmine.xml", dir
`git checkout gh-pages`
cp "#{dir}/jasmine-docset-#{VERSION}.tgz", "public"
cp "#{dir}/Jasmine.xml", "public"
`git add -A`
current_commit = `git rev-parse --short HEAD`
`git commit -m 'updated to #{current_commit}'`
`git push origin gh-pages`
`git checkout master`
`git stash pop`
}
end
desc "Generate the docset package for jasmine"
task :create_package do
mkdir_p HTML
`wget --progress=dot --convert-links -p http://pivotal.github.io/jasmine/`
cp_r Dir["pivotal.github.io/jasmine/*"], HTML
cp "templates/Info.plist", CONTENTS
cp "templates/icon.png", DOCSET
db = "#{RESOURCES}/docSet.dsidx"
html_index = "#{HTML}/index.html"
touch db
SearchIndex.create_and_populate db, html_index
end
CLEAN.include "pivotal.github.io"
class SearchIndex
IGNORED_SECTIONS = [ "Downloads", "Support", "Thanks" ]
def initialize db_file
@db_file = db_file
end
def with_db
begin
db = SQLite3::Database.open @db_file
yield db
rescue SQLite3::Exception => e
puts "[ERROR] #{e}"
ensure
db.close if db
end
end
def self.create_and_populate(db_file, html_file)
search_index = new(db_file)
search_index.create
search_index.populate_with_content html_file
end
def create
with_db { |db|
db.execute "CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT)"
db.execute "CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path)"
}
end
def populate_with_content html_file
File.open(html_file, "r") { |f|
doc = Nokogiri::HTML(f.read)
populate_with doc
}
end
private
def populate_with doc
doc.css(".docs h2").each { |e|
next if IGNORED_SECTIONS.include? e.content
name = e.content.split(":")[0]
add_to_index name, "Section", "index.html##{e.parent.parent["id"]}"
}
end
def add_to_index name, type, path
with_db { |db|
db.execute "INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ('#{name}', '#{type}', '#{path}');\n"
}
end
end