From f7aead95e4324fc020838eb16506f70a36e7f367 Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Tue, 6 Sep 2022 19:41:21 +0200 Subject: [PATCH] Add date-fns documentation (2.29.2) --- Gemfile | 1 + Gemfile.lock | 2 + assets/javascripts/news.json | 4 + .../templates/pages/about_tmpl.coffee | 5 + docs/file-scrapers.md | 12 ++ lib/docs/scrapers/date_fns.rb | 163 ++++++++++++++++++ public/icons/docs/date_fns/16.png | Bin 0 -> 849 bytes public/icons/docs/date_fns/16@2x.png | Bin 0 -> 1328 bytes public/icons/docs/date_fns/SOURCE | 2 + 9 files changed, 189 insertions(+) create mode 100755 lib/docs/scrapers/date_fns.rb create mode 100644 public/icons/docs/date_fns/16.png create mode 100644 public/icons/docs/date_fns/16@2x.png create mode 100644 public/icons/docs/date_fns/SOURCE diff --git a/Gemfile b/Gemfile index fa6189fd..ee87a784 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,7 @@ group :development do end group :docs do + gem 'redcarpet' gem 'progress_bar', require: false gem 'unix_utils', require: false gem 'tty-pager', require: false diff --git a/Gemfile.lock b/Gemfile.lock index a1dc6be9..5e1b329d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,6 +77,7 @@ GEM rb-fsevent (0.10.3) rb-inotify (0.10.0) ffi (~> 1.0) + redcarpet (3.5.1) rr (1.2.1) ruby2_keywords (0.0.5) sass (3.7.4) @@ -157,6 +158,7 @@ DEPENDENCIES rack-ssl-enforcer rack-test rake + redcarpet rr sass sinatra diff --git a/assets/javascripts/news.json b/assets/javascripts/news.json index d76b8b3f..8af6192b 100644 --- a/assets/javascripts/news.json +++ b/assets/javascripts/news.json @@ -1,4 +1,8 @@ [ + [ + "2022-09-06", + "New documentation: date-fns" + ], [ "2022-08-27", "New documentations: Sanctuary, Requests, Axios" diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index 365f20d9..103d3cbe 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -236,6 +236,11 @@ credits = [ '2012 the Dart project authors', 'CC BY-SA', 'https://creativecommons.org/licenses/by-sa/4.0/' + ], [ + 'date-fns', + '2021 Sasha Koss and Lesha Koss', + 'MIT', + 'https://raw.githubusercontent.com/date-fns/date-fns/main/LICENSE.md' ], [ 'Deno', '2018–2022 the Deno authors', diff --git a/docs/file-scrapers.md b/docs/file-scrapers.md index caeaa891..2b1843c5 100644 --- a/docs/file-scrapers.md +++ b/docs/file-scrapers.md @@ -26,6 +26,18 @@ Or run the following commands in your terminal: curl https://storage.googleapis.com/dart-archive/channels/stable/release/$RELEASE/api-docs/dartdocs-gen-api-zip > dartApi.zip; \ unzip dartApi.zip; mv gen-dartdocs docs/dart~$VERSION ``` + +## date-fns + +```sh +git clone https://github.com/date-fns/date-fns docs/date_fns +cd docs/date_fns +git checkout v2.29.2 +yarn install +node scripts/build/docs.js +ls tmp/docs.json +``` + ## Django Go to https://docs.djangoproject.com/, select the version from the diff --git a/lib/docs/scrapers/date_fns.rb b/lib/docs/scrapers/date_fns.rb new file mode 100755 index 00000000..db9d7902 --- /dev/null +++ b/lib/docs/scrapers/date_fns.rb @@ -0,0 +1,163 @@ +module Docs + class DateFns < FileScraper + self.name = 'date-fns' + self.slug = 'date_fns' + self.type = 'simple' + self.links = { + home: 'https://date-fns.org/', + code: 'https://github.com/date-fns/date-fns' + } + self.release = '2.29.2' + self.base_url = "https://date-fns.org/v#{self.release}/docs/" + + # https://github.com/date-fns/date-fns/blob/main/LICENSE.md + options[:attribution] = <<-HTML + © 2021 Sasha Koss and Lesha Koss
+ Licensed under the MIT License. + HTML + + def build_pages + markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, fenced_code_blocks: true, tables: true) + + md_files = %w(esm.md fp.md gettingStarted.md i18n.md i18nContributionGuide.md release.md timeZones.md unicodeTokens.md upgradeGuide.md webpack.md) + md_files.each do |md_file| + md_string = request_one("docs/#{md_file}").body + md_file = 'index.md' if md_file == 'gettingStarted.md' + name = md_string.match(/^#([^\n]+)/)[1] + path = md_file.sub '.md', '' + page = { + path: path, + store_path: "#{path}.html", + output: markdown.render(md_string), + entries: [Entry.new(name, path, 'General')] + } + yield page + end + + docs = JSON.parse(request_one('tmp/docs.json').body) + docs.each do |type, features| + features.each do |feature| + name = feature['title'] + feature_id = feature['urlId'] + next if feature_id.start_with?('fp/') + next if feature['type'] != 'jsdoc' + # fix description table on https://date-fns.org/v2.29.2/docs/parse + feature['content']['description'].sub! "\n| Unit", "\n\n| Unit" + feature['content']['description'].sub! "\nNotes:\n", "\n\nNotes:\n" + page = { + path: name, + store_path: "#{feature_id}.html", + output: ERB.new(PAGE_ERB).result(binding), + entries: [Entry.new(name, feature_id, type)] + } + yield page + end + end + end + + PAGE_ERB = <<-HTML.strip_heredoc +

<%= feature['title'] %>

+

<%= feature['description'] %>

+ +

Description

+

<%= markdown.render feature['content']['description'] %>

+ + <% if feature['usage'] %> +

Usage

+ <% feature['usage'].each do |_, usage| %> +
<%= '// ' + usage['title'] + '\n' %><%= usage['code'] %>
+ <% end %> + <% end %> + + <% if feature['syntax'] %> +

Syntax

+
<%= feature['syntax'] %>
+ <% end %> + + <% if feature['content']['properties'] %> +

Properties

+ + + + + + + <% feature['content']['properties'].each do |param| %> + + + + + + <% end %> +
NameTypeDescription
<%= param['name'] %><%= param['type']['names'].join ' ' %><%= markdown.render param['description'] || '' %>
+ <% end %> + + <% if feature['content']['params'] %> +

Arguments

+ + + + + + <% feature['content']['params'].each do |param| %> + + + + + <% end %> +
NameDescription
<%= param['name'] %><%= markdown.render param['description'] || '' %>
+ <% end %> + + <% if feature['content']['returns'] %> +

Returns

+ + + + + <% feature['content']['returns'].each do |param| %> + + + + <% end %> +
Description
<%= markdown.render param['description'] || '' %>
+ <% end %> + + <% if feature['content']['exceptions'] %> +

Exceptions

+ + + + + + <% feature['content']['exceptions'].each do |param| %> + + + + + <% end %> +
TypeDescription
<%= param['type']['names'].join ' ' %><%= markdown.render param['description'] || '' %>
+ <% end %> + + <% if feature['content']['examples'] %> +

Examples

+ <% feature['content']['examples'].each do |example| %> +
<%= example %>
+ <% end %> + <% end %> + +
+

+ <%= options[:attribution] %> +
+ + <%= self.base_url %><%= feature_id %> + +

+
+ HTML + + def get_latest_version(opts) + get_latest_github_release('date-fns', 'date-fns', opts) + end + end +end diff --git a/public/icons/docs/date_fns/16.png b/public/icons/docs/date_fns/16.png new file mode 100644 index 0000000000000000000000000000000000000000..f102d2e4bfc4941576c1312073d6162482d48d20 GIT binary patch literal 849 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbK}Scz*yNk~R%ZjzN%XpkpET4qkF zmA<}yZeB@Fe!6~IVp(Q#eqOP@k%6JPu7SC(k*R*Fd9q=WX_BR(p}B!^Qc_Zyv5AFQ zT8cqpvPnvEQj)nIP={VYUiuax&wii{Ea{HEjtmSN`?>!lvI6;x#X;^)4C~IxyaaL- zl0AZa85pY67#JE_7#My5g&JNkFq9fFFuY1&V6d9Oz#v{QXIG#NP=d3-BeEDsdw{Xq z$!t5IVIl!OA+F^-VdXrbWjtZo>>)r&Fc&B?qETV65-74`N`m}A@eB+qCKfh!4sKx) zQE_<%MI~hwHFXUw9X(?cQwvL1FW=yhu<(fJxcG#`q~w&;wDiof%IdlqGv_Z@wPDki z9XogL*?aWZ@l$6mT)uk!=IuMrp1*wa?)`_4pMN}7d-4oqdXl%hOU$bq4AX&}!=5gV zAr*|Q2icXG7#SQMs;@6_3lvw16x?)9PS8p_deOW8|M~B?uUfTAYr<`<#zQ%^TnTG_ z%52(T%d+$MZO#WT@>v&IC>RI7op<2L?NWw78J>{$r+fP+RBhsSS(~smcJVx!f@|?E ziz*h!dI!IYz3|3IdAGg(RuhqZ?=#A}PTYE3C8b%j)#82lgo`jFBr=wFvV!M)*E`9VDqP6!2X0!tdf~`FTGt>9WpQUcD8G)PDa<&-rVd#VfUc zB|56+{r3$7rIj)tt#6xX^VV$*SD@XKg$pj`e!uGXGJ5MSi3!_UR>g(@-NKmU?e5Z( z!+psa$bR7I;uvCadhO-R@XHPotPgg28T#fd^jaMxav^AXSo9r%4O>qHt!i*Ny7p32 zX?($9*6^6Xck|1PJUw*&9}Yb7%G#3nm52IdH#{s$uoz&tltCQ>}65(ku3f zvJWr#g)`&^9xKab+)(Xr{U&Hnvuy4L)^G2U)2BbVuq*lZ+*{X}Ilrmo)_xF>>^ouD z)L!Xwb=EAVl_r&6W_)e)nYQ=%RgWg&YYQaR{g?WE|LAk<*BW~tz87^DdJb;h`Da^k z$}R!+mE{3~jbgl6n=@pGOr{iOB>MsxOclZ-VB z-&$23zB!x8PcJ@y()Lq}N@i~^