Explorar el Código

Add Crystal documentation

Faustino Aguilar hace 9 años
padre
commit
0324bdca48

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

@@ -0,0 +1,6 @@
+#= require views/pages/base
+
+class app.views.CrystalPage extends app.views.BasePage
+  prepare: ->
+    @highlightCode @findAllByTag('pre'), 'ruby'
+    return

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

@@ -0,0 +1,7 @@
+._crystal {
+  @extend %simple;
+
+  blockquote {
+    @extend %note;
+  }
+}

+ 20 - 0
lib/docs/filters/crystal/clean_html.rb

@@ -0,0 +1,20 @@
+module Docs
+  class Crystal
+    class CleanHtmlFilter < Filter
+      def call
+
+        # Remove class attr from div and child nodes
+        css("div").each do |node|
+          node.xpath("//@class").remove
+        end
+
+        # Set id attributes on <h1> instead of an empty <a>
+        css("h1").each do |node|
+          node["id"] = node.at_css("a")["id"]
+        end
+
+        doc
+      end
+    end
+  end
+end

+ 21 - 0
lib/docs/filters/crystal/entries.rb

@@ -0,0 +1,21 @@
+module Docs
+  class Crystal
+    class EntriesFilter < Docs::EntriesFilter
+
+      # Set the name to h1 content
+      def get_name
+        node = at_css("h1")
+        node.content.strip
+      end
+
+      # Crystal types from url slug
+      def get_type
+        slug["blob/master/"] = ""
+        object, method = *slug.split("/")
+        object = object.capitalize
+        method ? object : "Index"
+      end
+
+    end
+  end
+end

+ 22 - 0
lib/docs/scrapers/crystal.rb

@@ -0,0 +1,22 @@
+module Docs
+  class Crystal < UrlScraper
+    self.name = "Crystal"
+    self.type = "crystal"
+    self.base_url = "https://github.com/crystal-lang/crystal-book"
+    self.initial_paths = %w(/blob/master/SUMMARY.md)
+    self.links = {
+      home: "https://crystal-lang.org/",
+      code: "https://github.com/crystal-lang/crystal"
+    }
+
+    html_filters.push "crystal/clean_html", "crystal/entries"
+
+    options[:container] = ".entry-content"
+    options[:only_patterns] = [/\/blob\/master\/.*\.md/]
+    options[:skip] = %w(/blob/master/README.md)
+
+    options[:attribution] = <<-HTML
+      <a href="http://creativecommons.org/publicdomain/zero/1.0/">CC0</a>
+    HTML
+  end
+end

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


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


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

@@ -0,0 +1 @@
+https://crystal-lang.org/images/favico.ico