repository-base 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.rubocop.yml +27 -0
- data/.travis.yml +6 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +128 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +132 -0
- data/Rakefile +33 -0
- data/bin/bundle +105 -0
- data/bin/htmldiff +29 -0
- data/bin/kramdown +29 -0
- data/bin/ldiff +29 -0
- data/bin/rake +29 -0
- data/bin/rspec +29 -0
- data/bin/rubocop +29 -0
- data/bin/ruby-parse +29 -0
- data/bin/ruby-rewrite +29 -0
- data/bin/setup +43 -0
- data/bin/yard +29 -0
- data/bin/yardoc +29 -0
- data/bin/yri +29 -0
- data/doc/Repository.html +128 -0
- data/doc/Repository/Base.html +1248 -0
- data/doc/Repository/Base/Internals.html +133 -0
- data/doc/Repository/Base/Internals/RecordDeleter.html +687 -0
- data/doc/Repository/Base/Internals/RecordSaver.html +816 -0
- data/doc/Repository/Base/Internals/RecordUpdater.html +1026 -0
- data/doc/Repository/Base/Internals/SlugFinder.html +986 -0
- data/doc/_index.html +176 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +499 -0
- data/doc/file.CHANGELOG.html +240 -0
- data/doc/file.README.html +218 -0
- data/doc/file_list.html +61 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +218 -0
- data/doc/js/app.js +248 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +363 -0
- data/doc/top-level-namespace.html +110 -0
- data/lib/repository/base.rb +115 -0
- data/lib/repository/base/internals/internals.rb +6 -0
- data/lib/repository/base/internals/record_deleter.rb +46 -0
- data/lib/repository/base/internals/record_saver.rb +58 -0
- data/lib/repository/base/internals/record_updater.rb +54 -0
- data/lib/repository/base/internals/slug_finder.rb +70 -0
- data/lib/repository/base/version.rb +12 -0
- data/repository-base.gemspec +37 -0
- data/spec/repository/base_spec.rb +398 -0
- data/spec/spec_helper.rb +14 -0
- metadata +281 -0
data/doc/file_list.html
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<title>File List</title>
|
19
|
+
<base id="base_target" target="_parent" />
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<div id="content">
|
23
|
+
<div class="fixed_header">
|
24
|
+
<h1 id="full_list_header">File List</h1>
|
25
|
+
<div id="full_list_nav">
|
26
|
+
|
27
|
+
<span><a target="_self" href="class_list.html">
|
28
|
+
Classes
|
29
|
+
</a></span>
|
30
|
+
|
31
|
+
<span><a target="_self" href="method_list.html">
|
32
|
+
Methods
|
33
|
+
</a></span>
|
34
|
+
|
35
|
+
<span><a target="_self" href="file_list.html">
|
36
|
+
Files
|
37
|
+
</a></span>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">Search: <input type="text" /></div>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<ul id="full_list" class="file">
|
45
|
+
|
46
|
+
|
47
|
+
<li id="object_README" class="odd">
|
48
|
+
<div class="item"><span class="object_link"><a href="index.html" title="README">README</a></span></div>
|
49
|
+
</li>
|
50
|
+
|
51
|
+
|
52
|
+
<li id="object_CHANGELOG" class="even">
|
53
|
+
<div class="item"><span class="object_link"><a href="file.CHANGELOG.html" title="CHANGELOG">CHANGELOG</a></span></div>
|
54
|
+
</li>
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
</ul>
|
59
|
+
</div>
|
60
|
+
</body>
|
61
|
+
</html>
|
data/doc/frames.html
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>Documentation by YARD 0.9.12</title>
|
6
|
+
</head>
|
7
|
+
<script type="text/javascript" charset="utf-8">
|
8
|
+
var match = unescape(window.location.hash).match(/^#!(.+)/);
|
9
|
+
var name = match ? match[1] : 'index.html';
|
10
|
+
name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
|
11
|
+
window.top.location = name;
|
12
|
+
</script>
|
13
|
+
<noscript>
|
14
|
+
<h1>Oops!</h1>
|
15
|
+
<h2>YARD requires JavaScript!</h2>
|
16
|
+
</noscript>
|
17
|
+
</html>
|
data/doc/index.html
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.12
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "README";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
<span class="title">File: README</span>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="search">
|
45
|
+
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
47
|
+
href="class_list.html">
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
54
|
+
</a>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div id="content"><div id='filecontents'><h1>Repository::Base</h1>
|
61
|
+
|
62
|
+
<p><a href="https://gitter.im/jdickey/repository-base?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><img src="https://badges.gitter.im/Join%20Chat.svg" alt="Join the chat at https://gitter.im/jdickey/repository-base" /></a>
|
63
|
+
<a href="http://badge.fury.io/rb/repository-base"><img src="https://badge.fury.io/rb/repository-base.svg" alt="Gem Version" /></a>
|
64
|
+
<a href="https://codeclimate.com/github/jdickey/repository-base"><img src="https://codeclimate.com/github/jdickey/repository-base.png" alt="Code Climate" /></a>
|
65
|
+
<a href="https://codeship.com/projects/63061"> <img src="https://codeship.com/projects/ae57fed0-969f-0132-1faa-76c54edd661d/status?branch=master" alt="Codeship Status for jdickey/repository-base" /></a>
|
66
|
+
<a href="https://hakiri.io/github/jdickey/repository-base/master"><img src="https://hakiri.io/github/jdickey/repository-base/master.svg" alt="security" /></a>
|
67
|
+
<a href="https://gemnasium.com/jdickey/repository-base"><img src="https://gemnasium.com/jdickey/repository-base.svg" alt="Dependency Status" /></a>
|
68
|
+
<a href="http://inch-ci.org/github/jdickey/repository-base"><img src="http://inch-ci.org/github/jdickey/repository-base.svg?style=shields" alt="Inline docs" /></a></p>
|
69
|
+
|
70
|
+
<p>This Gem supplies a class, <code>Repository::Base</code>, which can be used as a base class
|
71
|
+
for Repositories in an application that uses the
|
72
|
+
<a href="http://martinfowler.com/eaaCatalog/dataMapper.html">Data Mapper pattern</a>.
|
73
|
+
As described by Fowler, Data Mapper “moves data between objects and a database
|
74
|
+
while keeping them independent of each other and the mapper itself”.</p>
|
75
|
+
|
76
|
+
<p>This was originally developed within the structure of an R&D test-bed application,
|
77
|
+
<a href="https://github.com/jdickey/new_poc"><code>new_poc</code></a>. That app has a fairly wide-ranging
|
78
|
+
history; after browsing its README and
|
79
|
+
<a href="https://github.com/jdickey/new_poc/commits">commit history</a>, you may find Pull
|
80
|
+
Requests <a href="https://github.com/jdickey/new_poc/pull/153">#153</a> and
|
81
|
+
<a href="https://github.com/jdickey/new_poc/pull/153">#200</a> informative as to the
|
82
|
+
historical basis of this code.</p>
|
83
|
+
|
84
|
+
<h2>Contents</h2>
|
85
|
+
|
86
|
+
<ul>
|
87
|
+
<li><a href="#installation">Installation</a></li>
|
88
|
+
<li><a href="#usage">Usage</a>
|
89
|
+
<ul>
|
90
|
+
<li><a href="#important-legacy-notice">IMPORTANT LEGACY NOTICE</a></li>
|
91
|
+
<li><a href="#concepts">Concepts</a>
|
92
|
+
<ul>
|
93
|
+
<li><a href="#entities">Entities</a></li>
|
94
|
+
<li><a href="#entity-factories">Entity Factories</a></li>
|
95
|
+
<li><a href="#storeresult">StoreResult</a></li>
|
96
|
+
<li><a href="#repositorybase-instance-methods"><code>Repository::Base</code> Instance Methods</a></li>
|
97
|
+
</ul>
|
98
|
+
</li>
|
99
|
+
<li><a href="#more-details">More Details</a></li>
|
100
|
+
</ul>
|
101
|
+
</li>
|
102
|
+
<li><a href="#contributing">Contributing</a></li>
|
103
|
+
</ul>
|
104
|
+
|
105
|
+
<h2 id="installation">Installation</h2>
|
106
|
+
|
107
|
+
<p>Add this line to your application’s Gemfile:</p>
|
108
|
+
|
109
|
+
<p><code>ruby
|
110
|
+
gem 'repository-base'
|
111
|
+
</code></p>
|
112
|
+
|
113
|
+
<p>And then execute:</p>
|
114
|
+
|
115
|
+
<pre class="code ruby"><code class="ruby">$ bundle
|
116
|
+
</code></pre>
|
117
|
+
|
118
|
+
<p>Or install it yourself as:</p>
|
119
|
+
|
120
|
+
<pre class="code ruby"><code class="ruby">$ gem install repository-base
|
121
|
+
</code></pre>
|
122
|
+
|
123
|
+
<h2 id="usage">Usage</h2>
|
124
|
+
|
125
|
+
<h3 id="important-legacy-notice">IMPORTANT LEGACY NOTICE</h3>
|
126
|
+
|
127
|
+
<p><strong><em>NOTICE!</em></strong> This Gem was created to support a solo, ad-hoc, early learning experience in what is now known as Clean Architecture. It was part of our first attempt to build an alternative to the ActiveRecord/ActiveModel scheme native to Ruby on Rails.</p>
|
128
|
+
|
129
|
+
<p>As such, it has been superseded and far outshone by other, team efforts, notably <a href="http://rom-rb.org/">ROM</a> as used with <a href="http://hanamirb.org/">Hanami</a> and <a href="http://trailblazer.to/">Trailblazer</a>. You are <em>strongly advised</em> to examine these and other tools rather than to use this for <em>any</em> new development. The Gem is being republished as an 0.4.0 release purely for internal archaeological purposes.</p>
|
130
|
+
|
131
|
+
<h3 id="concepts">Concepts</h3>
|
132
|
+
|
133
|
+
<p>As mentioned at the top of this file, <code>Repository::Base</code> is intended to serve as
|
134
|
+
the base class for your app’s Repositories. As with most Data Mapper
|
135
|
+
implementations, it makes use of a database access object, or DAO, which you
|
136
|
+
specify as one of the two parameters to <code>#initialize</code>. The other parameter is an
|
137
|
+
“entity factory”, whose <code>.create</code> class method hands back an “entity” reflecting
|
138
|
+
the content of an individual record in the underlying DAO.</p>
|
139
|
+
|
140
|
+
<h4 id="entities">Entities</h4>
|
141
|
+
|
142
|
+
<p>What is an “entity”? It’s a domain object in your application, with methods
|
143
|
+
expressing the business logic applicable to the object represented by the underlying
|
144
|
+
database record. This is distinct from an ActiveRecord-style <em>model</em>, in that
|
145
|
+
more than one variation of entity may exist in your application for a given DAO.
|
146
|
+
Most applications have Users, for example; some applications may have distinct
|
147
|
+
variation of User <em>entities</em> (ordinary punters, admins, a “guest user” entity
|
148
|
+
representing a user who has not authenticated as a more-privileged user, etc),
|
149
|
+
that all share a common persistence layer (the underlying DAO) and an entity
|
150
|
+
factory that <em>knows</em> how to create the correct type of entity for a given DAO
|
151
|
+
record.</p>
|
152
|
+
|
153
|
+
<p>An entity is uniquely identified by a <em>slug</em> rather than a numeric ID. Generally,
|
154
|
+
a slug encodes textual, relatively SEO-friendly information corresponding to an
|
155
|
+
individual record (the title of an article, the name of a user, etc) such that
|
156
|
+
the corresponding record may be uniquely identified by the DAO. This is in
|
157
|
+
preference to a “traditional” numeric record ID number; <code>Repository::Base</code> has
|
158
|
+
no knowledge of nor direct support for numeric record IDs.</p>
|
159
|
+
|
160
|
+
<h4 id="entity-factories">Entity Factories</h4>
|
161
|
+
|
162
|
+
<p>Again, the entity factory, one of the parameters to this class’ <code>#initialize</code>
|
163
|
+
method, is responsible for creating an entity from a DAO instance (record). The
|
164
|
+
<code>Repository::Base</code> class knows nothing of the details of how that is done; it
|
165
|
+
simply calls methods on the DAO and/or entity factory to accomplish the tasks
|
166
|
+
encapsulated by its own individual methods.</p>
|
167
|
+
|
168
|
+
<h4 id="storeresult">StoreResult</h4>
|
169
|
+
|
170
|
+
<p>What is a <code>StoreResult</code>? It is a simple value object which communicates the
|
171
|
+
result of a call to a method on the underlying DAO <em>as reported by the DAO</em>,
|
172
|
+
with the following properties:</p>
|
173
|
+
|
174
|
+
<ul>
|
175
|
+
<li><code>success?</code> (accessible as <code>result.success?</code> or as <code>result[:success?]</code>), has the value <code>true</code> after a successful operation or <code>false</code> after an unsuccessful one;</li>
|
176
|
+
<li><code>entity</code> (<code>result.entity</code> or <code>result[:entity]</code>) is the instance or enumeration of instances of your domain entity resulting from a successful operation. After an unsuccessful operation, this property will be <code>nil</code>;</li>
|
177
|
+
<li><code>errors</code> (<code>result.errors</code> or <code>result[:errors]</code>) is an Array-like object which is empty after a successful operation. After an unsuccessful operation, it will contain an Array of Hash instances, with each Hash having a key identifying the field or similar concept for which an individual error is being reported, and a value of the specific error message. For example, to report that a <code>:name</code> field was empty or blank, you might have a Hash of `{ name: ‘is empty or blank’ }. Your application domain logic should then understand how to deal with that convention.</li>
|
178
|
+
</ul>
|
179
|
+
|
180
|
+
<h4 id="repositorybase-instance-methods"><code>Repository::Base</code> Instance Methods</h4>
|
181
|
+
|
182
|
+
<ul>
|
183
|
+
<li><code>#add</code> adds a new record to the underlying <em>DAO</em> (data-access object; see above) using the field values specified by the <em>entity</em> passed as the only parameter. Returns a <code>StoreResult</code> (see above) which indicates the success or failure of the operation. On success, the <code>StoreResult</code> contains a <em>new</em> entity that represents the state of the record added to the underlying DAO;</li>
|
184
|
+
<li><code>#all</code> returns a collection of entities matching all records as reported by the underlying DAO, with entities created by the appropriate entity factory;</li>
|
185
|
+
<li><code>#delete</code> instructs the DAO to delete the record corresponding to the specified <code>slug</code>. Returns a <code>StoreResult</code> with an entity corresponding to the deleted record on success, or with appropriate error message(s) on failure;</li>
|
186
|
+
<li><code>#find_by_slug</code> instructs the DAO to retrieve the record whose unique slug value matches the supplied parameter. On success, returns a <code>StoreResult</code> with an entity corresponding to the selected record; on failure, the <code>StoreResult</code> has an <code>entity</code> value of <code>nil</code> and appropriate error messages in <code>errors</code>;</li>
|
187
|
+
<li><code>update</code> causes the DAO to attempt to update the record identified by the passed-in slug using the passed-in field values. On success, returns a <code>StoreResult</code> whose <code>entity</code> value mirrors the updated DAO record; on failure, has appropriate error indications in the <code>StoreResult</code>’s <code>errors</code> property.</li>
|
188
|
+
</ul>
|
189
|
+
|
190
|
+
<h3 id="more-details">More Details</h3>
|
191
|
+
|
192
|
+
<p>This Gem now has <a href="./doc/index.html">full documentation available</a>. (No, this isn’t 1990s-era <code>rdoc</code>.)</p>
|
193
|
+
|
194
|
+
<p>This Gem was built with <strong>MRI Ruby 2.5.0</strong>. It <strong>is likely to</strong> work when rebuilt with any version after 2.0.0; however, as it makes use of <a href="http://ruby-doc.org//core-2.1.0/doc/syntax/methods_rdoc.html#label-Keyword+Arguments">keyword arguments</a> for various methods, it is <em>incompatible</em> with Ruby 1.9 or earlier.</p>
|
195
|
+
|
196
|
+
<h2 id="contributing">Contributing</h2>
|
197
|
+
|
198
|
+
<ol>
|
199
|
+
<li>Fork it ( https://github.com/jdickey/repository-base/fork )</li>
|
200
|
+
<li>Create your feature branch (<code>git checkout -b my-new-feature</code>)</li>
|
201
|
+
<li>Ensure that your changes are completely covered by <em>passing</em> specs, and comply with the <a href="https://github.com/bbatsov/ruby-style-guide">Ruby Style Guide</a> as enforced by <a href="https://github.com/bbatsov/rubocop">RuboCop</a>. To verify this, run <code>bundle exec rake</code>, noting and repairing any lapses in coverage or style violations;</li>
|
202
|
+
<li>Commit your changes (<code>git commit -a</code>). Please <em>do not</em> use a single-line commit message (<code>git commit -am "some message"</code>). A good commit message notes what was changed and why in sufficient detail that a relative newcomer to the code can understand your reasoning and your code;</li>
|
203
|
+
<li>Push to the branch (<code>git push origin my-new-feature</code>)</li>
|
204
|
+
<li>Create a new Pull Request. Describe at some length the rationale for your new feature; your implementation strategy at a higher level than each individual commit message; anything future maintainers should be aware of; and so on. <em>If this is a modification to existing code, reference the open issue being addressed</em>.</li>
|
205
|
+
<li>Don’t be discouraged if the PR generates a discussion that leads to further refinement of your PR through additional commits. These should <em>generally</em> be discussed in comments on the PR itself; discussion in the Gitter room (see below) may also be useful;</li>
|
206
|
+
<li>If you’ve comments, questions, or just want to talk through your ideas, don’t hesitate to hang out in the project’s <a href="https://gitter.im/jdickey/repository-base">room on Gitter</a>. Ask away!</li>
|
207
|
+
</ol>
|
208
|
+
</div></div>
|
209
|
+
|
210
|
+
<div id="footer">
|
211
|
+
Generated on Sat Feb 3 03:00:17 2018 by
|
212
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
213
|
+
0.9.12 (ruby-2.5.0).
|
214
|
+
</div>
|
215
|
+
|
216
|
+
</div>
|
217
|
+
</body>
|
218
|
+
</html>
|
data/doc/js/app.js
ADDED
@@ -0,0 +1,248 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
var localStorage = {}, sessionStorage = {};
|
4
|
+
try { localStorage = window.localStorage; } catch (e) { }
|
5
|
+
try { sessionStorage = window.sessionStorage; } catch (e) { }
|
6
|
+
|
7
|
+
function createSourceLinks() {
|
8
|
+
$('.method_details_list .source_code').
|
9
|
+
before("<span class='showSource'>[<a href='#' class='toggleSource'>View source</a>]</span>");
|
10
|
+
$('.toggleSource').toggle(function() {
|
11
|
+
$(this).parent().nextAll('.source_code').slideDown(100);
|
12
|
+
$(this).text("Hide source");
|
13
|
+
},
|
14
|
+
function() {
|
15
|
+
$(this).parent().nextAll('.source_code').slideUp(100);
|
16
|
+
$(this).text("View source");
|
17
|
+
});
|
18
|
+
}
|
19
|
+
|
20
|
+
function createDefineLinks() {
|
21
|
+
var tHeight = 0;
|
22
|
+
$('.defines').after(" <a href='#' class='toggleDefines'>more...</a>");
|
23
|
+
$('.toggleDefines').toggle(function() {
|
24
|
+
tHeight = $(this).parent().prev().height();
|
25
|
+
$(this).prev().css('display', 'inline');
|
26
|
+
$(this).parent().prev().height($(this).parent().height());
|
27
|
+
$(this).text("(less)");
|
28
|
+
},
|
29
|
+
function() {
|
30
|
+
$(this).prev().hide();
|
31
|
+
$(this).parent().prev().height(tHeight);
|
32
|
+
$(this).text("more...");
|
33
|
+
});
|
34
|
+
}
|
35
|
+
|
36
|
+
function createFullTreeLinks() {
|
37
|
+
var tHeight = 0;
|
38
|
+
$('.inheritanceTree').toggle(function() {
|
39
|
+
tHeight = $(this).parent().prev().height();
|
40
|
+
$(this).parent().toggleClass('showAll');
|
41
|
+
$(this).text("(hide)");
|
42
|
+
$(this).parent().prev().height($(this).parent().height());
|
43
|
+
},
|
44
|
+
function() {
|
45
|
+
$(this).parent().toggleClass('showAll');
|
46
|
+
$(this).parent().prev().height(tHeight);
|
47
|
+
$(this).text("show all");
|
48
|
+
});
|
49
|
+
}
|
50
|
+
|
51
|
+
function searchFrameButtons() {
|
52
|
+
$('.full_list_link').click(function() {
|
53
|
+
toggleSearchFrame(this, $(this).attr('href'));
|
54
|
+
return false;
|
55
|
+
});
|
56
|
+
window.addEventListener('message', function(e) {
|
57
|
+
if (e.data === 'navEscape') {
|
58
|
+
$('#nav').slideUp(100);
|
59
|
+
$('#search a').removeClass('active inactive');
|
60
|
+
$(window).focus();
|
61
|
+
}
|
62
|
+
});
|
63
|
+
|
64
|
+
$(window).resize(function() {
|
65
|
+
if ($('#search:visible').length === 0) {
|
66
|
+
$('#nav').removeAttr('style');
|
67
|
+
$('#search a').removeClass('active inactive');
|
68
|
+
$(window).focus();
|
69
|
+
}
|
70
|
+
});
|
71
|
+
}
|
72
|
+
|
73
|
+
function toggleSearchFrame(id, link) {
|
74
|
+
var frame = $('#nav');
|
75
|
+
$('#search a').removeClass('active').addClass('inactive');
|
76
|
+
if (frame.attr('src') === link && frame.css('display') !== "none") {
|
77
|
+
frame.slideUp(100);
|
78
|
+
$('#search a').removeClass('active inactive');
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
$(id).addClass('active').removeClass('inactive');
|
82
|
+
if (frame.attr('src') !== link) frame.attr('src', link);
|
83
|
+
frame.slideDown(100);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
function linkSummaries() {
|
88
|
+
$('.summary_signature').click(function() {
|
89
|
+
document.location = $(this).find('a').attr('href');
|
90
|
+
});
|
91
|
+
}
|
92
|
+
|
93
|
+
function summaryToggle() {
|
94
|
+
$('.summary_toggle').click(function(e) {
|
95
|
+
e.preventDefault();
|
96
|
+
localStorage.summaryCollapsed = $(this).text();
|
97
|
+
$('.summary_toggle').each(function() {
|
98
|
+
$(this).text($(this).text() == "collapse" ? "expand" : "collapse");
|
99
|
+
var next = $(this).parent().parent().nextAll('ul.summary').first();
|
100
|
+
if (next.hasClass('compact')) {
|
101
|
+
next.toggle();
|
102
|
+
next.nextAll('ul.summary').first().toggle();
|
103
|
+
}
|
104
|
+
else if (next.hasClass('summary')) {
|
105
|
+
var list = $('<ul class="summary compact" />');
|
106
|
+
list.html(next.html());
|
107
|
+
list.find('.summary_desc, .note').remove();
|
108
|
+
list.find('a').each(function() {
|
109
|
+
$(this).html($(this).find('strong').html());
|
110
|
+
$(this).parent().html($(this)[0].outerHTML);
|
111
|
+
});
|
112
|
+
next.before(list);
|
113
|
+
next.toggle();
|
114
|
+
}
|
115
|
+
});
|
116
|
+
return false;
|
117
|
+
});
|
118
|
+
if (localStorage.summaryCollapsed == "collapse") {
|
119
|
+
$('.summary_toggle').first().click();
|
120
|
+
} else { localStorage.summaryCollapsed = "expand"; }
|
121
|
+
}
|
122
|
+
|
123
|
+
function generateTOC() {
|
124
|
+
if ($('#filecontents').length === 0) return;
|
125
|
+
var _toc = $('<ol class="top"></ol>');
|
126
|
+
var show = false;
|
127
|
+
var toc = _toc;
|
128
|
+
var counter = 0;
|
129
|
+
var tags = ['h2', 'h3', 'h4', 'h5', 'h6'];
|
130
|
+
var i;
|
131
|
+
if ($('#filecontents h1').length > 1) tags.unshift('h1');
|
132
|
+
for (i = 0; i < tags.length; i++) { tags[i] = '#filecontents ' + tags[i]; }
|
133
|
+
var lastTag = parseInt(tags[0][1], 10);
|
134
|
+
$(tags.join(', ')).each(function() {
|
135
|
+
if ($(this).parents('.method_details .docstring').length != 0) return;
|
136
|
+
if (this.id == "filecontents") return;
|
137
|
+
show = true;
|
138
|
+
var thisTag = parseInt(this.tagName[1], 10);
|
139
|
+
if (this.id.length === 0) {
|
140
|
+
var proposedId = $(this).attr('toc-id');
|
141
|
+
if (typeof(proposedId) != "undefined") this.id = proposedId;
|
142
|
+
else {
|
143
|
+
var proposedId = $(this).text().replace(/[^a-z0-9-]/ig, '_');
|
144
|
+
if ($('#' + proposedId).length > 0) { proposedId += counter; counter++; }
|
145
|
+
this.id = proposedId;
|
146
|
+
}
|
147
|
+
}
|
148
|
+
if (thisTag > lastTag) {
|
149
|
+
for (i = 0; i < thisTag - lastTag; i++) {
|
150
|
+
var tmp = $('<ol/>'); toc.append(tmp); toc = tmp;
|
151
|
+
}
|
152
|
+
}
|
153
|
+
if (thisTag < lastTag) {
|
154
|
+
for (i = 0; i < lastTag - thisTag; i++) toc = toc.parent();
|
155
|
+
}
|
156
|
+
var title = $(this).attr('toc-title');
|
157
|
+
if (typeof(title) == "undefined") title = $(this).text();
|
158
|
+
toc.append('<li><a href="#' + this.id + '">' + title + '</a></li>');
|
159
|
+
lastTag = thisTag;
|
160
|
+
});
|
161
|
+
if (!show) return;
|
162
|
+
html = '<div id="toc"><p class="title hide_toc"><a href="#"><strong>Table of Contents</strong></a></p></div>';
|
163
|
+
$('#content').prepend(html);
|
164
|
+
$('#toc').append(_toc);
|
165
|
+
$('#toc .hide_toc').toggle(function() {
|
166
|
+
$('#toc .top').slideUp('fast');
|
167
|
+
$('#toc').toggleClass('hidden');
|
168
|
+
$('#toc .title small').toggle();
|
169
|
+
}, function() {
|
170
|
+
$('#toc .top').slideDown('fast');
|
171
|
+
$('#toc').toggleClass('hidden');
|
172
|
+
$('#toc .title small').toggle();
|
173
|
+
});
|
174
|
+
}
|
175
|
+
|
176
|
+
function navResizeFn(e) {
|
177
|
+
if (e.which !== 1) {
|
178
|
+
navResizeFnStop();
|
179
|
+
return;
|
180
|
+
}
|
181
|
+
|
182
|
+
sessionStorage.navWidth = e.pageX.toString();
|
183
|
+
$('.nav_wrap').css('width', e.pageX);
|
184
|
+
$('.nav_wrap').css('-ms-flex', 'inherit');
|
185
|
+
}
|
186
|
+
|
187
|
+
function navResizeFnStop() {
|
188
|
+
$(window).unbind('mousemove', navResizeFn);
|
189
|
+
window.removeEventListener('message', navMessageFn, false);
|
190
|
+
}
|
191
|
+
|
192
|
+
function navMessageFn(e) {
|
193
|
+
if (e.data.action === 'mousemove') navResizeFn(e.data.event);
|
194
|
+
if (e.data.action === 'mouseup') navResizeFnStop();
|
195
|
+
}
|
196
|
+
|
197
|
+
function navResizer() {
|
198
|
+
$('#resizer').mousedown(function(e) {
|
199
|
+
e.preventDefault();
|
200
|
+
$(window).mousemove(navResizeFn);
|
201
|
+
window.addEventListener('message', navMessageFn, false);
|
202
|
+
});
|
203
|
+
$(window).mouseup(navResizeFnStop);
|
204
|
+
|
205
|
+
if (sessionStorage.navWidth) {
|
206
|
+
navResizeFn({which: 1, pageX: parseInt(sessionStorage.navWidth, 10)});
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
function navExpander() {
|
211
|
+
var done = false, timer = setTimeout(postMessage, 500);
|
212
|
+
function postMessage() {
|
213
|
+
if (done) return;
|
214
|
+
clearTimeout(timer);
|
215
|
+
var opts = { action: 'expand', path: pathId };
|
216
|
+
document.getElementById('nav').contentWindow.postMessage(opts, '*');
|
217
|
+
done = true;
|
218
|
+
}
|
219
|
+
|
220
|
+
window.addEventListener('message', function(event) {
|
221
|
+
if (event.data === 'navReady') postMessage();
|
222
|
+
return false;
|
223
|
+
}, false);
|
224
|
+
}
|
225
|
+
|
226
|
+
function mainFocus() {
|
227
|
+
var hash = window.location.hash;
|
228
|
+
if (hash !== '' && $(hash)[0]) {
|
229
|
+
$(hash)[0].scrollIntoView();
|
230
|
+
}
|
231
|
+
|
232
|
+
setTimeout(function() { $('#main').focus(); }, 10);
|
233
|
+
}
|
234
|
+
|
235
|
+
$(document).ready(function() {
|
236
|
+
navResizer();
|
237
|
+
navExpander();
|
238
|
+
createSourceLinks();
|
239
|
+
createDefineLinks();
|
240
|
+
createFullTreeLinks();
|
241
|
+
searchFrameButtons();
|
242
|
+
linkSummaries();
|
243
|
+
summaryToggle();
|
244
|
+
generateTOC();
|
245
|
+
mainFocus();
|
246
|
+
});
|
247
|
+
|
248
|
+
})();
|