From b97cfa6693f32fa883db015c9cf5ccb7a0dff169 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Wed, 31 Jan 2018 18:53:33 -0500 Subject: [PATCH] Add Koa --- lib/docs/filters/github/clean_html.rb | 2 +- lib/docs/filters/koa/clean_html.rb | 42 ++++++++++++++++++++++++++ lib/docs/filters/koa/entries.rb | 36 ++++++++++++++++++++++ lib/docs/scrapers/koa.rb | 38 +++++++++++++++++++++++ public/icons/docs/koa/16.png | Bin 0 -> 847 bytes public/icons/docs/koa/16@2x.png | Bin 0 -> 1549 bytes public/icons/docs/koa/SOURCE | 1 + 7 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 lib/docs/filters/koa/clean_html.rb create mode 100644 lib/docs/filters/koa/entries.rb create mode 100644 lib/docs/scrapers/koa.rb create mode 100644 public/icons/docs/koa/16.png create mode 100644 public/icons/docs/koa/16@2x.png create mode 100644 public/icons/docs/koa/SOURCE diff --git a/lib/docs/filters/github/clean_html.rb b/lib/docs/filters/github/clean_html.rb index 80c8ea99..4d6da240 100644 --- a/lib/docs/filters/github/clean_html.rb +++ b/lib/docs/filters/github/clean_html.rb @@ -9,7 +9,7 @@ module Docs css('.highlight > pre').each do |node| node['data-language'] = node.parent['class'][/highlight-source-(\w+)/, 1] - node.content = node.content.strip_heredoc.gsub(' ', ' ') + node.content = node.content.strip_heredoc node.parent.replace(node) end diff --git a/lib/docs/filters/koa/clean_html.rb b/lib/docs/filters/koa/clean_html.rb new file mode 100644 index 00000000..7fbbdcfe --- /dev/null +++ b/lib/docs/filters/koa/clean_html.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +module Docs + class Koa + class CleanHtmlFilter < Filter + def call + fix_homepage if slug.start_with? 'api/index' + + css('[data-language=shell]').each do |node| + node['data-language'] = 'bash' + end + + doc + end + + def fix_homepage + # Shrink the headers + for n in (1..5).to_a.reverse + css("h#{n}").each do |header| + header.name = "h#{n+1}" + end + end + + # Add an introduction + doc.children.before <<-HTML.strip_heredoc +

Koa

+ +

Introduction

+

+ Expressive HTTP middleware framework for node.js to make web applications and APIs more enjoyable to write. Koa's middleware stack flows in a stack-like manner, allowing you to perform actions downstream then filter and manipulate the response upstream. +

+

+ Only methods that are common to nearly all HTTP servers are integrated directly into Koa's small ~570 SLOC codebase. This includes things like content negotiation, normalization of node inconsistencies, redirection, and a few others. +

+

+ Koa is not bundled with any middleware. +

