Bläddra i källkod

Add Handlebars.js documentation

Jasper van Merle 7 år sedan
förälder
incheckning
8b9c62d791

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

@@ -310,6 +310,11 @@ credits = [
     'GruntJS Team',
     'MIT',
     'https://github.com/gruntjs/grunt-docs/blob/master/package.json#L10'
+  ], [
+    'Handlebars',
+    '2011-2017 Yehuda Katz',
+    'MIT',
+    'https://raw.githubusercontent.com/wycats/handlebars.js/master/LICENSE'
   ], [
     'Haskell',
     'The University of Glasgow',

+ 1 - 0
assets/stylesheets/pages/_simple.scss

@@ -27,6 +27,7 @@
 ._flow,
 ._gnu,
 ._grunt,
+._handlebars,
 ._haxe,
 ._immutable,
 ._influxdata,

+ 44 - 0
lib/docs/filters/handlebars/clean_html.rb

@@ -0,0 +1,44 @@
+module Docs
+  class Handlebars
+    class CleanHtmlFilter < Filter
+      def call
+        # Remove the t-shirt shop advertisement
+        css('#callout').remove
+
+        # The title filter is used to add titles to pages without one, remove original headers
+        css('h1').remove
+
+        # Remove the link to the issue tracker
+        css('.issue-tracker').remove
+
+        css('pre').each do |node|
+          # Remove nested nodes inside pre tags
+          node.content = node.content
+
+          # Add syntax highlighting
+          node['data-language'] = 'html'
+        end
+
+        # Transform 'Learn More' links to headers in the "Getting Started" part of the homepage
+        # If this step is skipped, that section looks cluttered with 4 sub-sections without any dividers
+        css('#getting-started + .contents a.more-info').each do |node|
+          clone = node.clone
+
+          # Move it to the top of the sub-section
+          node.parent.prepend_child(clone)
+
+          # Turn it into a header
+          clone.name = 'h3'
+
+          # Remove the "Learn More: " part
+          clone.content = clone.content[12..-1]
+        end
+
+        # Remove class attributes from div elements to reduce file size
+        css('div').remove_attr('class')
+
+        doc
+      end
+    end
+  end
+end

+ 19 - 0
lib/docs/filters/handlebars/entries.rb

@@ -0,0 +1,19 @@
+module Docs
+  class Handlebars
+    class EntriesFilter < Docs::EntriesFilter
+      def get_name
+        subpath[0..-6].titleize
+      end
+
+      def get_type
+        name
+      end
+
+      def additional_entries
+        css('h2, h3').to_a.map do |node|
+          [node.content.strip, node['id'], root_page? ? 'Manual' : nil]
+        end
+      end
+    end
+  end
+end

+ 23 - 0
lib/docs/scrapers/handlebars.rb

@@ -0,0 +1,23 @@
+module Docs
+  class Handlebars < UrlScraper
+    self.name = 'Handlebars.js'
+    self.slug = 'handlebars'
+    self.type = 'handlebars'
+    self.release = '4.0.11'
+    self.base_url = 'https://handlebarsjs.com/'
+    self.links = {
+      home: 'https://handlebarsjs.com/',
+      code: 'https://github.com/wycats/handlebars.js/'
+    }
+
+    html_filters.push 'handlebars/entries', 'handlebars/clean_html', 'title'
+
+    options[:container] = '#contents'
+    options[:root_title] = 'Handlebars.js'
+
+    options[:attribution] = <<-HTML
+      &copy; 2011-2017 by Yehuda Katz<br>
+      Licensed under the MIT License.
+    HTML
+  end
+end

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


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


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

@@ -0,0 +1 @@
+https://github.com/yahoo/formatjs-site/tree/master/public/img