diff options
author | Benjamin Ragheb <ben@benzado.com> | 2015-05-09 17:57:45 -0400 |
---|---|---|
committer | Benjamin Ragheb <ben@benzado.com> | 2015-05-09 17:57:45 -0400 |
commit | 1944a844a74312fb68277acae003da3b7d773162 (patch) | |
tree | 41799a156a5e91f3f31c6e0cbd66ac46b25c881a /src/index.rb |
Here is a script and a Makefile for generating a GNU Make docset for Dash.
Diffstat (limited to 'src/index.rb')
-rwxr-xr-x | src/index.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/index.rb b/src/index.rb new file mode 100755 index 0000000..c719fcc --- /dev/null +++ b/src/index.rb @@ -0,0 +1,27 @@ +require 'pathname' + +puts %Q[ + CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT); + CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path); +] + +INSERT_SQL = %Q[ + INSERT INTO searchIndex(name, type, path) VALUES ('%s','%s','%s'); +] + +PATTERN = %r[<title>GNU make: (.+)</title>] + +def quote(s) + s.gsub(/&/, '&').gsub(/'/, "\\'") +end + +ARGV.each do |arg| + Pathname.glob(arg) do |path| + match = path.each_line.lazy.map { |line| PATTERN.match(line) }.find { |m| m } + if match + printf INSERT_SQL, quote(match[1]), 'Guide', path.basename + else + $stderr.puts "%{path.basename}: no title found" + end + end +end |