From 9b4f4c2ef4e104c47a4e1639a6701dd681b4f002 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 27 Mar 2016 16:16:51 -0400 Subject: [PATCH] Add XSLT to XPath doc --- assets/javascripts/app/app.coffee | 1 + assets/stylesheets/global/_icons.scss | 2 +- lib/app.rb | 3 ++- lib/docs/filters/mdn/clean_html.rb | 3 ++- lib/docs/filters/xpath/entries.rb | 22 --------------- .../{xpath => xslt_xpath}/clean_html.rb | 4 +-- lib/docs/filters/xslt_xpath/entries.rb | 27 +++++++++++++++++++ lib/docs/scrapers/mdn/xpath.rb | 16 ----------- lib/docs/scrapers/mdn/xslt_xpath.rb | 21 +++++++++++++++ 9 files changed, 56 insertions(+), 43 deletions(-) delete mode 100644 lib/docs/filters/xpath/entries.rb rename lib/docs/filters/{xpath => xslt_xpath}/clean_html.rb (91%) create mode 100644 lib/docs/filters/xslt_xpath/entries.rb delete mode 100644 lib/docs/scrapers/mdn/xpath.rb create mode 100644 lib/docs/scrapers/mdn/xslt_xpath.rb diff --git a/assets/javascripts/app/app.coffee b/assets/javascripts/app/app.coffee index 76639d71..08fbd9fe 100644 --- a/assets/javascripts/app/app.coffee +++ b/assets/javascripts/app/app.coffee @@ -101,6 +101,7 @@ for slug in @settings.getDocs() when not @docs.findBy('slug', slug) needsSaving = true doc = @disabledDocs.findBy('slug', 'node~4_lts') if slug == 'node~4.2_lts' + doc = @disabledDocs.findBy('slug', 'xslt_xpath') if slug == 'xpath' doc ||= @disabledDocs.findBy('slug_without_version', slug) if doc @disabledDocs.remove(doc) diff --git a/assets/stylesheets/global/_icons.scss b/assets/stylesheets/global/_icons.scss index 68f368e6..36ebc702 100644 --- a/assets/stylesheets/global/_icons.scss +++ b/assets/stylesheets/global/_icons.scss @@ -75,7 +75,7 @@ ._icon-cordova:before { background-position: 0 -5rem; } ._icon-markdown:before { background-position: -1rem -5rem; @extend %darkIconFix !optional; } ._icon-django:before { background-position: -2rem -5rem; } -._icon-xpath:before { background-position: -3rem -5rem; } +._icon-xslt_xpath:before { background-position: -3rem -5rem; } ._icon-nginx:before, ._icon-nginx_lua_module:before { background-position: -4rem -5rem; } ._icon-svg:before { background-position: -5rem -5rem; } diff --git a/lib/app.rb b/lib/app.rb index d8d05333..9c619944 100644 --- a/lib/app.rb +++ b/lib/app.rb @@ -273,7 +273,8 @@ class App < Sinatra::Application DOC_REDIRECTS = { 'iojs' => 'node', 'yii1' => 'yii~1.1', - 'python2' => 'python~2.7' + 'python2' => 'python~2.7', + 'xpath' => 'xslt_xpath' } get %r{\A/([\w~\.]+)(\-[\w\-]+)?(/.*)?\z} do |doc, type, rest| diff --git a/lib/docs/filters/mdn/clean_html.rb b/lib/docs/filters/mdn/clean_html.rb index 6214ba02..834955bf 100644 --- a/lib/docs/filters/mdn/clean_html.rb +++ b/lib/docs/filters/mdn/clean_html.rb @@ -9,7 +9,8 @@ module Docs '.todo', '.draftHeader', '.hidden', - '.button.section-edit'] + '.button.section-edit', + 'hr'] def call css(*REMOVE_NODES).remove diff --git a/lib/docs/filters/xpath/entries.rb b/lib/docs/filters/xpath/entries.rb deleted file mode 100644 index d07f2f86..00000000 --- a/lib/docs/filters/xpath/entries.rb +++ /dev/null @@ -1,22 +0,0 @@ -module Docs - class Xpath - class EntriesFilter < Docs::EntriesFilter - def get_name - name = super - name.remove!('Axes.') - name << '()' if name.gsub!('Functions.', '') - name - end - - def get_type - if slug.start_with?('Axes') - 'Axes' - elsif slug.start_with?('Functions') - 'Functions' - else - 'Miscellaneous' - end - end - end - end -end diff --git a/lib/docs/filters/xpath/clean_html.rb b/lib/docs/filters/xslt_xpath/clean_html.rb similarity index 91% rename from lib/docs/filters/xpath/clean_html.rb rename to lib/docs/filters/xslt_xpath/clean_html.rb index 6e3ee759..82096b20 100644 --- a/lib/docs/filters/xpath/clean_html.rb +++ b/lib/docs/filters/xslt_xpath/clean_html.rb @@ -1,8 +1,8 @@ module Docs - class Xpath + class XsltXpath class CleanHtmlFilter < Filter def call - root_page? ? root : other + initial_page? ? root : other doc end diff --git a/lib/docs/filters/xslt_xpath/entries.rb b/lib/docs/filters/xslt_xpath/entries.rb new file mode 100644 index 00000000..5151246f --- /dev/null +++ b/lib/docs/filters/xslt_xpath/entries.rb @@ -0,0 +1,27 @@ +module Docs + class XsltXpath + class EntriesFilter < Docs::EntriesFilter + def get_name + name = super + name.remove! 'XPath.' + name.remove! 'XSLT.' + name.remove! 'Axes.' + name.prepend 'xsl:' if slug =~ /\AXSLT\/[a-z]/ + name << '()' if name.gsub!('Functions.', '') + name + end + + def get_type + if slug =~ /\AXSLT\/[a-z]/ + 'XSLT Elements' + elsif slug.start_with?('XPath/Axes') + 'XPath Axes' + elsif slug.start_with?('XPath/Functions') + 'XPath Functions' + else + 'Miscellaneous' + end + end + end + end +end diff --git a/lib/docs/scrapers/mdn/xpath.rb b/lib/docs/scrapers/mdn/xpath.rb deleted file mode 100644 index fd2d486c..00000000 --- a/lib/docs/scrapers/mdn/xpath.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Docs - class Xpath < Mdn - self.name = 'XPath' - self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/XPath' - - html_filters.push 'xpath/clean_html', 'xpath/entries', 'title' - - options[:root_title] = 'XPath' - - options[:fix_urls] = ->(url) do - url.sub! 'https://developer.mozilla.org/en/XPath', Xpath.base_url - url.sub! 'https://developer.mozilla.org/en-US/docs/XPath', Xpath.base_url - url - end - end -end diff --git a/lib/docs/scrapers/mdn/xslt_xpath.rb b/lib/docs/scrapers/mdn/xslt_xpath.rb new file mode 100644 index 00000000..8d781e65 --- /dev/null +++ b/lib/docs/scrapers/mdn/xslt_xpath.rb @@ -0,0 +1,21 @@ +module Docs + class XsltXpath < Mdn + self.name = 'XSLT & XPath' + self.slug = 'xslt_xpath' + self.base_url = 'https://developer.mozilla.org/en-US/docs/Web' + self.root_path = '/XSLT' + self.initial_paths = %w(/XPath) + + html_filters.push 'xslt_xpath/clean_html', 'xslt_xpath/entries', 'title' + + options[:only_patterns] = [/\A\/XSLT/, /\A\/XPath/] + + options[:fix_urls] = ->(url) do + url.sub! 'https://developer.mozilla.org/en/XPath', "#{XsltXpath.base_url}/XPath" + url.sub! 'https://developer.mozilla.org/en/XSLT', "#{XsltXpath.base_url}/XSLT" + url.sub! 'https://developer.mozilla.org/en-US/docs/XPath', "#{XsltXpath.base_url}/XPath" + url.sub! 'https://developer.mozilla.org/en-US/docs/XSLT', "#{XsltXpath.base_url}/XSLT" + url + end + end +end