From c6da1d0c23d2d5c85781bdb7bac8e84728612f2b Mon Sep 17 00:00:00 2001 From: Phil Scherer Date: Fri, 18 Dec 2015 00:32:45 -0500 Subject: [PATCH] Add Perl documentation --- assets/javascripts/views/pages/perl.coffee | 6 ++ assets/stylesheets/application-dark.css.scss | 1 + assets/stylesheets/application.css.scss | 1 + assets/stylesheets/pages/_perl.scss | 12 ++++ lib/docs/filters/perl/clean_html.rb | 49 ++++++++++++++ lib/docs/filters/perl/entries.rb | 67 +++++++++++++++++++ lib/docs/scrapers/perl.rb | 35 ++++++++++ public/icons/docs/perl/16.png | Bin 0 -> 1244 bytes public/icons/docs/perl/16@2x.png | Bin 0 -> 636 bytes public/icons/docs/perl/SOURCE | 1 + 10 files changed, 172 insertions(+) create mode 100644 assets/javascripts/views/pages/perl.coffee create mode 100644 assets/stylesheets/pages/_perl.scss create mode 100644 lib/docs/filters/perl/clean_html.rb create mode 100644 lib/docs/filters/perl/entries.rb create mode 100644 lib/docs/scrapers/perl.rb create mode 100644 public/icons/docs/perl/16.png create mode 100644 public/icons/docs/perl/16@2x.png create mode 100644 public/icons/docs/perl/SOURCE diff --git a/assets/javascripts/views/pages/perl.coffee b/assets/javascripts/views/pages/perl.coffee new file mode 100644 index 00000000..4630ffe9 --- /dev/null +++ b/assets/javascripts/views/pages/perl.coffee @@ -0,0 +1,6 @@ +#= require views/pages/base + +class app.views.PerlPage extends app.views.BasePage + prepare: -> + @highlightCode @findAllByTag('pre'), 'perl' + return diff --git a/assets/stylesheets/application-dark.css.scss b/assets/stylesheets/application-dark.css.scss index dade560c..2c9148f2 100644 --- a/assets/stylesheets/application-dark.css.scss +++ b/assets/stylesheets/application-dark.css.scss @@ -59,6 +59,7 @@ 'pages/nginx', 'pages/node', 'pages/npm', + 'pages/perl', 'pages/phalcon', 'pages/phaser', 'pages/php', diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index 37931d7d..e17817e0 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -59,6 +59,7 @@ 'pages/nginx', 'pages/node', 'pages/npm', + 'pages/perl', 'pages/phalcon', 'pages/phaser', 'pages/php', diff --git a/assets/stylesheets/pages/_perl.scss b/assets/stylesheets/pages/_perl.scss new file mode 100644 index 00000000..98402adf --- /dev/null +++ b/assets/stylesheets/pages/_perl.scss @@ -0,0 +1,12 @@ +._perl { + + h2 { @extend %block-heading; } + h3 { @extend %block-label; } + h4 { @extend %block-label, %label-blue; } + + .perlvar, + .perlfunction { + @extend %block-label, %label-blue; + } + +} diff --git a/lib/docs/filters/perl/clean_html.rb b/lib/docs/filters/perl/clean_html.rb new file mode 100644 index 00000000..017e9a8e --- /dev/null +++ b/lib/docs/filters/perl/clean_html.rb @@ -0,0 +1,49 @@ +module Docs + class Perl + class CleanHtmlFilter < Filter + REMOVE_LIST = %w( + noscript + #recent_pages + #from_search + #page_index + .mod_az_list + ) + + def call + root_page? ? root : other + end + + def root + doc.inner_html = '

Perl 5 Documentation