+ HTML + end + end + end +end diff --git a/lib/docs/filters/koa/entries.rb b/lib/docs/filters/koa/entries.rb new file mode 100644 index 00000000..83a03a56 --- /dev/null +++ b/lib/docs/filters/koa/entries.rb @@ -0,0 +1,36 @@ +module Docs + class Koa + class EntriesFilter < Docs::EntriesFilter + @root_type = 'Koa' + def get_name + at_css('h1').content + end + + def additional_entries + return [] unless slug.match?(/^api/) + type = get_name + css('h2, h3').to_a + .delete_if do |node| + node.content == 'API' || + (slug.include?('index') && !node.content.include?('.')) + end + .map do |node| + name = node.content.sub(/\(.*\)$/, '') + type = 'API' if type == @root_type && name.include?('.') + [name, node['id'], type] + end + end + + def get_type + case slug + when /^api\/index/ + 'API' + when /^api/ + get_name + else + 'Guides' + end + end + end + end +end diff --git a/lib/docs/scrapers/koa.rb b/lib/docs/scrapers/koa.rb new file mode 100644 index 00000000..92d48c36 --- /dev/null +++ b/lib/docs/scrapers/koa.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Docs + class Koa < Github + self.base_url = 'https://github.com/koajs/koa/blob/master/docs/' + self.release = '2.4.1' + + self.root_path = 'api/index.md' + self.initial_paths = %w[ + error-handling + faq + guide + koa-vs-express + migration + troubleshooting + api/index + api/context + api/request + api/response + ].map { |name| name + '.md' } + + self.links = { + home: 'https://koajs.com/', + code: 'https://github.com/koajs/koa' + } + + html_filters.push 'koa/clean_html', 'koa/entries' + + options[:skip] = %w[middleware.gif] + options[:trailing_slash] = false + options[:container] = '.markdown-body' + + options[:attribution] = <<-HTML + © 2017 Koa contributors
+ Licensed under the MIT License. + HTML + end +end diff --git a/public/icons/docs/koa/16.png b/public/icons/docs/koa/16.png new file mode 100644 index 0000000000000000000000000000000000000000..a4280f6911556d775da0ac4e88022a4093f63d98 GIT binary patch literal 847 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|I14-?iy0WW zg+Z8+Vb&Z8pn}NEkcg59UmvUF{9L`nl>DSry^7odplSvNn+hu+GdHy)QK2F?C$HG5 z!d3~a!V1U+3F|8Y3;nDA{o-C@9zzrKDK}xwt{K19`Se z86_nJR{Hwo<>h+i#(Mch>H3D2mX`VkM*2oZx=P7{9O-#x!EwNQn0$BtH5O0c3d|4@L;p!@;Rg)2@K?ZPZ!4!3&Ev9 zzW#?C1ZrdL_*KjrnZ@6I;(qeKUHapZc1A^~pk{^pAzV|-?wW79(a|Yne)HXzv$JQK zZ+@MzHhJ?y3%GL4yj{JTBVB|ua4^Gv=IyY+&Na$tSNoh&14w zEY|HR!^iHqDQc}io1)fKE|Ix1c{1)Di#S$>a2uw(Z(jd>Aq@Oi%^SOUCtK11AfjnEK zjFOT9D}DX)@^Za$W4-*MbbUihOG|wNBYh(yU7!lx;>x^|#0uTKVr7USFmqf|i<65o z3raHc^AtelCMM;Vme?vOfh>Xph&xL%(-1c06+^uR^q@XSM&D4+Kp$>4P^%3{)XKjo zGZknv$b36P8?Z_gF{nK@`XI}Z90TzwSQO}0J1!f2c(B=V`5aP@WME+N^>lFziQs%2 zc0YS^x=7u=XY9VSmlVb(o13a}t=3q}x3Vct@??>*mBxxeP@uC;t;LittV?|q;1dERrI z=X1>GhpxY#ePc$%sWt!fm;LvCpC{w-y!S-?&AprVB`XKsU*2mF5PoEqS4qhh@ySmSuY6abb$l%x!GyOpF05LkiyA@!wIL?iDbRb=p$dBypSR z(QYe4ijL&)Gf6kxf8T!m@kYiC{3ni71+AXAa9N*f$-3VDv`v}EO>^fay<^m= zNsp}3($aQ_Z1d@y(J;{?h5g>XSVQkvrlS+CLT(hP`B@Bij8lz$PuWg8`8ac1Tr$t=OA;$XxTfp(Km7N%eM_wJnsl|v zqERai8ha<6emZT^Msp3GQ~Z)C0cI+{n-1(ucUkbkfbGTm`(2CO`yb5C-+z3bEwe)G zu^BfvxX-yc!}&|_`5hOHFHBay%w!_-uKE1+rDtAgh;(J2+n}%1lrW+8_qRu@_3e-U z{A|x1W!z*ZUwvr#CQUCJ<}(cm(>h&*Zf~pAi4I@imz?t^{76#Z)QJ5_dKzy&My`CZ zZ{b4ThRvQ`8q59b8_n}4?I=tRy7uSQ+qXv_JczTY{uc8sqMpgjA#U$1cde=0q)TdQ znA-XIy)VylTdJH~vG=U>b+!YyLRasKp80mB@%@KyZpw#-pZ9VwDtUD!z2Z-W)cW}2 zsr@Cw9t#5|T$Gah8PyO}`RR$FkNZKAGbZ4GdV2n%sJnsVxeL39e(m_ z-8(nGDcgOdt!~d0jb$odo?rD&yJ`Jrv9bi0<7N?=uk|&`MhZt3e|&0lXXpC**X0~+ z%ho*Ke{bJi=Cm_s7;8QWypw(?XMgV5V!!p*@A0lJW2?Cwcb~OB`2b7y^~-4sVi}_! h=P=z!NtoQYpW)j(t2*ZeA7nsfw5O||%Q~loCIB+$q7MK7 literal 0 HcmV?d00001 diff --git a/public/icons/docs/koa/SOURCE b/public/icons/docs/koa/SOURCE new file mode 100644 index 00000000..a018af7f --- /dev/null +++ b/public/icons/docs/koa/SOURCE @@ -0,0 +1 @@ +https://github.com/github/explore/blob/db7f2f28385d413ba9e03a635009b3434c9710fc/topics/koa/koa.png