Bladeren bron

Add TypeScript documentation

Thibaut Courouble 9 jaren geleden
bovenliggende
commit
905d6cee9e

BIN
assets/images/icons.png


BIN
assets/images/icons@2x.png


+ 3 - 0
assets/javascripts/news.json

@@ -1,5 +1,8 @@
 [
   [
+    "2016-03-27",
+    "New documentation: <a href=\"/typescript/\">TypeScript</a>"
+  ], [
     "2016-03-06",
     "New documentation: <a href=\"/tensorflow/\">TensorFlow</a>, <a href=\"/haxe/\">Haxe</a> and <a href=\"/ansible/\">Ansible</a>"
   ], [

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

@@ -439,6 +439,11 @@ credits = [
     '2015 The TensorFlow Authors',
     'Apache',
     'https://raw.githubusercontent.com/tensorflow/tensorflow/master/LICENSE'
+  ], [
+    'TypeScript',
+    'Microsoft and other contributors',
+    'Apache',
+    'https://raw.githubusercontent.com/Microsoft/TypeScript-Handbook/master/LICENSE'
   ], [
     'Underscore.js',
     '2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors',

+ 12 - 3
assets/javascripts/vendor/prism.js

@@ -1,4 +1,4 @@
-/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+c+cpp+coffeescript+ruby+elixir+go+lua+nginx+php+python+rust */
+/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+c+cpp+coffeescript+ruby+elixir+go+lua+nginx+php+python+rust+typescript */
 var _self = (typeof window !== 'undefined')
 	? window   // if in browser
 	: (
@@ -328,6 +328,9 @@ var _ = _self.Prism = {
 						delNum = 3;
 
 						if (to <= len) {
+							if (strarr[i + 1].greedy) {
+								continue;
+							}
 							delNum = 2;
 							combStr = combStr.slice(0, len);
 						}
@@ -354,7 +357,7 @@ var _ = _self.Prism = {
 						args.push(before);
 					}
 
-					var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match);
+					var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match, greedy);
 
 					args.push(wrapped);
 
@@ -395,12 +398,13 @@ var _ = _self.Prism = {
 	}
 };
 
-var Token = _.Token = function(type, content, alias, matchedStr) {
+var Token = _.Token = function(type, content, alias, matchedStr, greedy) {
 	this.type = type;
 	this.content = content;
 	this.alias = alias;
 	// Copy of the full string this token was created from
 	this.matchedStr = matchedStr || null;
+	this.greedy = !!greedy;
 };
 
 Token.stringify = function(o, language, parent) {
@@ -633,6 +637,7 @@ Prism.languages.insertBefore('javascript', 'keyword', {
 Prism.languages.insertBefore('javascript', 'class-name', {
 	'template-string': {
 		pattern: /`(?:\\\\|\\?[^\\])*?`/,
+		greedy: true,
 		inside: {
 			'interpolation': {
 				pattern: /\$\{[^}]+\}/,
@@ -1218,3 +1223,7 @@ Prism.languages.rust = {
 	'punctuation': /[{}[\];(),:]|\.+|->/,
 	'operator': /[-+*\/%!^=]=?|@|&[&=]?|\|[|=]?|<<?=?|>>?=?/
 };
+Prism.languages.typescript = Prism.languages.extend('javascript', {
+	'keyword': /\b(break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|get|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|set|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield|module|declare|constructor|string|Function|any|number|boolean|Array|enum)\b/
+});
+

+ 10 - 0
assets/javascripts/views/pages/simple.coffee

@@ -0,0 +1,10 @@
+#= require views/pages/base
+
+class app.views.SimplePage extends app.views.BasePage
+  prepare: ->
+    for el in @findAllByTag('pre') when el.hasAttribute('data-language')
+      @highlightCode el, el.getAttribute('data-language')
+    return
+
+app.views.TypescriptPage =
+app.views.SimplePage

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

@@ -132,3 +132,4 @@
 ._icon-tensorflow:before    { background-position: -6rem -10rem; }
 ._icon-haxe:before          { background-position: -7rem -10rem; }
 ._icon-ansible:before       { background-position: -8rem -10rem; @extend %darkIconFix !optional; }
+._icon-typescript:before    { background-position: -9rem -10rem; }

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

@@ -27,6 +27,7 @@
 ._mocha,
 ._mongoose,
 ._sinon,
+._typescript,
 ._webpack {
   @extend %simple;
 }

+ 27 - 0
lib/docs/filters/typescript/clean_html.rb

@@ -0,0 +1,27 @@
+module Docs
+  class Typescript
+    class CleanHtmlFilter < Filter
+      def call
+        @doc = at_css('.doc-content-container')
+
+        css('.xs-toc-container').remove
+
+        css('article h1').each do |node|
+          node.name = 'h2'
+        end
+
+        css('> header', '> article').each do |node|
+          node.before(node.children).remove
+        end
+
+        css('pre > code').each do |node|
+          node.parent['data-language'] = node['class'].sub('ts', 'typescript').sub('js', 'javascript').remove('language-')
+          node.content = node.content.gsub('    ', '  ')
+          node.before(node.children).remove
+        end
+
+        doc
+      end
+    end
+  end
+end

+ 37 - 0
lib/docs/filters/typescript/entries.rb

@@ -0,0 +1,37 @@
+module Docs
+  class Typescript
+    class EntriesFilter < Docs::EntriesFilter
+      def get_name
+        name = at_css('h1').content
+        name.sub! ' and ', ' & '
+        name
+      end
+
+      def get_type
+        type = at_css('#main-nav a.active').ancestors('.panel').first.at_css('> a').content
+        type = name if type == 'Handbook'
+        type
+      end
+
+      SKIP_ENTRIES = ['Introduction', 'A note', 'A Note', ', and', 'Techniques', ' Concepts', 'Hello World', 'Working with', 'Our ', 'Implementing ', 'Difference between', 'Basic', 'sample', 'Questions', 'Example', 'Export as close', 'Red Flags', 'First steps', 'Pitfalls', 'Well-known', 'Starting out', 'Comparing ', 'Do not', 'Trade-off', ' vs']
+
+      def additional_entries
+        return [] unless slug.start_with?('handbook')
+        return [] if slug == 'handbook/writing-definition-files'
+
+        css('h1, h2').each_with_object [] do |node, entries|
+          next if node.next_element.try(:name) == 'h2'
+          name = node.content.strip
+          next if name.length > 40
+          next if name == self.name || SKIP_ENTRIES.any? { |str| name.include?(str) }
+          name.remove! %r{\A#{self.name.remove(/s\z/)}s? }
+          name.sub! 'for..of', 'for...of'
+          name.remove! 'Symbol.'
+          name.remove! '/// '
+          name.prepend "#{self.name}: "
+          entries << [name, node['id']]
+        end
+      end
+    end
+  end
+end

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

@@ -0,0 +1,29 @@
+module Docs
+  class Typescript < UrlScraper
+    self.name = 'TypeScript'
+    self.type = 'typescript'
+    self.release = '1.8'
+    self.base_url = 'https://www.typescriptlang.org/docs/'
+    self.root_path = 'tutorial.html'
+    self.links = {
+      home: 'https://www.typescriptlang.org',
+      code: 'https://github.com/Microsoft/TypeScript'
+    }
+
+    html_filters.push 'typescript/entries', 'typescript/clean_html'
+
+    options[:container] = '#content'
+    options[:skip_link] = ->(node) { node.parent.parent['class'] == 'dropdown-menu' }
+    options[:fix_urls] = ->(url) {
+      url.sub!(/(\w+)\.md/) { "#{$1.downcase}.html" }
+      url
+    }
+
+    options[:attribution] = <<-HTML
+      &copy; Microsoft and other contributors<br>
+      Licensed under the Apache License, Version 2.0.
+    HTML
+  end
+end
+
+

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


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


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

@@ -0,0 +1 @@
+https://github.com/remojansen/logo.ts