From 018d09cc6db6c8d8dfe585a0ce0cef4b808a339e Mon Sep 17 00:00:00 2001 From: Sven Date: Mon, 8 Jan 2024 16:07:29 +0000 Subject: [PATCH] add Hammerspoon docs --- lib/docs/filters/hammerspoon/clean_html.rb | 32 ++++++++++ lib/docs/filters/hammerspoon/entries.rb | 71 +++++++++++++++++++++ lib/docs/scrapers/hammerspoon.rb | 32 ++++++++++ public/icons/docs/hammerspoon/16.png | Bin 0 -> 901 bytes public/icons/docs/hammerspoon/16@2x.png | Bin 0 -> 1417 bytes public/icons/docs/hammerspoon/SOURCE | 1 + 6 files changed, 136 insertions(+) create mode 100644 lib/docs/filters/hammerspoon/clean_html.rb create mode 100644 lib/docs/filters/hammerspoon/entries.rb create mode 100644 lib/docs/scrapers/hammerspoon.rb create mode 100644 public/icons/docs/hammerspoon/16.png create mode 100644 public/icons/docs/hammerspoon/16@2x.png create mode 100644 public/icons/docs/hammerspoon/SOURCE diff --git a/lib/docs/filters/hammerspoon/clean_html.rb b/lib/docs/filters/hammerspoon/clean_html.rb new file mode 100644 index 00000000..a7bbca97 --- /dev/null +++ b/lib/docs/filters/hammerspoon/clean_html.rb @@ -0,0 +1,32 @@ +module Docs + class Hammerspoon + class CleanHtmlFilter < Filter + def call + + # Remove script tags for functionality not needed in DevDocs + css("script").remove + + # Remove styles that are not necessary + css("style").remove + + # Modify the main title - remove leading "docs » " + at_css("h1").content = at_css("h1").content.sub("docs » ", "") + + # add syntax highlighting + css("pre").each do |pre| + if pre.get_attribute("lang") == "lua" + pre.set_attribute("data-language", "lua") + pre.remove_attribute("lang") + else + if pre.get_attribute("lang") + # logger.warn("unrecognised pre.get_attribute('lang') = #{pre.get_attribute("lang")}") + end + end + end + + doc + end + + end + end +end diff --git a/lib/docs/filters/hammerspoon/entries.rb b/lib/docs/filters/hammerspoon/entries.rb new file mode 100644 index 00000000..b3a5083f --- /dev/null +++ b/lib/docs/filters/hammerspoon/entries.rb @@ -0,0 +1,71 @@ +module Docs + class Hammerspoon + class EntriesFilter < Docs::EntriesFilter + def get_name + at_css("h1").content + end + + def get_type + subpath.split("/")[0] + end + + def additional_entries + return [] if root_page? + entries = [] + + base_name = at_css("h1").content + + # add a base entry + entries << [base_name, nil, base_name] + + css("section").each do |section| + title_node = section.at_css("h5") + if title_node.nil? + next + end + entry_name = title_node.content.strip + entry_id = section["id"] + + fn_type = section.at_css("a.dashAnchor").get_attribute("name") + # this dashAnchor is the most consistent way to get the type of the entry + if fn_type.start_with?("//apple_ref/cpp/Function") + fn_type = "Function" + entry_name << "()" + elsif fn_type.start_with?("//apple_ref/cpp/Constructor/") + fn_type = "Constructor" + entry_name << "()" + elsif fn_type.start_with?("//apple_ref/cpp/Method") + fn_type = "Method" + entry_name << "()" + elsif fn_type.start_with?("//apple_ref/cpp/Class") + fn_type = "Class" + elsif fn_type.start_with?("//apple_ref/cpp/Constant") + fn_type = "Constant" + elsif fn_type.start_with?("//apple_ref/cpp/Variable") + fn_type = "Variable" + elsif fn_type.start_with?("//apple_ref/cpp/Deprecated") + fn_type = "Deprecated" + elsif fn_type.start_with?("//apple_ref/cpp/Field") + fn_type = "Field" + else + fn_type = "Unknown" + end + + # Create a new entry for each method/function + if fn_type != "Unknown" + entries << ["#{base_name}.#{entry_name}", entry_id, base_name] + end + + end + + entries + end + + def include_default_entry? + # Decide when to include the default entry + # Here we include it unless the page is a module overview or similar + !subpath.end_with?("index.lp") + end + end + end +end diff --git a/lib/docs/scrapers/hammerspoon.rb b/lib/docs/scrapers/hammerspoon.rb new file mode 100644 index 00000000..e4ceae94 --- /dev/null +++ b/lib/docs/scrapers/hammerspoon.rb @@ -0,0 +1,32 @@ +module Docs + class Hammerspoon < UrlScraper + self.type = 'hammerspoon' + self.root_path = '' + self.links = { + home: 'https://www.hammerspoon.org', + code: 'https://github.com/Hammerspoon/hammerspoon' + } + + html_filters.push 'hammerspoon/clean_html', 'hammerspoon/entries' + + # links with no content will still render a page, this is an error in the docs + # (see: https://github.com/Hammerspoon/hammerspoon/pull/3579) + options[:skip] = ['module.lp/matrix.md'] + # Replace '/module.lp/' with '' in URLs + options[:replace_paths] = { 'localhost:12345/module.lp/MATRIX.md' => 'localhost:12345/module.lp/hs.canvas.matrix' } + + # Hammerspoon docs don't have a license (MIT specified in the hammerspoon repo) + # https://github.com/Hammerspoon/hammerspoon/blob/master/LICENSE + options[:attribution] = <<-HTML + Hammerspoon + HTML + + + version '0.9.100' do + self.release = '0.9.100' + # add `hs.doc.hsdocs.start()` to your init.lua to enable the docs server + self.base_url = 'http://localhost:12345/' + end + + end +end diff --git a/public/icons/docs/hammerspoon/16.png b/public/icons/docs/hammerspoon/16.png new file mode 100644 index 0000000000000000000000000000000000000000..b78dd7880f87eb6fd1f1f89123c2aeeedb19889c GIT binary patch literal 901 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!Lb6AYF9SoB8UsT^3j@P1pisjL z28L1t28LG&3=CE?7#PG0=IjczVPIg)4)6(a{SO4UlK$UH_y#VjQ=;W{@cV1Qnrct-_7_J$HKo}i~-v6`&wLFpmJ)M+MPW? z8IkHhzg*np2ef*6qlKZC(2OR_#9)DHb>LX zUU=JNz2B!C|DSjJf6?pzPNDz1#s2S=`oB-^{{f}{ht!HAgnX>|{~a>|`4{AD=Kq^n z|8M2^zm4br4*rWX_<1-O?k`sf3q}@hHf~QD8F!%2c25__5Q)pl2?w|&X3mI= zxOv0U;-HOQo*c8Ya8i-sG66c}Ib z_|bA?$rF*&SGJT$PH4z+OA9OW%ZuBW>bOwG!(kr>PnWmX=~JQ(OkG~C0SlI_VJh3b zDk^Z|uC`^W$G~hOrWag$8mn7yE ZV9{d;u_Wlv;|oAN44$rjF6*2UngEEKiYEX7 literal 0 HcmV?d00001 diff --git a/public/icons/docs/hammerspoon/16@2x.png b/public/icons/docs/hammerspoon/16@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..106b50b053f46fef047876ef954eeae53c88ec2f GIT binary patch literal 1417 zcmZ{kcTm#@6vuyI1{pyim?|g;vV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/docs/hammerspoon/SOURCE b/public/icons/docs/hammerspoon/SOURCE new file mode 100644 index 00000000..ff6491dc --- /dev/null +++ b/public/icons/docs/hammerspoon/SOURCE @@ -0,0 +1 @@ +https://www.hammerspoon.org/images/hammerspoon.ico \ No newline at end of file