' + end + + def other + @doc = at_css('#content_body') + + css(*REMOVE_LIST).remove + + css('h4').each { |node| node.name = 'h5' } + css('h3').each { |node| node.name = 'h4' } + css('h2').each { |node| node.name = 'h3' } + css('h1').drop(1).each { |node| node.name = 'h2' } + + css('a[name] + h2', 'a[name] + h3', 'a[name] + h4', 'a[name] + h5').each do |node| + node['id'] = node.previous_element['name'] + end + + css('li > a[name]').each do |node| + node.parent['id'] = node['name'] + end + + css('pre').each do |node| + node.css('li').each do |li| + li.content = li.content + "\n" + end + node.content = node.content + end + + doc + end + end + end +end diff --git a/lib/docs/filters/perl/entries.rb b/lib/docs/filters/perl/entries.rb new file mode 100644 index 00000000..710f18e5 --- /dev/null +++ b/lib/docs/filters/perl/entries.rb @@ -0,0 +1,67 @@ +module Docs + class Perl + class EntriesFilter < Docs::EntriesFilter + REPLACE_TYPES = { + 'Platform specific' => 'Platform Specific', + 'Internals and C language interface' => 'Internals', + + 'perlop' => 'Perl Operators', + 'perlvar' => 'Perl Variables', + 'Functions' => 'Functions' + } + + def breadcrumbs + at_css('#breadcrumbs').content.split('>').each { |s| s.strip! } + end + + def include_default_entry? + not slug =~ /\Aindex/ and + not slug =~ /perlop\z/ and + not slug =~ /perlvar/ + end + + def get_name + at_css('h1').content.strip + end + + def get_type + case breadcrumbs[1] + when 'Language reference' + REPLACE_TYPES[breadcrumbs[2]] || 'Language Reference' + when /\ACore modules/ + 'Core Modules' + else + REPLACE_TYPES[breadcrumbs[1]] || breadcrumbs[1] + end + end + + def additional_entries + entries = [] + case slug + when /perlop\z/ + css('h2').each do |node| + name = node.content + id = node.previous_element['name'] + entries << [name, id, get_type] + end + + when /perlvar/ + css('#content_body > ul > li > b').each do |node| + node['class'] = 'perlvar' + name = node.content + id = node.previous_element['name'] + entries << [name, id, get_type] + end + + when /functions/ + css('#content_body > ul > li > b').each do |node| + node['class'] = 'perlfunction' + end + + end + + entries + end + end + end +end diff --git a/lib/docs/scrapers/perl.rb b/lib/docs/scrapers/perl.rb new file mode 100644 index 00000000..9ca0ce70 --- /dev/null +++ b/lib/docs/scrapers/perl.rb @@ -0,0 +1,35 @@ +module Docs + class Perl < FileScraper + self.name = 'Perl' + self.type = 'perl' + self.release = '5.22.0' + self.dir = '' + self.base_url = 'http://perldoc.perl.org/' + self.root_path = 'index.html' + self.links = { + home: 'https://www.perl.org/' + } + + html_filters.push 'perl/entries', 'perl/clean_html' + + options[:skip] = %w( + preferences.html + perlartistic.html + perlgpl.html + perlhist.html + perltodo.html + perlunifaq.html + ) + + options[:skip_patterns] = [ + /\.pdf/, + /delta\.html/, + /\Aperlfaq/ + ] + + options[:attribution] = <<-HTML + © 2010–2015
+ Dual Licensed under the GNU General Public License version 1+ or the Artistic License. + HTML + end +end diff --git a/public/icons/docs/perl/16.png b/public/icons/docs/perl/16.png new file mode 100644 index 0000000000000000000000000000000000000000..1c6ad84c32ec39c5d877defb6bc210c48e845a8e GIT binary patch literal 1244 zcmZ`(drVVj6#tMhHW#7`b51uF*)nl+jP}w37VIogDRgZqU`5`gz2zlzl$OF^P)vb> z6{%Uv!?wUg9-SgnBu;sZk!*nAm?)3&ki`idi8vU6L1@`w{Ix%JbMJY5zwx0m)+ThQ^=v!M`>+2iC!;jT!1CN*Q>zfe}kj~>3 ztJPOVMrJIQO|#itUS4>WT%F62M>fb6=Eg%8&FB13jOULo^LZQ;rb31V-=;f7E zU*Bf2Snl4vPo;`?c;J-9%8iXJlFKjZbf&Xsl@v0adDkQQnkFi zwz&AGUjMCLeRZ#YI*i-J|#tsVFDUW z91~Lz94uzDQzIjl7cN|li#zY*lLAPU%Cx+^IyYwqX1EEFD5O#o*lZb0)7>4mLcn5W zXtmqRv$C>w@7|zHW`I6;c_mV*iO^Ws#*vZHjg3vqK94b2Vw-qofIm{%IWfSomj<%v z_Omwc*g5T5&~>N5@f(5uw6M2E1aa^P<3)U2FhBcyJhDxDH-?&LLv!Z8&L!@Rjq(i% zia5z*$I!TeX9^2wr&!T`q0GpD)0`*Y5BH5Ldmar={qS($*B?h8%=G-yKT+88cxbwJ zj}ZauI=ZlonCzf!@5%x9gdt-uK|Zr- z_u78fn44emCzkgeJ$+piek*f&!{Keu)R~*I$yFzB`Eya+_$~PptF8SWC#qy+e96&; zW;`a_7@WwMcZ=$ft`D42$!|n=r~ftj+*|%)+FpWQjPo^q{9OysvJa&6aH)_l#VG;_ z4hmreBH5LQxe`6Xh$ITZgF?bwK@tf5kz&(-5>my&BvJPNCy-wrdlM24Y*z>si==YC k1V=QXI37O~n95JULvX$@JG~!=Uk*ZnbhdwsZ``?m0Lz6TA^-pY literal 0 HcmV?d00001 diff --git a/public/icons/docs/perl/16@2x.png b/public/icons/docs/perl/16@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..016daf7e571af3419ea69414ddbc7aeca527efca GIT binary patch literal 636 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyEa{HEjtmUfZd~z?Faq)=OI#yL zg7ec#$`gxH85~pclTsBta}(23gHjVyDhp4h+5i<91o(uw{{R2~%$YMYX9Cg8v@{?} zGd4~Giv9mT^Z$P!!}$My1`zMeng3^I{y&qpOZT)a0|VnFPZ!6Kid#tu4h(K-Vq#`t zVq$7;Dvk{dP6}yZW)=ylP29{Z0x?orN11||j9C>L7PK8M-F(0|vC)H(MPQbVH1{qp zpyJ8yVGMzc0uBl-O8rY3dL=bD1soh&*0fJ$y=k1|FrA4--~yA%{f!$8jg1wnr#CVx zG)&-4NK8sjOH6Sr6H;b&U@$Z|VCmzqS>mQdqt=XxcYykNd_GKIJY~FbL!-^n7K0X` zo&>WE4R;P5;`k`V&25t+$;ia<%Duy8!eJIpi5*;O4Gc*RK^&V{gjf|OE4XcDU=d(8 zahc)J6{+}-shwBZr48tM2>~{ToWurc#%(P?o&uLbkwX4~CV36EZ}Qv@42s$bPC*Bl z$^oU=3!x5Ve7`hk@}3!%~NbeQB&WczGBYSvs}VHt0)EkUh!6rx?ZtROuq7 zeS|MWLYHtMhR$w1P5n+LR1p#%9Mm8N0lhBR~RRywFYoh0z>z-#Q~SIO|xDAJuJ9I zKsn-Ku{zMPJdWoC)|@FQ1S)Xzc@V>VM(Tv5xWWO3eq-MK6-I^ez?8w@>FVdQ&MBb@ E0JR9#-~a#s literal 0 HcmV?d00001 diff --git a/public/icons/docs/perl/SOURCE b/public/icons/docs/perl/SOURCE new file mode 100644 index 00000000..9e2313c2 --- /dev/null +++ b/public/icons/docs/perl/SOURCE @@ -0,0 +1 @@ +http://www.perlfoundation.org/perl_trademark