History

add Hammerspoon docs

Sven committed 2 years ago

Commit 018d09c1 parent 9a5b70c6 files · +134 −-2Browse files

Unified · Split

6 files
  1. lib/docs/filters/hammerspoon/clean_html.rb +32 −0
  2. lib/docs/filters/hammerspoon/entries.rb +71 −0
  3. lib/docs/scrapers/hammerspoon.rb +32 −0
  4. public/icons/docs/hammerspoon/16.png +0 −0
  5. public/icons/docs/hammerspoon/16@2x.png +0 −0
  6. public/icons/docs/hammerspoon/SOURCE +1 −0
lib/docs/filters/hammerspoon/clean_html.rb+32−0
@@ -0,0 +1,32 @@
1+module Docs
2+ class Hammerspoon
3+ class CleanHtmlFilter < Filter
4+ def call
5+
6+ # Remove script tags for functionality not needed in DevDocs
7+ css("script").remove
8+
9+ # Remove styles that are not necessary
10+ css("style").remove
11+
12+ # Modify the main title - remove leading "docs » "
13+ at_css("h1").content = at_css("h1").content.sub("docs » ", "")
14+
15+ # add syntax highlighting
16+ css("pre").each do |pre|
17+ if pre.get_attribute("lang") == "lua"
18+ pre.set_attribute("data-language", "lua")
19+ pre.remove_attribute("lang")
20+ else
21+ if pre.get_attribute("lang")
22+ # logger.warn("unrecognised pre.get_attribute('lang') = #{pre.get_attribute("lang")}")
23+ end
24+ end
25+ end
26+
27+ doc
28+ end
29+
30+ end
31+ end
32+end
lib/docs/filters/hammerspoon/entries.rb+71−0
@@ -0,0 +1,71 @@
1+module Docs
2+ class Hammerspoon
3+ class EntriesFilter < Docs::EntriesFilter
4+ def get_name
5+ at_css("h1").content
6+ end
7+
8+ def get_type
9+ subpath.split("/")[0]
10+ end
11+
12+ def additional_entries
13+ return [] if root_page?
14+ entries = []
15+
16+ base_name = at_css("h1").content
17+
18+ # add a base entry
19+ entries << [base_name, nil, base_name]
20+
21+ css("section").each do |section|
22+ title_node = section.at_css("h5")
23+ if title_node.nil?
24+ next
25+ end
26+ entry_name = title_node.content.strip
27+ entry_id = section["id"]
28+
29+ fn_type = section.at_css("a.dashAnchor").get_attribute("name")
30+ # this dashAnchor is the most consistent way to get the type of the entry
31+ if fn_type.start_with?("//apple_ref/cpp/Function")
32+ fn_type = "Function"
33+ entry_name << "()"
34+ elsif fn_type.start_with?("//apple_ref/cpp/Constructor/")
35+ fn_type = "Constructor"
36+ entry_name << "()"
37+ elsif fn_type.start_with?("//apple_ref/cpp/Method")
38+ fn_type = "Method"
39+ entry_name << "()"
40+ elsif fn_type.start_with?("//apple_ref/cpp/Class")
41+ fn_type = "Class"
42+ elsif fn_type.start_with?("//apple_ref/cpp/Constant")
43+ fn_type = "Constant"
44+ elsif fn_type.start_with?("//apple_ref/cpp/Variable")
45+ fn_type = "Variable"
46+ elsif fn_type.start_with?("//apple_ref/cpp/Deprecated")
47+ fn_type = "Deprecated"
48+ elsif fn_type.start_with?("//apple_ref/cpp/Field")
49+ fn_type = "Field"
50+ else
51+ fn_type = "Unknown"
52+ end
53+
54+ # Create a new entry for each method/function
55+ if fn_type != "Unknown"
56+ entries << ["#{base_name}.#{entry_name}", entry_id, base_name]
57+ end
58+
59+ end
60+
61+ entries
62+ end
63+
64+ def include_default_entry?
65+ # Decide when to include the default entry
66+ # Here we include it unless the page is a module overview or similar
67+ !subpath.end_with?("index.lp")
68+ end
69+ end
70+ end
71+end
lib/docs/scrapers/hammerspoon.rb+32−0
@@ -0,0 +1,32 @@
1+module Docs
2+ class Hammerspoon < UrlScraper
3+ self.type = 'hammerspoon'
4+ self.root_path = ''
5+ self.links = {
6+ home: 'https://www.hammerspoon.org',
7+ code: 'https://github.com/Hammerspoon/hammerspoon'
8+ }
9+
10+ html_filters.push 'hammerspoon/clean_html', 'hammerspoon/entries'
11+
12+ # links with no content will still render a page, this is an error in the docs
13+ # (see: https://github.com/Hammerspoon/hammerspoon/pull/3579)
14+ options[:skip] = ['module.lp/matrix.md']
15+ # Replace '/module.lp/' with '' in URLs
16+ options[:replace_paths] = { 'localhost:12345/module.lp/MATRIX.md' => 'localhost:12345/module.lp/hs.canvas.matrix' }
17+
18+ # Hammerspoon docs don't have a license (MIT specified in the hammerspoon repo)
19+ # https://github.com/Hammerspoon/hammerspoon/blob/master/LICENSE
20+ options[:attribution] = <<-HTML
21+ Hammerspoon
22+ HTML
23+
24+
25+ version '0.9.100' do
26+ self.release = '0.9.100'
27+ # add `hs.doc.hsdocs.start()` to your init.lua to enable the docs server
28+ self.base_url = 'http://localhost:12345/'
29+ end
30+
31+ end
32+end
public/icons/docs/hammerspoon/16.png+0−0

Binary file not shown.

public/icons/docs/hammerspoon/16@2x.png+0−0

Binary file not shown.

public/icons/docs/hammerspoon/SOURCE+1−0
@@ -0,0 +1 @@
1+https://www.hammerspoon.org/images/hammerspoon.ico