rgabo-readability 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,112 @@
1
+ <!DOCTYPE html>
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5
+ <title>TomDoc - Reasonable Ruby Documentation</title>
6
+ <meta name="author" content="Tom Preston-Werner" />
7
+ <link href="http://feeds.feedburner.com/tom-preston-werner" rel="alternate" title="Tom Preston-Werner" type="application/atom+xml" />
8
+
9
+ <!-- syntax highlighting CSS -->
10
+ <link rel="stylesheet" href="/css/syntax.css" type="text/css" />
11
+
12
+ <!-- Homepage CSS -->
13
+ <link rel="stylesheet" href="/css/screen.css" type="text/css" media="screen, projection" />
14
+
15
+ <script type="text/javascript" src="script.js"></script>
16
+ <script type="text/javascript">document.title = "failed";</script>
17
+ </head>
18
+ <body>
19
+
20
+ <script type="text/javascript">
21
+ document.title = "failed";
22
+ </script>
23
+
24
+ <div class="site">
25
+ <div class="title">
26
+ <a href="/">Tom Preston-Werner</a>
27
+ <a class="extra" href="/">home</a>
28
+ </div>
29
+
30
+ <div id="post">
31
+ <h1>TomDoc &#8211; Reasonable Ruby Documentation</h1>
32
+ <p class="meta">11 May 2010 &#8211; San Francisco</p>
33
+ <p><a href="http://rdoc.rubyforge.org">RDoc</a> is an abomination. It&#8217;s ugly to read in plain text, requires the use of the inane :nodoc: tag to prevent private method documentation from showing up in final rendering, and does nothing to encourage complete or unambiguous documentation of classes, methods, or parameters. <a href="http://yardoc.org"><span class="caps">YARD</span></a> is much better but goes too far in the other direction (and still doesn&#8217;t look good in plain text). Providing an explicit way to specify parameters and types is great, but having to remember a bunch of strict tag names in order to be compliant is not a good way to encourage coders to write documentation. And again we see a @private tag that&#8217;s necessary to hide docs from the final render.</p>
34
+ <p>Three years ago, after suffering with these existing documentation formats for far too long, I started using my own documentation format. It looked a bit like RDoc but had a set of conventions for specifying parameters, return values, and the expected types. It used plain language and full sentences so that a human could read and understand it without having to parse machine-oriented tags or crufty markup. I called this format TomDoc, because if Linus can name stuff after himself, then why can&#8217;t I?</p>
35
+ <p>After years in the making, TomDoc is finally a well specified documentation format. You can find the full spec at <a href="http://tomdoc.org">http://tomdoc.org</a>.</p>
36
+ <p>But enough talk. Here&#8217;s a sample of what a TomDoc&#8217;d method might look like:</p>
37
+ <div class="highlight"><pre><code class="ruby"><span class="c1"># Public: Duplicate some text an abitrary number of times.</span>
38
+ <span class="c1">#</span>
39
+ <span class="c1"># text - The String to be duplicated.</span>
40
+ <span class="c1"># count - The Integer number of times to duplicate the text.</span>
41
+ <span class="c1">#</span>
42
+ <span class="c1"># Examples</span>
43
+ <span class="c1">#</span>
44
+ <span class="c1"># multiplex(&#39;Tom&#39;, 4)</span>
45
+ <span class="c1"># # =&gt; &#39;TomTomTomTom&#39;</span>
46
+ <span class="c1">#</span>
47
+ <span class="c1"># Returns the duplicated String.</span>
48
+ <span class="k">def</span> <span class="nf">multiplex</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="n">count</span><span class="p">)</span>
49
+ <span class="n">text</span> <span class="o">*</span> <span class="n">count</span>
50
+ <span class="k">end</span>
51
+ </code></pre>
52
+ </div><p>At first glance you&#8217;ll notice a few things. First, and most important, is that the documentation looks nice in plain text. When I&#8217;m working on a project, I need to be able to scan and read method documentation quickly. Littering the docs with tags and markup (especially <span class="caps">HTML</span> markup) is not acceptable. Code documentation should be optimized for human consumption. Second, all parameters and return values, and their expected types are specified. Types are generally denoted by class name. Because Ruby is so flexible, you are not constrained by a rigid type declaration syntax and are free to explain precisely how the expected types may vary under different circumstances. Finally, the basic layout is designed to be easy to remember. Once you commit a few simple conventions to memory, writing documentation becomes second nature, with all of the tricky decision making already done for you.</p>
53
+ <p>Today&#8217;s Ruby libraries suffer deeply from haphazard versioning schemes. Even RubyGems itself does not follow a sane or predictable versioning pattern. This lack of discipline stems from the absence of well defined Public APIs. TomDoc attempts to solve this problem by making it simple to define an unambiguous Public <span class="caps">API</span> for your library. Instead of assuming that all classes and methods are intended for public consumption, TomDoc makes the Public <span class="caps">API</span> opt-in. To denote that something is public, all you have to do is preface the main description with &#8220;Public:&#8221;. By forcing you to explicitly state that a class or method is intended for public consumption, a deliberate and thoughtful Public <span class="caps">API</span> is automatically constructed that can inform disciplined version changes according to the tenets of <a href="http://semver.org">Semantic Versioning</a>. In addition, the prominent display of &#8220;Public&#8221; in a method description ensures that developers are made aware of the sensitive nature of the method and do not carelessly change the signature of something in the Public <span class="caps">API</span>.</p>
54
+ <p>Once a Public <span class="caps">API</span> has been established, some very exciting things become possible. We&#8217;re currently working on a processing tool that will render TomDoc into various forms (terminal, <span class="caps">HTML</span>, etc). If you run this tool on a library, you&#8217;ll get a printout of the Public <span class="caps">API</span> documentation. You can publish this online so that others have easy access to it. When you roll a new version of the library, you can run the tool again, giving it a prior version as a base, and have it automatically display only the methods that have changed. This diff will be extremely useful for users while they upgrade to the new version (or so they can evaluate whether an upgrade is warrented)!</p>
55
+ <p>While I&#8217;ve been using various nascent forms of TomDoc for several years, we&#8217;re just now starting to adopt it for everything we do at GitHub. Now that I&#8217;ve formalized the spec it will be easy for the entire team to write compliant TomDoc. The goal is to have every class, method, and accessor of every GitHub library documented. In the future, once we have proper tooling, we&#8217;d even like to create a unit test that will fail if anything is missing documentation.</p>
56
+ <p>TomDoc is still a rough specification so I&#8217;m initially releasing it as 0.9.0. Over the coming months I&#8217;ll make any necessary changes to address user concerns and release a 1.0.0 version once things have stabilized. If you&#8217;d like to suggest changes, please open an issue on the <a href="http://github.com/mojombo/tomdoc">TomDoc GitHub repository</a>.</p>
57
+ </div>
58
+
59
+ <div id="related">
60
+ <h2>Related Posts</h2>
61
+ <ul class="posts">
62
+
63
+ <li><span>19 May 2009</span> &raquo; <a href="/2009/05/19/the-git-parable.html">The Git Parable</a></li>
64
+
65
+ <li><span>17 Nov 2008</span> &raquo; <a href="/2008/11/17/blogging-like-a-hacker.html">Blogging Like a Hacker</a></li>
66
+
67
+ <li><span>03 Nov 2008</span> &raquo; <a href="/2008/11/03/how-to-meet-your-next-cofounder.html">How to Meet Your Next Cofounder</a></li>
68
+
69
+ </ul>
70
+ </div>
71
+
72
+ <div class="footer">
73
+ <div class="contact">
74
+ <p>
75
+ Tom Preston-Werner<br />
76
+ Cofounder of <a href="http://github.com/">GitHub</a><br />
77
+ tom@mojombo.com
78
+ </p>
79
+ </div>
80
+ <div class="contact">
81
+ <p>
82
+ <a href="http://github.com/mojombo/">github.com/mojombo</a><br />
83
+ <a href="http://twitter.com/mojombo/">twitter.com/mojombo</a><br />
84
+ <a href="http://flickr.com/photos/mojombo/">flickr.com/photos/mojombo</a>
85
+ </p>
86
+ </div>
87
+ <div class="rss">
88
+ <a href="http://feeds.feedburner.com/tom-preston-werner">
89
+ <img src="/images/rss.png" alt="Subscribe to RSS Feed" />
90
+ </a>
91
+ </div>
92
+ </div>
93
+ </div>
94
+
95
+ <a href="http://github.com/mojombo"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub" /></a>
96
+
97
+ <div id="ClickTaleDiv" style="display: none;"></div>
98
+
99
+ <script type="text/javascript">
100
+ document.write(unescape("%3Cscript%20src='script.js'%20type='text/javascript'%3E%3C/script%3E"));
101
+ </script>
102
+
103
+ <script type="text/javascript">
104
+ document.write(unescape("%3Cscript%20type='text/javascript'%3E%20document.title = 'failed'%20%3C/script%3E"));
105
+ </script>
106
+
107
+ <script type="text/javascript">
108
+ document.title = "failed"
109
+ </script>
110
+
111
+ </body>
112
+ </html>
@@ -4,6 +4,7 @@ require 'open-uri'
4
4
  describe Readability::Harmonizable do
