From 6510b06a363c8b6badc930521da8d0d9ffaf72b1 Mon Sep 17 00:00:00 2001 From: David Chambers Date: Sun, 3 Jul 2022 18:15:00 +0200 Subject: [PATCH] add Sanctuary --- .../templates/pages/about_tmpl.coffee | 5 + assets/stylesheets/application.css.scss | 1 + assets/stylesheets/pages/_sanctuary.scss | 77 ++++++++++++++++ lib/docs/filters/sanctuary/clean_html.rb | 86 ++++++++++++++++++ lib/docs/filters/sanctuary/entries.rb | 33 +++++++ lib/docs/scrapers/sanctuary.rb | 25 +++++ public/icons/docs/sanctuary/16.png | Bin 0 -> 564 bytes public/icons/docs/sanctuary/16@2x.png | Bin 0 -> 1213 bytes public/icons/docs/sanctuary/SOURCE | 1 + 9 files changed, 228 insertions(+) create mode 100644 assets/stylesheets/pages/_sanctuary.scss create mode 100644 lib/docs/filters/sanctuary/clean_html.rb create mode 100644 lib/docs/filters/sanctuary/entries.rb create mode 100644 lib/docs/scrapers/sanctuary.rb create mode 100644 public/icons/docs/sanctuary/16.png create mode 100644 public/icons/docs/sanctuary/16@2x.png create mode 100644 public/icons/docs/sanctuary/SOURCE diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index ebadb1b3..ad87b37b 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -801,6 +801,11 @@ credits = [ '2021 SaltStack', 'Apache', 'https://raw.githubusercontent.com/saltstack/salt/develop/LICENSE' + ], [ + 'Sanctuary', + '2020 Sanctuary; 2016 Plaid Technologies, Inc.', + 'MIT', + 'https://raw.githubusercontent.com/sanctuary-js/sanctuary/v3.1.0/LICENSE' ], [ 'Sass', '2006-2020 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein', diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index b9f99a5f..66569d69 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -112,6 +112,7 @@ 'pages/rubydoc', 'pages/rust', 'pages/rxjs', + 'pages/sanctuary', 'pages/scala', 'pages/sinon', 'pages/socketio', diff --git a/assets/stylesheets/pages/_sanctuary.scss b/assets/stylesheets/pages/_sanctuary.scss new file mode 100644 index 00000000..a290499a --- /dev/null +++ b/assets/stylesheets/pages/_sanctuary.scss @@ -0,0 +1,77 @@ +._sanctuary { + @extend %simple; + + --base-font-size: 14px; + + --h2-padding-top: 0.5em; + --h2-line-height: 1.25rem; + --h2-padding-bottom: 0.5em; + --h2-border-bottom-width: 1px; + --h2-margin-bottom: 1em; + + --h3-padding-top: 1px; + --h3-line-height: 1.375rem; + --h3-padding-bottom: 2px; + --h3-border-bottom-width: 1px; + --h3-margin-bottom: 1em; + + --h4-padding-top: 0px; + --h4-line-height: calc(1.3 * var(--base-font-size)); + --h4-padding-bottom: 0px; + --h4-margin-bottom: 1em; + + padding-left: 32px; + + .pilcrow { + position: absolute; + display: block; + width: 24px; + text-align: center; + text-decoration: none; + font-weight: var(--bolderFontWeight); + color: #eee; + } + + .pilcrow:hover { + color: var(--linkColor); + } + + .pilcrow.h2 { + margin-left: -40px; + margin-top: calc(0px - (var(--h2-padding-top) + + var(--h2-line-height) + + var(--h2-padding-bottom) + + var(--h2-border-bottom-width) + + var(--h2-margin-bottom))); + padding: var(--h2-padding-top) 0 var(--h2-padding-bottom); + font-size: 1rem; + line-height: var(--h2-line-height); + } + + .pilcrow.h3 { + margin-left: -40px; + margin-top: calc(0px - (var(--h3-padding-top) + + var(--h3-line-height) + + var(--h3-padding-bottom) + + var(--h3-border-bottom-width) + + var(--h3-margin-bottom))); + padding: var(--h3-padding-top) 0 var(--h3-padding-bottom); + font-size: inherit; + line-height: var(--h3-line-height); + } + + .pilcrow.h4 { + margin-left: -24px; + margin-top: calc(0px - (var(--h4-padding-top) + + var(--h4-line-height) + + var(--h4-padding-bottom) + + var(--h4-margin-bottom))); + padding: var(--h4-padding-top) 0 var(--h4-padding-bottom); + font-size: inherit; + line-height: var(--h4-line-height); + } + + pre > code { + font-size: inherit; + } +} diff --git a/lib/docs/filters/sanctuary/clean_html.rb b/lib/docs/filters/sanctuary/clean_html.rb new file mode 100644 index 00000000..c76ea1c0 --- /dev/null +++ b/lib/docs/filters/sanctuary/clean_html.rb @@ -0,0 +1,86 @@ +def repeat(n, s) + Array.new(n, s).join("") +end + +def _(n) + repeat(n, " ") +end + +module Docs + + class Sanctuary + class CleanHtmlFilter < Filter + def call + # Remove header containing GitHub, Gitter, and Stack Overflow links. + doc.at("#css-header").unlink() + + # Remove redundant section links from table of contents. + doc.at("a[href='#section:api']").next_element.unlink() + + # Swap headings and accompanying pilcrows to aid positioning via CSS. + doc.css(".pilcrow").each { |node| node.next_element.after(node) } + + # Insert Fink link in place of logo. + doc.at("[id='section:sponsors'] ~ ul > li > p").prepend_child( + doc.document.create_element("a", "Fink", {"href" => "https://www.fink.no/"}) + ) + + # Convert code blocks to the correct structure for syntax highlighting. + doc.css("code[class^='language-']").each { |node| + node.parent.replace( + doc.document.create_element( + "pre", + node.content, + {"data-language" => node.attributes["class"].value.delete_prefix("language-")} + ) + ) + } + + # Convert interactive examples to straightforward code blocks. + doc.css(".examples").each { |node| + node.replace( + doc.document.create_element( + "pre", + node + .css("input") + .map { |node| "> " + node.attributes["value"].value } + .zip(node.css(".output").map { |node| + if node.content.start_with?("! Invalid value") + # XXX: Reinstate newlines and consecutive spaces. + content = node.content.dup() + content[ 15] = "\n\n" + content[ 68] = "\n" + _("add :: FiniteNumber -> ".size) + content[104] = "\n" + _("add :: FiniteNumber -> ".size + ("FiniteNumber".size - 1) / 2) + content[134] = "\n\n" + content[138] = _(2) + content[155] = "\n\n" + content[215] = "\n\n" + content[337] = "\n" + content + else + node.content + end + }) + .map { |pair| pair.join("\n") } + .join("\n\n"), + {"data-language" => "javascript"} + ) + ) + } + + # Remove example that requires interactivity. + pre = doc.at("[id='section:overview'] ~ pre") + p = pre.previous_element + if p.content == "Try changing words to [] in the REPL below. Hit return to re-evaluate." + p.unlink() + pre.unlink() + else + raise "Failed to find interactive example within overview section" + end + + doc + end + end + end + +end diff --git a/lib/docs/filters/sanctuary/entries.rb b/lib/docs/filters/sanctuary/entries.rb new file mode 100644 index 00000000..28985bb7 --- /dev/null +++ b/lib/docs/filters/sanctuary/entries.rb @@ -0,0 +1,33 @@ +module Docs + + class EntryIndex + # Override to prevent sorting. + def entries_as_json + @entries.map(&:as_json) + end + # Override to prevent sorting. + def types_as_json + @types.values.map(&:as_json) + end + end + + class Sanctuary + class EntriesFilter < Docs::EntriesFilter + def additional_entries + entries = [] + type = "" + css("h3, h4").each do |node| + case node.name + when "h3" + type = node.text + when "h4" + name = id = node.attributes["id"].value + entries << [name, id, type] + end + end + return entries + end + end + end + +end diff --git a/lib/docs/scrapers/sanctuary.rb b/lib/docs/scrapers/sanctuary.rb new file mode 100644 index 00000000..1f2a41dc --- /dev/null +++ b/lib/docs/scrapers/sanctuary.rb @@ -0,0 +1,25 @@ +module Docs + + class Sanctuary < UrlScraper + self.name = "Sanctuary" + self.slug = "sanctuary" + self.type = "sanctuary" + self.release = "3.1.0" + self.base_url = "https://sanctuary.js.org/" + self.links = { + home: "https://sanctuary.js.org/", + code: "https://github.com/sanctuary-js/sanctuary", + } + + html_filters.push("sanctuary/entries") + html_filters.push("sanctuary/clean_html") + + options[:title] = "Sanctuary" + options[:attribution] = "Licensed under the MIT License." + + def get_latest_version(opts) + get_npm_version("sanctuary", opts) + end + end + +end diff --git a/public/icons/docs/sanctuary/16.png b/public/icons/docs/sanctuary/16.png new file mode 100644 index 0000000000000000000000000000000000000000..df0bbd4f6294ce35b1cd30a7c6fe8c85b675c9fa GIT binary patch literal 564 zcmV-40?Yl0P)vqhTN0++z+pkRU_dYm=F|!f;0zv{c23&NLV%p} zpx_6RI{aQ%8FX1I){83Bnx)NzJa7jav^y$@3l3N85Lu76QhtG0(4|joT&J@^Mjf6B zwiPm`l`HcEoA4dGaYD*q9HquuXYR-w%R470sBmQS-{gK1wBZXph@g_ zQLnLbL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/sanctuary/SOURCE b/public/icons/docs/sanctuary/SOURCE new file mode 100644 index 00000000..4aba6a0d --- /dev/null +++ b/public/icons/docs/sanctuary/SOURCE @@ -0,0 +1 @@ +https://github.com/sanctuary-js/sanctuary-logo/tree/v1.1.0