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 %>
Name Type Description
<%= param['name'] %> <%= param['type']['names'].join ' ' %> <%= markdown.render param['description'] || '' %>
<% end %> <% if feature['content']['params'] %>

Arguments

<% feature['content']['params'].each do |param| %> <% end %>
Name Description
<%= 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 %>
Type Description
<%= 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