Skip to content

Commit 55b0da7

Browse files
authored
Merge pull request #2108 from supersational/hammerspoon
add Hammerspoon docs
2 parents e63a1d2 + db4037b commit 55b0da7

File tree

7 files changed

+141
-0
lines changed

7 files changed

+141
-0
lines changed

assets/javascripts/news.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
[
2+
[
3+
"2024-01-12",
4+
"New documentation: <a href=\"/hammerspoon/\">Hammerspoon</a>"
5+
],
26
[
37
"2024-01-05",
48
"New documentation: <a href=\"/bazel/\">Bazel</a>"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Docs
2+
class Hammerspoon
3+
class CleanHtmlFilter < Filter
4+
def call
5+
6+
at_css("#search").parent.remove if at_css("#search")
7+
8+
# Remove script tags for functionality not needed in DevDocs
9+
css("script").remove
10+
11+
# Remove styles that are not necessary
12+
css("style").remove
13+
14+
# Modify the main title - remove leading "docs » "
15+
at_css("h1").content = at_css("h1").content.sub("docs » ", "")
16+
17+
# add syntax highlighting
18+
css("pre").each do |pre|
19+
if pre.get_attribute("lang") == "lua"
20+
pre.set_attribute("data-language", "lua")
21+
pre.remove_attribute("lang")
22+
else
23+
if pre.get_attribute("lang")
24+
# logger.warn("unrecognised pre.get_attribute('lang') = #{pre.get_attribute("lang")}")
25+
end
26+
end
27+
end
28+
29+
doc
30+
end
31+
32+
end
33+
end
34+
end
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
slug.split("/").first
10+
end
11+
12+
def additional_entries
13+
return [] if root_page?
14+
entries = []
15+
16+
# add a base entry
17+
entries << [name, nil, name]
18+
19+
css("section").each do |section|
20+
title_node = section.at_css("h5")
21+
if title_node.nil?
22+
next
23+
end
24+
entry_name = title_node.content.strip
25+
entry_id = section["id"]
26+
27+
fn_type = section.at_css("a.dashAnchor").get_attribute("name")
28+
# this dashAnchor is the most consistent way to get the type of the entry
29+
if fn_type.start_with?("//apple_ref/cpp/Function")
30+
fn_type = "Function"
31+
entry_name << "()"
32+
elsif fn_type.start_with?("//apple_ref/cpp/Constructor/")
33+
fn_type = "Constructor"
34+
entry_name << "()"
35+
elsif fn_type.start_with?("//apple_ref/cpp/Method")
36+
fn_type = "Method"
37+
entry_name << "()"
38+
elsif fn_type.start_with?("//apple_ref/cpp/Class")
39+
fn_type = "Class"
40+
elsif fn_type.start_with?("//apple_ref/cpp/Constant")
41+
fn_type = "Constant"
42+
elsif fn_type.start_with?("//apple_ref/cpp/Variable")
43+
fn_type = "Variable"
44+
elsif fn_type.start_with?("//apple_ref/cpp/Deprecated")
45+
fn_type = "Deprecated"
46+
elsif fn_type.start_with?("//apple_ref/cpp/Field")
47+
fn_type = "Field"
48+
else
49+
fn_type = "Unknown"
50+
end
51+
52+
# Create a new entry for each method/function
53+
if fn_type != "Unknown"
54+
entries << ["#{name}.#{entry_name}", entry_id, name]
55+
end
56+
57+
end
58+
59+
entries
60+
end
61+
62+
def include_default_entry?
63+
# Decide when to include the default entry
64+
# Here we include it unless the page is a module overview or similar
65+
!subpath.end_with?("index.lp")
66+
end
67+
end
68+
end
69+
end

lib/docs/scrapers/hammerspoon.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
self.base_url = 'https://www.hammerspoon.org/docs/'
10+
self.release = '0.9.100'
11+
12+
html_filters.push 'hammerspoon/clean_html', 'hammerspoon/entries'
13+
14+
# links with no content will still render a page, this is an error in the docs
15+
# (see: https://github.com/Hammerspoon/hammerspoon/pull/3579)
16+
options[:skip] = ['module.lp/matrix.md']
17+
options[:skip_patterns] = [
18+
/LuaSkin/,
19+
]
20+
21+
# Hammerspoon docs don't have a license (MIT specified in the hammerspoon repo)
22+
# https://github.com/Hammerspoon/hammerspoon/blob/master/LICENSE
23+
options[:attribution] = <<-HTML
24+
&copy; 2014–2017 Hammerspoon contributors<br>
25+
Licensed under the MIT License.
26+
HTML
27+
28+
def get_latest_version(opts)
29+
get_latest_github_release('Hammerspoon', 'hammerspoon', opts)
30+
end
31+
32+
end
33+
end

public/icons/docs/hammerspoon/16.png

901 Bytes
Loading
1.38 KB
Loading

public/icons/docs/hammerspoon/SOURCE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://www.hammerspoon.org/images/hammerspoon.ico

0 commit comments

Comments
 (0)