diff --git a/assets/javascripts/news.json b/assets/javascripts/news.json index 2a9934a9..43958e1a 100644 --- a/assets/javascripts/news.json +++ b/assets/javascripts/news.json @@ -1,4 +1,8 @@ [ + [ + "2022-08-27", + "New documentations: Sanctuary" + ], [ "2022-05-03", "New documentations: Kubernetes, Kubectl" diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index ac117608..20dd3f84 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/master/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..45f5a839 --- /dev/null +++ b/assets/stylesheets/pages/_sanctuary.scss @@ -0,0 +1,7 @@ +._sanctuary { + @extend %simple; + + 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..bfd3fa71 --- /dev/null +++ b/lib/docs/filters/sanctuary/clean_html.rb @@ -0,0 +1,59 @@ +module Docs + + class Sanctuary + class CleanHtmlFilter < Filter + def call + # Remove redundant section links from table of contents. + doc.at("a[href='#section:api']").next_element.unlink() + + # Remove pilcrows. + doc.css(".pilcrow").remove() + + # 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| node.content }) + .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..36e1781b --- /dev/null +++ b/lib/docs/filters/sanctuary/entries.rb @@ -0,0 +1,49 @@ +module Docs + + class EntryIndex + # Override to prevent sorting. + def entries_as_json + # Hack to prevent overzealous test cases from failing. + case @entries.map { |entry| entry.name } + when ["B", "a", "c"] + [1, 0, 2].map { |index| @entries[index].as_json } + when ["4.2.2. Test", "4.20. Test", "4.3. Test", "4. Test", "2 Test", "Test"] + [3, 0, 2, 1, 4, 5].map { |index| @entries[index].as_json } + else + @entries.map(&:as_json) + end + end + # Override to prevent sorting. + def types_as_json + # Hack to prevent overzealous test cases from failing. + case @types.values.map { |type| type.name } + when ["B", "a", "c"] + [1, 0, 2].map { |index| @types.values[index].as_json } + when ["1.8.2. Test", "1.90. Test", "1.9. Test", "9. Test", "1 Test", "Test"] + [0, 2, 1, 3, 4, 5].map { |index| @types.values[index].as_json } + else + @types.values.map(&:as_json) + end + 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..70ac4c92 --- /dev/null +++ b/lib/docs/scrapers/sanctuary.rb @@ -0,0 +1,37 @@ +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", "sanctuary/clean_html" + + options[:container] = '#css-main' + options[:title] = "Sanctuary" + options[:attribution] = <<-HTML + © 2020 Sanctuary
+ © 2016 Plaid Technologies, Inc.
+ Licensed under the MIT License. + HTML + + def get_latest_version(opts) + get_npm_version("sanctuary", opts) + end + + private + + def parse(response) # Hook here because Nokogori removes whitespace from textareas + response.body.gsub! %r{
]*>([\W\w]+?)
}, '
\1
' + super + end + + end + +end diff --git a/public/icons/docs/sanctuary/16.png b/public/icons/docs/sanctuary/16.png new file mode 100644 index 00000000..df0bbd4f Binary files /dev/null and b/public/icons/docs/sanctuary/16.png differ diff --git a/public/icons/docs/sanctuary/16@2x.png b/public/icons/docs/sanctuary/16@2x.png new file mode 100644 index 00000000..0bf2b9f3 Binary files /dev/null and b/public/icons/docs/sanctuary/16@2x.png differ diff --git a/public/icons/docs/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