From 09eea66d5769c8427a7f8aa1a6f3903c934166c3 Mon Sep 17 00:00:00 2001 From: Konstantin Zaitsev Date: Thu, 6 Jul 2017 01:14:22 +0700 Subject: [PATCH] Add Nim documentation --- assets/stylesheets/application-dark.css.scss | 1 + assets/stylesheets/application.css.scss | 1 + assets/stylesheets/pages/_nim.scss | 81 +++++++++++++++++++ lib/docs/filters/nim/clean_html.rb | 31 +++++++ lib/docs/filters/nim/entries.rb | 51 ++++++++++++ lib/docs/scrapers/nim.rb | 21 +++++ public/icons/docs/nim/16.png | Bin 0 -> 789 bytes public/icons/docs/nim/16@2x.png | Bin 0 -> 1949 bytes public/icons/docs/nim/SOURCE | 1 + 9 files changed, 187 insertions(+) create mode 100644 assets/stylesheets/pages/_nim.scss create mode 100644 lib/docs/filters/nim/clean_html.rb create mode 100644 lib/docs/filters/nim/entries.rb create mode 100644 lib/docs/scrapers/nim.rb create mode 100644 public/icons/docs/nim/16.png create mode 100644 public/icons/docs/nim/16@2x.png create mode 100644 public/icons/docs/nim/SOURCE diff --git a/assets/stylesheets/application-dark.css.scss b/assets/stylesheets/application-dark.css.scss index 8e719586..7cedbf59 100644 --- a/assets/stylesheets/application-dark.css.scss +++ b/assets/stylesheets/application-dark.css.scss @@ -67,6 +67,7 @@ 'pages/meteor', 'pages/modernizr', 'pages/moment', + 'pages/nim', 'pages/nginx', 'pages/node', 'pages/npm', diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index 21ce39a3..e909e005 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -67,6 +67,7 @@ 'pages/meteor', 'pages/modernizr', 'pages/moment', + 'pages/nim', 'pages/nginx', 'pages/node', 'pages/npm', diff --git a/assets/stylesheets/pages/_nim.scss b/assets/stylesheets/pages/_nim.scss new file mode 100644 index 00000000..590fb342 --- /dev/null +++ b/assets/stylesheets/pages/_nim.scss @@ -0,0 +1,81 @@ +._nim { + @extend %simple; + + @if $style == 'dark' { + span.DecNumber { color: #AE81FF; } + span.BinNumber { color: #AE81FF; } + span.HexNumber { color: #AE81FF; } + span.OctNumber { color: #AE81FF; } + span.FloatNumber { color: #AE81FF; } + span.Identifier { color: #F8F8F2; } + span.Keyword { font-weight: 600; color: #F92672; } + span.StringLit { color: #E6DB74; } + span.LongStringLit { color: #E6DB74; } + span.CharLit { color: #E6DB74; } + span.EscapeSequence { color: white; } + span.Operator { color: white; } + span.Punctuation {color: white; } + span.Comment, span.LongComment { + font-style: italic; + font-weight: 400; + color: #75715E; } + + span.RegularExpression { color: darkviolet; } + span.TagStart { color: #F92672; } + span.TagEnd { color: #F92672; } + span.Key { color: #AE81FF; } + span.Value { color: #AE81FF; } + span.RawData { color: #a4255b; } + span.Assembler { color: #AE81FF; } + span.Preprocessor { color: #AE81FF; } + span.Directive { color: #AE81FF; } + + span.Command, span.Rule, span.Hyperlink, span.Label, span.Reference, + span.Other { color: white; } + + /* Pop type, const, proc, and iterator defs in nim def blocks */ + dt pre > span.Identifier, dt pre > span.Operator { color: #529B2F; font-weight: 700; } + } @else { + span.DecNumber { color: #252dbe; } + span.BinNumber { color: #252dbe; } + span.HexNumber { color: #252dbe; } + span.OctNumber { color: #252dbe; } + span.FloatNumber { color: #252dbe; } + span.Identifier { color: #3b3b3b; } + span.Keyword { font-weight: 600; color: #5e8f60; } + span.StringLit { color: #a4255b; } + span.LongStringLit { color: #a4255b; } + span.CharLit { color: #a4255b; } + span.EscapeSequence { color: black; } + span.Operator { color: black; } + span.Punctuation {color: black; } + span.Comment, span.LongComment { + font-style: italic; + font-weight: 400; + color: #484a86; } + + span.RegularExpression { color: darkviolet; } + span.TagStart { color: darkviolet; } + span.TagEnd { color: darkviolet; } + span.Key { color: #252dbe; } + span.Value { color: #252dbe; } + span.RawData { color: #a4255b; } + span.Assembler { color: #252dbe; } + span.Preprocessor { color: #252dbe; } + span.Directive { color: #252dbe; } + + span.Command, span.Rule, span.Hyperlink, span.Label, span.Reference, + span.Other { color: black; } + + /* Pop type, const, proc, and iterator defs in nim def blocks */ + dt pre > span.Identifier, dt pre > span.Operator { color: #155da4; font-weight: 700; } + } + dt pre > span.Identifier ~ span.Identifier, dt pre > span.Operator ~ span.Identifier { + color: inherit; + font-weight: inherit; } + + dt pre > span.Operator ~ span.Identifier, dt pre > span.Operator ~ span.Operator { + color: inherit; + font-weight: inherit; } + +} diff --git a/lib/docs/filters/nim/clean_html.rb b/lib/docs/filters/nim/clean_html.rb new file mode 100644 index 00000000..3231f9eb --- /dev/null +++ b/lib/docs/filters/nim/clean_html.rb @@ -0,0 +1,31 @@ +module Docs + class Nim + class CleanHtmlFilter < Filter + def call + @doc = at_css('#documentId .container') + + css('.docinfo').remove + + content = at_css('#content') + if content != nil + at_css('#content').remove_attribute('class') + @doc.add_child(at_css('#content').inner_html) + end + + css('> div.row').remove + + css('pre').each do |node| + node['data-language'] = 'nim' + end + + # remove link from headers + css('h1 > a', 'h2 > a', 'h3 > a', 'h4 > a').each do |node| + node.parent['id'] = node['id'] + node.parent.content = node.content + end + + doc + end + end + end +end diff --git a/lib/docs/filters/nim/entries.rb b/lib/docs/filters/nim/entries.rb new file mode 100644 index 00000000..ddcd7522 --- /dev/null +++ b/lib/docs/filters/nim/entries.rb @@ -0,0 +1,51 @@ +module Docs + class Nim + class EntriesFilter < Docs::EntriesFilter + def get_type + at_css('h1').content + end + + def get_name + at_css('h1').content + end + + def additional_entries + entries = [] + if get_name.start_with? 'Module ' + module_name = get_name[7..-1] + css('div .section').map do |node| + section_node = node.at_css('h1 a') + if section_node != nil + section_name = section_node.content.strip + items_node = node.at_css('dl.item') + if items_node != nil + items_node.css('dt a').map do |item_node| + item_name = item_node['name'] + if item_name.include? ',' + item_name = item_name.sub(',', '(') + ')' + end + entries << [module_name + '.' + item_name, item_node.parent['id']] + end + end + end + end + else + css('h1', 'h2', 'h3').map do |node| + id = node['id'] + name = node.content.strip + if id != nil + entries << [name, id] + else + a = node.at_css('a') + if a != nil + id = a['id'] + entries << [name, id] + end + end + end + end + entries + end + end + end +end diff --git a/lib/docs/scrapers/nim.rb b/lib/docs/scrapers/nim.rb new file mode 100644 index 00000000..571c529a --- /dev/null +++ b/lib/docs/scrapers/nim.rb @@ -0,0 +1,21 @@ +module Docs + class Nim < UrlScraper + self.type = 'nim' + self.release = '0.17.0' + self.links = { + home: 'https://nim-lang.org/', + code: 'https://github.com/nim-lang/Nim' + } + self.base_url = 'https://nim-lang.org/' + self.root_path = 'docs/overview.html' + + html_filters.push 'nim/entries', 'nim/clean_html' + + options[:skip] = %w(cdn-cgi/l/email-protection docs/theindex.html docs/docgen.txt) + options[:attribution] = <<-HTML + © 2006–2017 Andreas Rumpf
+ All rights reserved. Licensed under the MIT License. + HTML + + end +end \ No newline at end of file diff --git a/public/icons/docs/nim/16.png b/public/icons/docs/nim/16.png new file mode 100644 index 0000000000000000000000000000000000000000..1945b395a7b163d571b929c3f7923b53dcc560b7 GIT binary patch literal 789 zcmV+w1M2*VP)N2bZe?^JG%heMF)~90YwQ330-{Mo zK~#9!rBhu<6j2!c+@gqH>P6{6B*GpNihAoYupa|;HQbl-r^v`P#+==q8J*dkb!T;T zXH^6tVbjglpTJ*Cu*7^RwWu^&x75-~A|$m`)=J5~?wyU2h!T1@!@1`>-??*V?gw_e z9sUP@Dav586=|US9|1DRvK_brH%L||h*B}(Wg53y72pY{nn>2vBg?-+wH+j@0}8|v zXz?W(T*dr$x62e+U6Hdt(6^_3w14-_Do<`4)o88LpO8uY5(&1EASiJP+xUV~Xs;E+u%^*# z(32y?RjN!hLClq^>_aWSsV9Ghas5DwsGAR99Y%9qEnr`Mu{33!(~enN^^>HScs=Gpo;Kh?!G> zwK(Zl*7bH7FZFiiFtRM`OhltKBjbUldP{sy8(*$MaivR#PB5f_ug znAaoDoCZt!mK$wV95pcW%{B>;n*u#vL&~)0{wVBjaisk9FcN34(I~slYCpdCs>iu~W*WZ15 zoh`(`2?{8RZIee8qsUpKoQiETPc&Mip7pcw$04F7$yx-3qC*4azc+4R8aIaTX1?xX Te1w~*00000NkvXXu0mjfUBqSE literal 0 HcmV?d00001 diff --git a/public/icons/docs/nim/16@2x.png b/public/icons/docs/nim/16@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..bd13ba65cf59cc1b728d7ea60073816abed8deaa GIT binary patch literal 1949 zcmV;O2V(e%P)N2bZe?^JG%heMF)~90YwQ332P#QK zK~#9!?N@tHRAm(Zb{Fh9Ha$>B%dDB~onvWJI#d18^cWwoyJ}&DqoSmk$RPW;`?&1g z<)QIV z^ZT9OcfPY9Bq1SzTumd_2>iQ1p71<-svHS+m9qYS2=GdBNUR6}sD$bGwYX=L)Dg}ov$Zr51Y%r}SIT_3EE69#`!eCxU1cx;^ zzy}IIl9LMmCg_#+M;k)Ae`7fM19OUV3 zA$=v=w6hJSbpVt!;Kx}L+0*6ZG-XAzbeNathpRBaOp#TC09hGPlP(`6;)&XjeYqPW zAI;8)np{>iJG{E=Dcgb1r)+Mnx~Jsg5h7k_CiHw0p+G{c-}T@-wdGSY+@&+PPYdUS z=VvZ{JTG&}lwQ69e1H_1)XVay#8U@uZE!fOY7Q`*fQ2Mb zY1qf8yHRR`DTQp=wD^hR-;Axopl&(2j{!lY-QTOc1Jeqxvd zb79UCwPUJL&3Nb^*qWg9^=m@N_Phntf8H13K2-TgE;wK4`+sTg;Pm%Y&O|nF=YciPUyMAYG6AE zu2jop^h=ELWJN{4BIgdP`XQ&cC@*|QoFR=sLvX?Iu>Vz` z%rJ;Qf<%p)UaSzE>UTYyUy!}%N$6Y^o@M_r#Ky%2vce$pKRM-iq7S}HNs7Ovq(B#X zv}R(3U$x&G)xD@vi+kb@v&99c&Kg8)wgi%xXuA#u4r!|y|2fLjS$}iOww#FRMsqR) zRF0@JgzOq+N~+k9VpGn}*6>}U3?YrpE)XLS;$Vinzjglep8A{Gd{CgL;l>|RQ`U@j zx$L9tc3wp+76)0MV!64pG$vGVm{g5>AIizuxO~!D|*(gg1S& zC>_C_f_)UL#%fI}!78n=T^N{=ZW&YOUMBcD zbX{OQb?(UIj5PCDj6omt^~V4ywb3jP-p-TSJ&`urJ%{FH877-K`FBRyUvPrp#+oIW z^x|xKrtQ^(9~8zuk5!l;7!8xBuII)cs$SyscFgOf=Rzs{O(z?yz3nZR#BK3E<8Rb`a5@6^0@+7(Kr4juKK*7r*tdI?Ql0}=SvduravufB+i`>=4$i(l`G z;!ZZbwwrpiKFled(fUe?VxL2D3ChpCdmmkZeYz~I%P$W411o{Qt`Cj>+96^pJ{#d5MV*GV)cCB&oOo^N>=)Q%*(WUF7=+) zUlu#`Ua@`95QHjV^fx^nYDh%+CMy1-Pl@yXs=q|f&!y!bthyM#QVJA9n9pu~hPe z_0ZqLsMM~P6a_?(TT&E|0zuifNJACCSlGrscg360oP~j_|KdtE^tQsQv6DAv#ozx^ z!y6w#LqamxPmfmKYXHFg4lw8q0F_t|ATTuX&yBC|+>#srm~x~?ycho2ZI|FV#_hlv zu`Pe?v~R1Irga^Ar3py%)2^_<=JYq6M=N$8U(njPZ*kUp1+g=&AUUcjTrr^j!L{6f zMZJ7F*dnh}h%2*hq@{u)2<(1!aD|Cj{yhe`n$ZbL4( j|MVY~YyTTwbpn3?(52U!3uiUi00000NkvXXu0mjf8qT`y literal 0 HcmV?d00001 diff --git a/public/icons/docs/nim/SOURCE b/public/icons/docs/nim/SOURCE new file mode 100644 index 00000000..ed29d859 --- /dev/null +++ b/public/icons/docs/nim/SOURCE @@ -0,0 +1 @@ +https://nim-lang.org/assets/img/logo.svg \ No newline at end of file