| @@ -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 | © 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 |