diff --git a/lib/docs/filters/cyclejs/clean_html.rb b/lib/docs/filters/cyclejs/clean_html.rb new file mode 100644 index 0000000000..cfafee84b9 --- /dev/null +++ b/lib/docs/filters/cyclejs/clean_html.rb @@ -0,0 +1,23 @@ +module Docs + class Cyclejs + class CleanHtmlFilter < Filter + def call + return "

Cycle.js

A functional and reactive JavaScript framework for predictable code

" if root_page? + css('br').remove + + css('pre > code').each do |node| + parent = node.parent + parent['data-language'] = 'javascript' + parent.content = node.content.strip + end + + css('table[style]', 'tr[style]', 'td[style]', 'th[style]').remove_attr('style') + css('img').each do |node| + node['alt'] = node['alt'].presence || '' + end + + doc + end + end + end +end diff --git a/lib/docs/filters/cyclejs/entries.rb b/lib/docs/filters/cyclejs/entries.rb new file mode 100644 index 0000000000..b7149201c3 --- /dev/null +++ b/lib/docs/filters/cyclejs/entries.rb @@ -0,0 +1,27 @@ +module Docs + class Cyclejs + class EntriesFilter < Docs::EntriesFilter + def get_name + title = at_css('h1') + name = title ? title.content.strip : subpath.sub(/\.html\z/, '').titleize + name = 'Cycle.js' if root_page? + name = 'API Reference' if slug == 'api/index' + name.delete_suffix! ' - source' + name + end + + def get_type + slug.start_with?('api/') ? 'API' : 'Guide' + end + + def additional_entries + css('h2[id], h3[id]').map do |node| + name = node.content.strip + name.sub!(/\A#\s*/, '') + name.sub!(/\s+#\z/, '') + [get_name + ': ' + name, node['id']] + end + end + end + end +end diff --git a/lib/docs/scrapers/cyclejs.rb b/lib/docs/scrapers/cyclejs.rb new file mode 100644 index 0000000000..284e4f50e7 --- /dev/null +++ b/lib/docs/scrapers/cyclejs.rb @@ -0,0 +1,85 @@ +require 'redcarpet' + +module Docs + class Cyclejs < UrlScraper + self.name = 'Cycle.js' + self.slug = 'cyclejs' + self.type = 'cyclejs' + self.release = '23.1.0' + self.base_url = 'https://cycle.js.org/' + self.root_path = 'index.html' + self.initial_paths = %w( + getting-started.html + model-view-intent.html + streams.html + drivers.html + components.html + basic-examples.html + dialogue.html + releases.html + api/index.html + api/run.html + api/rxjs-run.html + api/most-run.html + api/dom.html + api/html.html + api/http.html + api/history.html + api/isolate.html + api/state.html + ) + + self.links = { + home: 'https://cycle.js.org/', + code: 'https://github.com/cyclejs/cyclejs' + } + + html_filters.push 'cyclejs/clean_html', 'cyclejs/entries' + + options[:only_patterns] = [ + /\Aindex\.html\z/, + /\Agetting-started\.html\z/, + /\Amodel-view-intent\.html\z/, + /\Astreams\.html\z/, + /\Adrivers\.html\z/, + /\Acomponents\.html\z/, + /\Abasic-examples\.html\z/, + /\Adialogue\.html\z/, + /\Areleases\.html\z/, + /\Aapi\// + ] + + options[:download_images] = false + options[:attribution] = <<-HTML + © 2014–present Cycle.js contributors.
+ Licensed under the MIT License. + HTML + + def get_latest_version(opts) + get_npm_version('@cycle/dom', opts) + end + + private + + def parse(response) + document = Parser.new(response.body).html + markdown = document.at_css('script#markdown') + + return super unless markdown + + html = markdown_renderer.render(markdown.content.strip) + title = document.at_css('title').try(:content).try(:strip) + [Parser.new("#{title}#{html}").html, title] + end + + def markdown_renderer + @markdown_renderer ||= Redcarpet::Markdown.new( + Redcarpet::Render::HTML.new(with_toc_data: true), + autolink: true, + fenced_code_blocks: true, + no_intra_emphasis: true, + tables: true + ) + end + end +end diff --git a/public/icons/docs/cyclejs/16.png b/public/icons/docs/cyclejs/16.png new file mode 100644 index 0000000000..b870a7a678 Binary files /dev/null and b/public/icons/docs/cyclejs/16.png differ diff --git a/public/icons/docs/cyclejs/16@2x.png b/public/icons/docs/cyclejs/16@2x.png new file mode 100644 index 0000000000..7e8be668a4 Binary files /dev/null and b/public/icons/docs/cyclejs/16@2x.png differ diff --git a/public/icons/docs/cyclejs/SOURCE b/public/icons/docs/cyclejs/SOURCE new file mode 100644 index 0000000000..eb89497c99 --- /dev/null +++ b/public/icons/docs/cyclejs/SOURCE @@ -0,0 +1 @@ +https://cycle.js.org/img/cyclejs_logo.svg