History

Add date-fns documentation (2.29.2)

Simon Legner committed 4 years ago

Commit f7aead91 parent 20455679 files · +187 −-2Browse files

Unified · Split

9 files
  1. Gemfile +1 −0
  2. Gemfile.lock +2 −0
  3. assets/javascripts/news.json +4 −0
  4. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  5. docs/file-scrapers.md +12 −0
  6. lib/docs/scrapers/date_fns.rb +163 −0
  7. public/icons/docs/date_fns/16.png +0 −0
  8. public/icons/docs/date_fns/16@2x.png +0 −0
  9. public/icons/docs/date_fns/SOURCE +2 −0
Gemfile+1−0
@@ -39,6 +39,7 @@ group :development do · 38 unmodified lines
3939 end
4040
4141 group :docs do
42+ gem 'redcarpet'
4243 gem 'progress_bar', require: false
4344 gem 'unix_utils', require: false
4445 gem 'tty-pager', require: false
Gemfile.lock+2−0
@@ -77,6 +77,7 @@ GEM · 76 unmodified lines
7777 rb-fsevent (0.10.3)
7878 rb-inotify (0.10.0)
7979 ffi (~> 1.0)
80+ redcarpet (3.5.1)
8081 rr (1.2.1)
8182 ruby2_keywords (0.0.5)
8283 sass (3.7.4)
@@ -157,6 +158,7 @@ DEPENDENCIES · 74 unmodified lines
157158 rack-ssl-enforcer
158159 rack-test
159160 rake
161+ redcarpet
160162 rr
161163 sass
162164 sinatra
assets/javascripts/news.json+4−0
@@ -1,4 +1,8 @@
11 [
2+ [
3+ "2022-09-06",
4+ "New documentation: <a href=\"/date_fns/\">date-fns</a>"
5+ ],
26 [
37 "2022-08-27",
48 "New documentations: <a href=\"/sanctuary/\">Sanctuary</a>, <a href=\"/requests/\">Requests</a>, <a href=\"/axios/\">Axios</a>"
assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -236,6 +236,11 @@ credits = [ · 235 unmodified lines
236236 '2012 the Dart project authors',
237237 'CC BY-SA',
238238 'https://creativecommons.org/licenses/by-sa/4.0/'
239+ ], [
240+ 'date-fns',
241+ '2021 Sasha Koss and Lesha Koss',
242+ 'MIT',
243+ 'https://raw.githubusercontent.com/date-fns/date-fns/main/LICENSE.md'
239244 ], [
240245 'Deno',
241246 '2018–2022 the Deno authors',
docs/file-scrapers.md+12−0
@@ -26,6 +26,18 @@ Or run the following commands in your terminal: · 25 unmodified lines
2626 curl https://storage.googleapis.com/dart-archive/channels/stable/release/$RELEASE/api-docs/dartdocs-gen-api-zip > dartApi.zip; \
2727 unzip dartApi.zip; mv gen-dartdocs docs/dart~$VERSION
2828 ```
29+
30+## date-fns
31+
32+```sh
33+git clone https://github.com/date-fns/date-fns docs/date_fns
34+cd docs/date_fns
35+git checkout v2.29.2
36+yarn install
37+node scripts/build/docs.js
38+ls tmp/docs.json
39+```
40+
2941 ## Django
3042
3143 Go to https://docs.djangoproject.com/, select the version from the
lib/docs/scrapers/date_fns.rb+163−0
@@ -0,0 +1,163 @@
1+module Docs
2+ class DateFns < FileScraper
3+ self.name = 'date-fns'
4+ self.slug = 'date_fns'
5+ self.type = 'simple'
6+ self.links = {
7+ home: 'https://date-fns.org/',
8+ code: 'https://github.com/date-fns/date-fns'
9+ }
10+ self.release = '2.29.2'
11+ self.base_url = "https://date-fns.org/v#{self.release}/docs/"
12+
13+ # https://github.com/date-fns/date-fns/blob/main/LICENSE.md
14+ options[:attribution] = <<-HTML
15+ &copy; 2021 Sasha Koss and Lesha Koss<br>
16+ Licensed under the MIT License.
17+ HTML
18+
19+ def build_pages
20+ markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, fenced_code_blocks: true, tables: true)
21+
22+ md_files = %w(esm.md fp.md gettingStarted.md i18n.md i18nContributionGuide.md release.md timeZones.md unicodeTokens.md upgradeGuide.md webpack.md)
23+ md_files.each do |md_file|
24+ md_string = request_one("docs/#{md_file}").body
25+ md_file = 'index.md' if md_file == 'gettingStarted.md'
26+ name = md_string.match(/^#([^\n]+)/)[1]
27+ path = md_file.sub '.md', ''
28+ page = {
29+ path: path,
30+ store_path: "#{path}.html",
31+ output: markdown.render(md_string),
32+ entries: [Entry.new(name, path, 'General')]
33+ }
34+ yield page
35+ end
36+
37+ docs = JSON.parse(request_one('tmp/docs.json').body)
38+ docs.each do |type, features|
39+ features.each do |feature|
40+ name = feature['title']
41+ feature_id = feature['urlId']
42+ next if feature_id.start_with?('fp/')
43+ next if feature['type'] != 'jsdoc'
44+ # fix description table on https://date-fns.org/v2.29.2/docs/parse
45+ feature['content']['description'].sub! "\n| Unit", "\n\n| Unit"
46+ feature['content']['description'].sub! "\nNotes:\n", "\n\nNotes:\n"
47+ page = {
48+ path: name,
49+ store_path: "#{feature_id}.html",
50+ output: ERB.new(PAGE_ERB).result(binding),
51+ entries: [Entry.new(name, feature_id, type)]
52+ }
53+ yield page
54+ end
55+ end
56+ end
57+
58+ PAGE_ERB = <<-HTML.strip_heredoc
59+ <h1><%= feature['title'] %></h1>
60+ <p><%= feature['description'] %></p>
61+
62+ <h2>Description</h2>
63+ <p><%= markdown.render feature['content']['description'] %></p>
64+
65+ <% if feature['usage'] %>
66+ <h2>Usage</h2>
67+ <% feature['usage'].each do |_, usage| %>
68+ <pre data-language="javascript"><%= '// ' + usage['title'] + '\n' %><%= usage['code'] %></pre>
69+ <% end %>
70+ <% end %>
71+
72+ <% if feature['syntax'] %>
73+ <h2>Syntax</h2>
74+ <pre data-language="javascript"><%= feature['syntax'] %></pre>
75+ <% end %>
76+
77+ <% if feature['content']['properties'] %>
78+ <h2>Properties</h2>
79+ <table>
80+ <tr>
81+ <th>Name</th>
82+ <th>Type</th>
83+ <th>Description</th>
84+ </tr>
85+ <% feature['content']['properties'].each do |param| %>
86+ <tr>
87+ <td><code><%= param['name'] %></code></td>
88+ <td><code><%= param['type']['names'].join ' ' %></code></td>
89+ <td><%= markdown.render param['description'] || '' %></td>
90+ </tr>
91+ <% end %>
92+ </table>
93+ <% end %>
94+
95+ <% if feature['content']['params'] %>
96+ <h2>Arguments</h2>
97+ <table>
98+ <tr>
99+ <th>Name</th>
100+ <th>Description</th>
101+ </tr>
102+ <% feature['content']['params'].each do |param| %>
103+ <tr>
104+ <td><code><%= param['name'] %></code></td>
105+ <td><%= markdown.render param['description'] || '' %></td>
106+ </tr>
107+ <% end %>
108+ </table>
109+ <% end %>
110+
111+ <% if feature['content']['returns'] %>
112+ <h2>Returns</h2>
113+ <table>
114+ <tr>
115+ <th>Description</th>
116+ </tr>
117+ <% feature['content']['returns'].each do |param| %>
118+ <tr>
119+ <td><%= markdown.render param['description'] || '' %></td>
120+ </tr>
121+ <% end %>
122+ </table>
123+ <% end %>
124+
125+ <% if feature['content']['exceptions'] %>
126+ <h2>Exceptions</h2>
127+ <table>
128+ <tr>
129+ <th>Type</th>
130+ <th>Description</th>
131+ </tr>
132+ <% feature['content']['exceptions'].each do |param| %>
133+ <tr>
134+ <td><code><%= param['type']['names'].join ' ' %></code></td>
135+ <td><%= markdown.render param['description'] || '' %></td>
136+ </tr>
137+ <% end %>
138+ </table>
139+ <% end %>
140+
141+ <% if feature['content']['examples'] %>
142+ <h2>Examples</h2>
143+ <% feature['content']['examples'].each do |example| %>
144+ <pre data-language="javascript"><%= example %></pre>
145+ <% end %>
146+ <% end %>
147+
148+ <div class="_attribution">
149+ <p class="_attribution-p">
150+ <%= options[:attribution] %>
151+ <br>
152+ <a href="<%= self.base_url %><%= feature_id %>" class="_attribution-link">
153+ <%= self.base_url %><%= feature_id %>
154+ </a>
155+ </p>
156+ </div>
157+ HTML
158+
159+ def get_latest_version(opts)
160+ get_latest_github_release('date-fns', 'date-fns', opts)
161+ end
162+ end
163+end
public/icons/docs/date_fns/16.png+0−0

Binary file not shown.

public/icons/docs/date_fns/16@2x.png+0−0

Binary file not shown.

public/icons/docs/date_fns/SOURCE+2−0
@@ -0,0 +1,2 @@
1+https://date-fns.org/static/favicon-16x16.png
2+https://date-fns.org/static/favicon-32x32.png