Browse Source

Add XPath documentation

Thibaut 11 years ago
parent
commit
7cade1d4fc

BIN
assets/images/icons.png


BIN
assets/images/icons@2x.png


+ 1 - 1
assets/javascripts/templates/pages/about_tmpl.coffee

@@ -108,7 +108,7 @@ credits = [
     'Apache',
     'https://raw.githubusercontent.com/apache/cordova-docs/master/LICENSE'
   ], [
-    'CSS<br>DOM<br>HTML<br>JavaScript',
+    'CSS<br>DOM<br>HTML<br>JavaScript<br>XPath',
     '2005-2014 Mozilla Developer Network and individual contributors',
     'CC BY-SA',
     'http://creativecommons.org/licenses/by-sa/2.5/'

+ 4 - 1
assets/javascripts/templates/pages/news_tmpl.coffee

@@ -32,7 +32,10 @@ newsItem = (date, news) ->
   result
 
 app.news = [
-  [ 1410048000000, # September 7, 2014
+  [ 1413158400000, # October 13, 2014
+    """ New <a href="/xpath/">XPath</a> documentation """,
+  ], [
+    1410048000000, # September 7, 2014
     """ Updated the HTML, CSS, JavaScript, and DOM documentations with additional content. """,
   ], [
     1407110400000, # August 4, 2014

+ 1 - 0
assets/stylesheets/global/_icons.scss

@@ -64,3 +64,4 @@
 ._icon-cordova:before       { background-position: 0 -10rem; }
 ._icon-markdown:before      { background-position: -1rem -10rem; }
 ._icon-django:before        { background-position: -2rem -10rem; }
+._icon-xpath:before         { background-position: -3rem -10rem; }

+ 30 - 0
lib/docs/filters/xpath/clean_html.rb

@@ -0,0 +1,30 @@
+module Docs
+  class Xpath
+    class CleanHtmlFilter < Filter
+      def call
+        root_page? ? root : other
+        doc
+      end
+
+      def root
+        if table = at_css('.topicpage-table')
+          table.after(table.css('td').children).remove
+        end
+      end
+
+      def other
+        css('div[style*="background: #f5f5f5;"]').remove
+
+        css('h3[id]').each do |node|
+          node.name = 'h2'
+        end
+
+        css('p').each do |node|
+          child = node.child
+          child = child.next while child && child.text? && child.content.blank?
+          child.remove if child.try(:name) == 'br'
+        end
+      end
+    end
+  end
+end

+ 22 - 0
lib/docs/filters/xpath/entries.rb

@@ -0,0 +1,22 @@
+module Docs
+  class Xpath
+    class EntriesFilter < Docs::EntriesFilter
+      def get_name
+        name = super
+        name.remove!('Axes.')
+        name << '()' if name.remove!('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

+ 16 - 0
lib/docs/scrapers/mdn/xpath.rb

@@ -0,0 +1,16 @@
+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

BIN
public/icons/docs/xpath/16.png


BIN
public/icons/docs/xpath/16@2x.png