Browse Source

Add RequireJS documentation

Thibaut 11 years ago
parent
commit
ec0e9f0b44

BIN
assets/images/icons.png


BIN
assets/images/icons@2x.png


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

@@ -210,6 +210,11 @@ credits = [
     '2009-2014 Salvatore Sanfilippo',
     'CC BY-SA',
     'http://creativecommons.org/licenses/by-sa/4.0/'
+  ], [
+    'RequireJS',
+    '2010-2014 The Dojo Foundation',
+    'MIT',
+    'https://raw.githubusercontent.com/jrburke/requirejs/master/LICENSE'
   ], [
     'Ruby',
     '1993-2014 Yukihiro Matsumoto',

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

@@ -24,7 +24,10 @@ newsItem = (date, news) ->
   result
 
 app.news = [
-  [ 1402704000000, # June 14, 2014
+  [ 1402790400000, # June 15, 2014
+    """ New <a href="/requirejs/">RequireJS</a> documentation """,
+  ], [
+    1402704000000, # June 14, 2014
     """ New <a href="/haskell/">Haskell</a> documentation """,
   ], [
     1400976000000, # May 25, 2014

+ 11 - 0
assets/javascripts/views/pages/requirejs.coffee

@@ -0,0 +1,11 @@
+#= require views/pages/base
+
+class app.views.RequirejsPage extends app.views.BasePage
+  afterRender: ->
+    for el in @findAllByTag 'pre'
+      language = if el.textContent.match(/^\s*</)
+        'markup'
+      else
+        'javascript'
+      @highlightCode el, language
+    return

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

@@ -51,6 +51,7 @@
         'pages/postgres',
         'pages/rdoc',
         'pages/redis',
+        'pages/requirejs',
         'pages/rfc',
         'pages/sphinx',
         'pages/underscore',

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

@@ -58,3 +58,4 @@
 ._icon-maxcdn:before        { background-position: -4rem -8rem; }
 ._icon-laravel:before       { background-position: 0 -9rem; }
 ._icon-haskell:before       { background-position: -1rem -9rem; }
+._icon-requirejs:before     { background-position: -2rem -9rem; }

+ 10 - 0
assets/stylesheets/pages/_requirejs.scss

@@ -0,0 +1,10 @@
+._requirejs {
+  padding-left: 1rem;
+
+  h1, h2, h3, ul.index { margin-left: -1rem; }
+  h2 { @extend %block-heading; }
+  h3 { @extend %block-label, %label-blue; }
+  h4 { font-size: 1em; }
+
+  ul.index ul { margin: .5em 0; }
+}

+ 22 - 0
lib/docs/filters/requirejs/clean_html.rb

@@ -0,0 +1,22 @@
+module Docs
+  class Requirejs
+    class CleanHtmlFilter < Filter
+      def call
+        css('.sectionMark', '.hbox > .sect').remove
+        css('h1 + .note').remove if root_page?
+
+        css('.section', 'pre > code').each do |node|
+          node.before(node.children).remove
+        end
+
+        css('h2', 'h3', 'h4').each do |node|
+          next unless link = node.at_css('a[name]')
+          node['id'] = link['name']
+          link.before(link.children).remove
+        end
+
+        doc
+      end
+    end
+  end
+end

+ 35 - 0
lib/docs/filters/requirejs/entries.rb

@@ -0,0 +1,35 @@
+module Docs
+  class Requirejs
+    class EntriesFilter < Docs::EntriesFilter
+      def get_name
+        at_css('h1').content
+      end
+
+      def get_type
+        'Guides'
+      end
+
+      def additional_entries
+        return [] unless root_page?
+
+        entries = []
+        type = nil
+
+        css('*').each do |node|
+          if node.name == 'h2'
+            type = node.content
+          elsif node.name == 'h3' || node.name == 'h4'
+            entries << [node.content, node['id'], type]
+          end
+        end
+
+        css('p[id^="config-"]').each do |node|
+          next if node['id'].include?('note')
+          entries << [node.at_css('strong').content, node['id'], 'Configuration Options']
+        end
+
+        entries
+      end
+    end
+  end
+end

+ 29 - 0
lib/docs/scrapers/requirejs.rb

@@ -0,0 +1,29 @@
+module Docs
+  class Requirejs < UrlScraper
+    self.name = 'RequireJS'
+    self.type = 'requirejs'
+    self.version = '2.1.4'
+    self.base_url = 'http://requirejs.org/docs/'
+    self.root_path = 'api.html'
+    self.initial_paths = %w(
+      optimization.html
+      jquery.html
+      node.html
+      dojo.html
+      commonjs.html
+      plugins.html
+      why.html
+      whyamd.html)
+
+    html_filters.push 'requirejs/clean_html', 'requirejs/entries'
+
+    options[:container] = '#content'
+    options[:follow_links] = false
+    options[:only] = self.initial_paths
+
+    options[:attribution] = <<-HTML
+      &copy; 2010&ndash;2014 The Dojo Foundation<br>
+      Licensed under the MIT License.
+    HTML
+  end
+end

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


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


+ 1 - 0
public/icons/docs/requirejs/SOURCE

@@ -0,0 +1 @@
+http://requirejs.org/