diff --git a/assets/images/icons.png b/assets/images/icons.png index 41d823f2..686cd5b5 100644 Binary files a/assets/images/icons.png and b/assets/images/icons.png differ diff --git a/assets/images/icons@2x.png b/assets/images/icons@2x.png index c256dede..bac8943b 100644 Binary files a/assets/images/icons@2x.png and b/assets/images/icons@2x.png differ diff --git a/assets/javascripts/news.json b/assets/javascripts/news.json index 34b282fe..8b87ccef 100644 --- a/assets/javascripts/news.json +++ b/assets/javascripts/news.json @@ -1,5 +1,8 @@ [ [ + "2016-03-27", + "New documentation: TypeScript" + ], [ "2016-03-06", "New documentation: TensorFlow, Haxe and Ansible" ], [ diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index 5d0ecf7e..0fdda22f 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/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', diff --git a/assets/javascripts/vendor/prism.js b/assets/javascripts/vendor/prism.js index 5e247a48..b41bcb98 100644 --- a/assets/javascripts/vendor/prism.js +++ b/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/ +}); + diff --git a/assets/javascripts/views/pages/simple.coffee b/assets/javascripts/views/pages/simple.coffee new file mode 100644 index 00000000..058a2386 --- /dev/null +++ b/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 diff --git a/assets/stylesheets/global/_icons.scss b/assets/stylesheets/global/_icons.scss index 36ebc702..26f44b8c 100644 --- a/assets/stylesheets/global/_icons.scss +++ b/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; } diff --git a/assets/stylesheets/pages/_base.scss b/assets/stylesheets/pages/_base.scss index 2f5056c6..7e813832 100644 --- a/assets/stylesheets/pages/_base.scss +++ b/assets/stylesheets/pages/_base.scss @@ -27,6 +27,7 @@ ._mocha, ._mongoose, ._sinon, +._typescript, ._webpack { @extend %simple; } diff --git a/lib/docs/filters/typescript/clean_html.rb b/lib/docs/filters/typescript/clean_html.rb new file mode 100644 index 00000000..62894512 --- /dev/null +++ b/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 diff --git a/lib/docs/filters/typescript/entries.rb b/lib/docs/filters/typescript/entries.rb new file mode 100644 index 00000000..d3422ff2 --- /dev/null +++ b/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 diff --git a/lib/docs/scrapers/typescript.rb b/lib/docs/scrapers/typescript.rb new file mode 100644 index 00000000..4e79bc8b --- /dev/null +++ b/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 + © Microsoft and other contributors
+ Licensed under the Apache License, Version 2.0. + HTML + end +end + + diff --git a/public/icons/docs/typescript/16.png b/public/icons/docs/typescript/16.png new file mode 100644 index 00000000..66526f5e Binary files /dev/null and b/public/icons/docs/typescript/16.png differ diff --git a/public/icons/docs/typescript/16@2x.png b/public/icons/docs/typescript/16@2x.png new file mode 100644 index 00000000..d2a80959 Binary files /dev/null and b/public/icons/docs/typescript/16@2x.png differ diff --git a/public/icons/docs/typescript/SOURCE b/public/icons/docs/typescript/SOURCE new file mode 100644 index 00000000..490c0b58 --- /dev/null +++ b/public/icons/docs/typescript/SOURCE @@ -0,0 +1 @@ +https://github.com/remojansen/logo.ts