Browse Source

Add Moment.js documentation

Thibaut 11 years ago
parent
commit
032457e527

BIN
assets/images/icons.png


BIN
assets/images/icons@2x.png


+ 5 - 0
assets/javascripts/templates/pages/about_tmpl.coffee

@@ -143,6 +143,11 @@ credits = [
     '2009-2013 The Dojo Foundation',
     'MIT',
     'https://raw.github.com/lodash/lodash/master/LICENSE.txt'
+  ], [
+    'Moment.js',
+    '2011-2014 Tim Wood, Iskren Chernev, Moment.js contributors',
+    'MIT',
+    'https://raw.github.com/moment/moment/master/LICENSE'
   ], [
     'Node.js',
     'Joyent, Inc. and other Node contributors<br>Node.js is a trademark of Joyent, Inc.',

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

@@ -24,7 +24,10 @@ newsItem = (date, news) ->
   result
 
 app.news = [
-  [ 1392163200000, # February 12, 2013
+  [ 1392508800000, # February 16, 2013
+    """ New <a href="/moment/">Moment.js</a> documentation """,
+  ], [
+    1392163200000, # February 12, 2013
     """ The root/category pages are now included in the search index (e.g. <a href="/#q=CSS">CSS</a>) """,
   ], [
     1390694400000, # January 26, 2013

+ 6 - 0
assets/javascripts/views/pages/moment.coffee

@@ -0,0 +1,6 @@
+#= require views/pages/base
+
+class app.views.MomentPage extends app.views.BasePage
+  afterRender: ->
+    @highlightCode @findAll('pre'), 'javascript'
+    return

+ 1 - 0
assets/stylesheets/application.css.scss

@@ -37,6 +37,7 @@
         'pages/less',
         'pages/lodash',
         'pages/mdn',
+        'pages/moment',
         'pages/node',
         'pages/php',
         'pages/postgres',

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

@@ -47,3 +47,4 @@
 ._icon-postgresql:before    { background-position: -3rem -6rem; }
 ._icon-d3:before            { background-position: -4rem -6rem; }
 ._icon-knockout:before      { background-position: 0 -7rem; }
+._icon-moment:before        { background-position: -1rem -7rem; }

+ 7 - 0
assets/stylesheets/pages/_moment.scss

@@ -0,0 +1,7 @@
+._moment {
+  > h2 { @extend %block-heading; }
+  > h3 { @extend %block-label, %label-blue; }
+  > h3 > span { float: right;}
+  h4 { font-size: 1em; }
+  code { @extend %label; }
+}

+ 26 - 0
lib/docs/filters/moment/clean_html.rb

@@ -0,0 +1,26 @@
+module Docs
+  class Moment
+    class CleanHtmlFilter < Filter
+      def call
+        # Set id attributes on headings
+        css('a.target').each do |node|
+          node.next_element['id'] = node['name'].sub(/\A\//, '').sub(/\/\z/, '').gsub('/', '-')
+        end
+
+        css('> article', '.prose', 'h2 > a', 'h3 > a', 'pre > code').each do |node|
+          node.before(node.children).remove
+        end
+
+        # Remove introduction
+        doc.child.remove while doc.child['id'] != 'parsing'
+
+        # Remove plugin list
+        doc.children.last.remove while doc.children.last['id'] != 'plugins'
+
+        css('.hash', '#plugins').remove
+
+        doc
+      end
+    end
+  end
+end

+ 46 - 0
lib/docs/filters/moment/entries.rb

@@ -0,0 +1,46 @@
+module Docs
+  class Moment
+    class EntriesFilter < Docs::EntriesFilter
+      IGNORE_IDS = %w(
+        i18n-loading-into-nodejs
+        i18n-loading-into-browser
+        i18n-adding-language
+        i18n-getting-language)
+
+      def additional_entries
+        entries = []
+        type = nil
+
+        css('[id]').each do |node|
+          if node.name == 'h2'
+            type = node.content
+            next
+          end
+
+          next if IGNORE_IDS.include?(node['id'])
+
+          if node['id'] == 'utilities-invalid' # bug fix
+            name = 'moment.invalid()'
+          elsif %w(Display Durations Get\ +\ Set i18n Manipulate Query Utilities).include?(type) ||
+                %w(parsing-is-valid parsing-parse-zone parsing-unix-timestamp parsing-utc).include?(node['id'])
+            name = node.next_element.content[/moment(?:\(.*?\))?\.(?:duration\(\)\.)?\w+/]
+            name.sub! %r{\(.*?\)\.}, '#'
+            name << '()'
+          elsif type == 'Customize'
+            name = node.next_element.content[/moment.lang\(.+?\{\s+(\w+)/, 1]
+            name.prepend 'Language#'
+          else
+            name = node.content.strip
+            name.sub! %r{\s[\d\.]+\z}, '' # remove version number
+            name.sub! %r{\s\(.+\)\z}, ''  # remove parenthesis
+            name.prepend 'Parse: ' if type == 'Parse'
+          end
+
+          entries << [name, node['id'], type]
+        end
+
+        entries
+      end
+    end
+  end
+end

+ 20 - 0
lib/docs/scrapers/moment.rb

@@ -0,0 +1,20 @@
+module Docs
+  class Moment < UrlScraper
+    self.name = 'Moment.js'
+    self.slug = 'moment'
+    self.type = 'moment'
+    self.version = '2.5.1'
+    self.base_url = 'http://momentjs.com/docs/'
+
+    html_filters.push 'moment/clean_html', 'moment/entries', 'title'
+
+    options[:title] = 'Moment.js'
+    options[:container] = '.docs'
+    options[:skip_links] = true
+
+    options[:attribution] = <<-HTML
+      &copy; 2011&ndash;2014 Tim Wood, Iskren Chernev, Moment.js contributors<br>
+      Licensed under the MIT License.
+    HTML
+  end
+end

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


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