5
5
  before :each do
6
6
  @doc = Nokogiri::HTML(open(File.dirname(__FILE__) + '/../files/tomdoc-reasonable-ruby-documentation.html'))
7
+ @doc.remove('script')
7
8
  end
8
9
 
9
10
  it "extends Nokogiri::HTML::Document" do
@@ -1,5 +1,8 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
+ require 'open-uri'
4
+ require 'yaml'
5
+
3
6
  describe Readability::Readable do
4
7
  before :each do
5
8
  @doc = Nokogiri::HTML(open(File.dirname(__FILE__) + '/../files/tomdoc-reasonable-ruby-documentation.html'))
@@ -48,3 +51,47 @@ describe Readability::Readable do
48
51
  content.to_html.should_not include "Original Page"
49
52
  end
50
53
  end
54
+
55
+ describe "Readability.js" do
56
+ class << self
57
+ def test_with(url)
58
+ self.class_eval do <<-EOF
59
+ def it "should work on #{url}" do
60
+ # load webpage
61
+ @doc = Nokogiri::HTML(open("#{url}"))
62
+
63
+ # run readability in place
64
+ @doc.to_readable!
65
+
66
+ @doc.to_html.should include('Readability version 1.5.0')
67
+ end
68
+ EOF
69
+ end
70
+ end
71
+ end
72
+
73
+ it "should not execute any Javascript" do
74
+ # load modified version of the tomdoc post
75
+ @doc = Nokogiri::HTML(open(File.dirname(__FILE__) + '/../files/tomdoc-script_test.html'))
76
+
77
+ # run readability in place
78
+ @doc.to_readable!
79
+
80
+ # check whether any script could change the title of the document
81
+ @doc.window.document.title.should_not == "failed"
82
+ end
83
+
84
+ it "should not fail on any article" do
85
+ urls = YAML.load(File.open(File.join(File.dirname(__FILE__), 'urls.yaml')))
86
+
87
+ urls.each do |url|
88
+ # load webpage
89
+ @doc = Nokogiri::HTML(open(url))
90
+
91
+ # run readability in place
92
+ @doc.to_readable!
93
+
94
+ @doc.to_html.should include('Readability version 1.5.0')
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,8 @@
1
+ # Array of URLs to test readability with
2
+ - 'http://techcrunch.com/2010/05/16/groupon-invades-europe-with-acquisition-of-citydeal'
3
+ - 'http://blogs.wsj.com/venturecapital/2010/05/14/despite-short-term-improvement-vc-10-year-index-goes-negative/?mod=rss_WSJBlog'
4
+ - 'http://www.engadget.com/2010/04/03/entelligence-the-ipad-as-a-productivity-tool/'
5
+ # - 'http://www.huffingtonpost.com/2010/05/15/delete-facebook-account-q_n_576956.html'
6
+ - 'http://mashable.com/2010/05/16/in-defense-of-facebook/'
7
+ - 'http://feeds.venturebeat.com/~r/Venturebeat/~3/rYPVBROMiEI/'
8
+ - 'http://eu.techcrunch.com/2010/04/25/new-eu-rules-could-kill-off-european-vc-and-screw-startups-lets-stop-them/'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgabo-readability
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gabor Ratky
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-16 00:00:00 +02:00
18
+ date: 2010-05-17 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -77,6 +77,7 @@ extra_rdoc_files:
77
77
  files:
78
78
  - .document
79
79
  - .gitignore
80
+ - .rvmrc
80
81
  - LICENSE
81
82
  - README.rdoc
82
83
  - Rakefile
@@ -89,9 +90,13 @@ files:
89
90
  - readability.gems
90
91
  - rgabo-readability.gemspec
91
92
  - spec/files/change_title.js
93
+ - spec/files/script.js
94
+ - spec/files/techcrunch-article.html
92
95
  - spec/files/tomdoc-reasonable-ruby-documentation.html
96
+ - spec/files/tomdoc-script_test.html
93
97
  - spec/readability/harmonizable_spec.rb
94
98
  - spec/readability/readable_spec.rb
99
+ - spec/readability/urls.yaml
95
100
  - spec/readability_spec.rb
96
101
  - spec/spec.opts
97
102
  - spec/spec_helper.rb