History

Finish Phalcon scraper

Thibaut committed 11 years ago

Commit ece7a751 parent 4cde9d214 files · +69 −19Browse files

Unified · Split

14 files
  1. assets/images/icons.png +0 −0
  2. assets/images/icons@2x.png +0 −0
  3. assets/javascripts/news.json +3 −0
  4. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  5. assets/javascripts/views/pages/phalcon.coffee +7 −0
  6. assets/stylesheets/application-dark.css.scss +1 −0
  7. assets/stylesheets/application.css.scss +1 −0
  8. assets/stylesheets/global/_icons.scss +1 −0
  9. assets/stylesheets/pages/_phalcon.scss +8 −0
  10. lib/docs/filters/phalcon/clean_html.rb +31 −5
  11. lib/docs/filters/phalcon/entries.rb +10 −13
  12. lib/docs/scrapers/phalcon.rb +6 −5
  13. public/icons/docs/phalcon/16.png +0 −0
  14. public/icons/docs/phalcon/16@2x.png +0 −0
assets/images/icons.png+0−0

Binary file not shown.

assets/images/icons@2x.png+0−0

Binary file not shown.

assets/javascripts/news.json+3−0
@@ -1,5 +1,8 @@
11 [
22 [
3+ "2015-09-13",
4+ "New documentation: <a href=\"/phalcon/\">Phalcon</a>"
5+ ], [
36 "2015-08-09",
47 "New documentation: <a href=\"/react_native/\">React Native</a>"
58 ], [
assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -279,6 +279,11 @@ credits = [ · 278 unmodified lines
279279 '2010-2015 The OpenTSDB Authors',
280280 'LGPLv2.1',
281281 'https://raw.githubusercontent.com/OpenTSDB/opentsdb.net/gh-pages/COPYING.LESSER'
282+ ], [
283+ 'Phalcon',
284+ '2011-2015 Phalcon Framework Team',
285+ 'CC BY',
286+ 'https://docs.phalconphp.com/en/latest/reference/license.html'
282287 ], [
283288 'Phaser',
284289 '2015 Richard Davey, Photon Storm Ltd.',
assets/javascripts/views/pages/phalcon.coffee+7−0
@@ -0,0 +1,7 @@
1+#= require views/pages/base
2+
3+class app.views.PhalconPage extends app.views.BasePage
4+ afterRender: ->
5+ @highlightCode @findAll('pre[class*="php"]'), 'php'
6+ @highlightCode @findAll('pre.highlight-html'), 'markup'
7+ return
assets/stylesheets/application-dark.css.scss+1−0
@@ -55,6 +55,7 @@ · 54 unmodified lines
5555 'pages/node',
5656 'pages/npm',
5757 'pages/opentsdb',
58+ 'pages/phalcon',
5859 'pages/phaser',
5960 'pages/php',
6061 'pages/phpunit',
assets/stylesheets/application.css.scss+1−0
@@ -55,6 +55,7 @@ · 54 unmodified lines
5555 'pages/node',
5656 'pages/npm',
5757 'pages/opentsdb',
58+ 'pages/phalcon',
5859 'pages/phaser',
5960 'pages/php',
6061 'pages/phpunit',
assets/stylesheets/global/_icons.scss+1−0
@@ -112,3 +112,4 @@ · 111 unmodified lines
112112 %icon-expand-white { background-position: -8rem -8rem; }
113113 %icon-contract-white { background-position: -9rem -8rem; }
114114 ._icon-react_native:before { background-position: 0 -9rem; }
115+._icon-phalcon:before { background-position: -1rem -9rem; }
assets/stylesheets/pages/_phalcon.scss+8−0
@@ -0,0 +1,8 @@
1+._phalcon {
2+ @extend %simple;
3+
4+ h3 > small {
5+ float: right;
6+ color: $textColorLight;
7+ }
8+}
lib/docs/filters/phalcon/clean_html.rb+31−5
@@ -4,12 +4,38 @@ module Docs · 3 unmodified lines
44 def call
55 @doc = at_css('.body')
66
7− # Remove unnecessary things
8− css('.headerlink', '#what-is-phalcon', '#other-formats', '#welcome h1', '#welcome p', '#table-of-contents h2').remove
7+ if root_page?
8+ at_css('h1').content = 'Phalcon'
9+ end
10+
11+ css('#what-is-phalcon', '#other-formats').remove
12+
13+ css('#methods > p > strong, #constants > p > strong').each do |node|
14+ node.parent.name = 'h3'
15+ node.parent['id'] = node.content.parameterize
16+ node.parent['class'] = 'method-signature'
17+ node.parent.inner_html = node.parent.inner_html.sub(/inherited from .*/, '<small>\0</small>')
18+ end
19+
20+ css('.headerlink').each do |node|
21+ id = node['href'][1..-1]
22+ node.parent['id'] ||= id
23+ node.remove
24+ end
25+
26+ css('div[class^="highlight-"]').each do |node|
27+ code = node.at_css('pre').content
28+ code.remove! %r{\A\s*<\?php\s*} unless code.include?(' ?>')
29+ node.content = code
30+ node.name = 'pre'
31+ end
32+
33+ css('.section').each do |node|
34+ node.before(node.children).remove
35+ end
936
10− # Add id for constants and methods
11− css('#constants strong', '#methods strong').each do |node|
12− node.parent['id'] = node.content.strip
37+ css('table[border]').each do |node|
38+ node.remove_attribute('border')
1339 end
1440
1541 doc
lib/docs/filters/phalcon/entries.rb+10−13
@@ -1,31 +1,28 @@
11 module Docs
22 class Phalcon
33 class EntriesFilter < Docs::EntriesFilter
4−
54 def get_name
6− node = css('h1').first
7− name = node.content.strip
8− node.remove
9− name
5+ (at_css('h1 > strong') || at_css('h1')).content.strip.remove('Phalcon\\')
106 end
117
128 def get_type
13− if slug.start_with? 'reference'
9+ if slug.start_with?('reference')
1410 'Guides'
1511 else
16− 'Classes'
12+ path = name.split('\\')
13+ path[1] == 'Mvc' ? path[1..2].join('\\') : path[1]
1714 end
1815 end
1916
2017 def additional_entries
2118 entries = []
2219
23− css('#constants strong').each do |node|
24− entries << [node.content.strip, node.parent['id'], 'Constants']
25− end
26−
27− css('#methods strong').each do |node|
28− entries << [node.content.strip, node.parent['id'], 'Methods']
20+ css('.method-signature').each do |node|
21+ next if node.content.include?('inherited from') || node.content.include?('protected ') || node.content.include?('private ')
22+ name = node.at_css('strong').content.strip
23+ next if name == '__construct' || name == '__toString'
24+ name.prepend "#{self.name}::"
25+ entries << [name, node['id']]
2926 end
3027
3128 entries
lib/docs/scrapers/phalcon.rb+6−5
@@ -1,8 +1,7 @@
11 module Docs
22 class Phalcon < UrlScraper
3− self.name = 'Phalcon'
4− self.slug = 'phalcon'
53 self.type = 'phalcon'
4+ self.version = '2.0.6'
65 self.base_url = 'https://docs.phalconphp.com/en/latest/'
76 self.root_path = 'index.html'
87 self.links = {
@@ -10,14 +9,16 @@ module Docs · 1 unmodified line
109 code: 'https://github.com/phalcon/cphalcon/'
1110 }
1211
13− html_filters.push 'phalcon/clean_html', 'phalcon/entries', 'title'
12+ html_filters.push 'phalcon/clean_html', 'phalcon/entries'
1413
1514 options[:root_title] = 'Phalcon'
1615 options[:only_patterns] = [/reference\//, /api\//]
17− options[:skip_patterns] = [/api\/index/]
16+ options[:skip] = %w(
17+ api/index.html
18+ reference/license.html)
1819
1920 options[:attribution] = <<-HTML
20− &copy; 2012&ndash;2015 the Phalcon Team<br>
21+ &copy; 2011&ndash;2015 Phalcon Framework Team<br>
2122 Licensed under the Creative Commons Attribution License 3.0.
2223 HTML
2324 end
public/icons/docs/phalcon/16.png+0−0

Binary file not shown.

public/icons/docs/phalcon/16@2x.png+0−0

Binary file not shown.