Browse Source

Finish CakePHP documentation

Thibaut Courouble 9 years ago
parent
commit
5f2d9cde50

BIN
assets/images/icons.png


BIN
assets/images/icons@2x.png


+ 3 - 0
assets/javascripts/news.json

@@ -1,5 +1,8 @@
 [
   [
+    "2016-02-14",
+    "New documentation: <a href=\"/cakephp/\">CakePHP</a>"
+  ], [
     "2016-01-31",
     "New documentations: <a href=\"/erlang/\">Erlang</a> and <a href=\"/tcl_tk/\">Tcl/Tk</a>"
   ], [

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

@@ -99,6 +99,11 @@ credits = [
     'cppreference.com',
     'CC BY-SA',
     'http://en.cppreference.com/w/Cppreference:Copyright/CC-BY-SA'
+  ], [
+    'CakePHP',
+    '2005-2016 The Cake Software Foundation, Inc.',
+    'MIT',
+    'https://raw.githubusercontent.com/cakephp/cakephp/master/LICENSE.txt'
   ], [
     'Chai',
     '2011-2015 Jake Luer',

+ 5 - 0
assets/stylesheets/global/_classes.scss

@@ -70,6 +70,11 @@
   @extend %label;
 }
 
+%label-yellow {
+  background: $noteBackground;
+  border-color: $noteBorder;
+}
+
 %note-green, %label-green {
   background: $noteGreenBackground;
   border-color: $noteGreenBorder;

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

@@ -94,7 +94,7 @@
 %icon-check-white           { background-position: -9rem -6rem; }
 %icon-light                 { background-position: 0 -7rem; }
 %icon-light-white           { background-position: -1rem -7rem; }
-._icon-iojs:before          { background-position: -2rem -7rem; @extend %darkIconFix !optional; }
+._icon-cakephp:before       { background-position: -2rem -7rem; }
 ._icon-lua:before           { background-position: -3rem -7rem; @extend %darkIconFix !optional; }
 ._icon-clojure:before       { background-position: -4rem -7rem; }
 ._icon-symfony:before       { background-position: -5rem -7rem; }

+ 11 - 10
assets/stylesheets/pages/_cakephp.scss

@@ -1,16 +1,17 @@
 ._cakephp {
-  h2 { @extend %block-heading; }
+  @extend %simple;
 
-  h3 { @extend %block-label, %label-blue; }
+  h3 > .source { float: right; }
+  h3 > a, span.label, span.php-keyword1 { font-weight: normal; }
 
-  h3 > a { float: right; }
-
-  h3 > a,
-  span.label,
-  span.php-keyword1 {
-    font-weight: normal;
+  h4 {
+    margin: 1.5em 0;
+    @extend %block-label;
   }
 
-  .tree > dd { margin-left: 0px; }
-  .list { margin-left: 20px; }
+  dl { margin: 1em 0; }
+
+  .info { @extend %note; }
+  code { @extend %label; }
+  p > .label, dt > .label { @extend %label, %label-yellow; }
 }

+ 1 - 0
lib/docs/core/scrapers/file_scraper.rb

@@ -8,6 +8,7 @@ module Docs
       def inherited(subclass)
         super
         subclass.base_url = base_url
+        subclass.dir = dir
       end
     end
 

+ 30 - 17
lib/docs/filters/cakephp/clean_html.rb

@@ -2,44 +2,50 @@ module Docs
   class Cakephp
     class CleanHtmlFilter < Filter
       def call
-        if root_page?
-          css('.section').remove
-        end
+        css('.breadcrumbs', 'a.permalink', 'a.anchor').remove
 
-        css('.breadcrumbs', '.info', 'a.permalink').remove
+        css('.section', '#content', '.description', '.list').each do |node|
+          node.before(node.children).remove
+        end
 
         css('h1').drop(1).each do |node|
           node.name = 'h2'
         end
 
+        css('> h6').each do |node|
+          node.name = 'h2'
+        end
+
+        css('h6').each do |node|
+          node.name = 'h4'
+        end
+
         css('.property-name').each do |node|
           node.name = 'h3'
         end
 
+        css('var').each do |node|
+          node.name = 'code'
+        end
+
         # Move dummy anchor to method and property name
+
         css('.method-detail').each do |node|
           node.at_css('.method-name')['id'] = node.at_css('a')['id']
         end
+
         css('.property-detail').each do |node|
           node.at_css('.property-name')['id'] = node['id']
           node.remove_attribute('id')
         end
 
         # Break out source link to separate element
+
         css('.method-name', '.property-name').each do |node|
           source = node.at_css('a')
-          source.add_previous_sibling("<span class=\"name\">#{source.content}</span>")
+          source.before(%(<span class="name">#{source.content}</span>))
           source.content = 'source'
-        end
-
-        # These are missing in upstream documentation. Not sure why.
-        css('.section > h2').each do |node|
-          if node.content == "Method Detail"
-            node['id'] = 'methods'
-          end
-          if node.content == 'Properties summary'
-            node['id'] = 'properties'
-          end
+          source['class'] = 'source'
         end
 
         css('.method-signature').each do |node|
@@ -51,8 +57,15 @@ module Docs
           node.content = node.content.strip
         end
 
-        # Pages don't share a nice common base css tag.
-        doc.children
+        css('code code').each do |node|
+          node.before(node.children).remove
+        end
+
+        css('code').each do |node|
+          node.inner_html = node.inner_html.squish
+        end
+
+        doc
       end
     end
   end

+ 40 - 32
lib/docs/filters/cakephp/entries.rb

@@ -1,55 +1,63 @@
 module Docs
   class Cakephp
     class EntriesFilter < Docs::EntriesFilter
-      INCLUDE_PAGE_TYPES = {
-        'class'     => true,
-        'function'  => true,
-        'namespace' => false,
-      }
-
-      def get_page_type
-        page_type = slug.split('-')[0]
+      def page_type
+        @page_type ||= slug.split('-').first
       end
 
-      def include_default_entry?
-        INCLUDE_PAGE_TYPES[get_page_type]
+      def slug_without_page_type
+        @slug_without_page_type ||= slug.split('-').last
       end
 
       def get_name
-        case get_page_type
-          when 'class'
-            slug.split('.').last
-          when 'function'
-            at_css('h1').content.split(' ')[1]
+        case page_type
+        when 'class'
+          slug_without_page_type.split('.').last.concat(' (class)')
+        when 'function'
+          at_css('h1').content.remove('Function ')
+        when 'namespace', 'package'
+          slug_without_page_type.split('.').tap do |path|
+            path.shift if path.length > 1
+          end.join('\\').concat(" (#{page_type})")
         end
       end
 
       def get_type
-        case get_page_type
-          when 'class'
-            slug.split('.')[1..-2].join('\\')
-          when 'function'
-            'Global Functions'
+        return 'Global' if slug == 'namespace-None'
+        case page_type
+        when 'class', 'namespace', 'package'
+          if (node = at_css('.info')) && node.content =~ /Located at\s+((?:\w+\/?)+)/ # for 2.x docs
+            path = $1.split('/')
+          else
+            path = slug_without_page_type.split('.')
+          end
+          path.shift if path.length > 1 && path[0] == 'Cake'
+          path.pop if path.length > 1
+          path.pop if path.last == 'Exception'
+          path.join('\\')
+        when 'function'
+          'Global'
         end
       end
 
       def additional_entries
+        return [] unless page_type == 'class'
+        class_name = name.remove(' (class)')
+        return [] if class_name.end_with?('Exception')
         entries = []
-        if get_page_type == 'class'
-          css('.method-name').each do |node|
-            name = get_name + '::' + node.at_css('.name').content.strip + '()'
-            id = node['id']
-            entries << [name, id, get_type]
-          end
-          css('.property-name').each do |node|
-            name = get_name + '::' + node.at_css('.name').content.strip
-            id = node['id']
-            entries << [name, id, get_type]
-          end
+
+        css('.method-name').each do |node|
+          break if node.parent.previous_element.content =~ /\AMethods.*from/
+          entries << ["#{class_name}::#{node.at_css('.name').content.strip}()", node['id']]
         end
+
+        css('.property-name').each do |node|
+          break if node.parent.parent['class'].include?('used')
+          entries << ["#{class_name}::#{node.at_css('.name').content.strip}", node['id']]
+        end
+
         entries
       end
-
     end
   end
 end

+ 25 - 6
lib/docs/scrapers/cakephp.rb

@@ -2,9 +2,7 @@ module Docs
   class Cakephp < FileScraper
     self.name = 'CakePHP'
     self.type = 'cakephp'
-    self.version = '3.1'
-    self.dir = ''
-    self.base_url = "http://api.cakephp.org/#{version}/"
+    self.dir = '/Users/Thibaut/DevDocs/Docs/CakePHP'
     self.root_path = 'index.html'
     self.links = {
       home: 'http://cakephp.org/',
@@ -15,12 +13,33 @@ module Docs
 
     options[:container] = '#right.columns.nine'
 
-    # CakePHP docs include full source code. Ignore it.
     options[:skip_patterns] = [/\Asource-/]
 
     options[:attribution] = <<-HTML
-      &copy; 2005&ndash;2015 The Cake Software Foundation, Inc.<br>
-      Licensed under the MIT License.
+      &copy; 2005&ndash;2016 The Cake Software Foundation, Inc.<br>
+      Licensed under the MIT License.<br>
+      CakePHP is a registered trademark of Cake Software Foundation, Inc.<br>
+      We are not endorsed by or affiliated with CakePHP.
     HTML
+
+    version '3.2' do # http://api.cakephp.org/3.2/cakephp-api-documentation.zip
+      self.release = '3.2.2'
+      self.base_url = 'http://api.cakephp.org/3.2/'
+    end
+
+    version '3.1' do # http://api.cakephp.org/3.1/cakephp-api-documentation.zip
+      self.release = '3.1.10'
+      self.base_url = 'http://api.cakephp.org/3.1/'
+    end
+
+    version '2.8' do # http://api.cakephp.org/2.8/cakephp-api-documentation.zip
+      self.release = '2.8.0'
+      self.base_url = 'http://api.cakephp.org/2.8/'
+    end
+
+    version '2.7' do # http://api.cakephp.org/2.7/cakephp-api-documentation.zip
+      self.release = '2.7.10'
+      self.base_url = 'http://api.cakephp.org/2.7/'
+    end
   end
 end

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


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