├── .github
└── pull_request_template.md
├── .gitignore
├── Gruntfile.js
├── LICENSE
├── README.md
├── VERSION_PREFIX
├── bench
└── bench.js
├── bin
├── build_dev_browser
├── build_dev_browser_amd
├── build_dev_node
├── build_jar
├── build_release_browser
├── build_release_browser_amd
├── build_release_node
├── closure_deps_graph.clj
├── deps
├── docs
├── make_deps_js
├── prelude
└── test
├── build
├── package_local
├── release
└── revision
├── doctheme
├── assets
│ ├── css
│ │ ├── cognitect.jpg
│ │ ├── external-small.png
│ │ ├── logo.png
│ │ └── main.css
│ ├── js
│ │ ├── tabs.js
│ │ └── yui-prettify.js
│ └── vendor
│ │ └── prettify
│ │ ├── CHANGES.html
│ │ ├── COPYING
│ │ ├── README.html
│ │ ├── prettify-min.css
│ │ └── prettify-min.js
├── layouts
│ └── main.handlebars
├── partials
│ ├── attrs.handlebars
│ ├── classes.handlebars
│ ├── events.handlebars
│ ├── files.handlebars
│ ├── index.handlebars
│ ├── method.handlebars
│ ├── module.handlebars
│ ├── props.handlebars
│ └── sidebar.handlebars
└── theme.json
├── package.json
├── pom.xml
├── resources
├── amd_externs.js
├── externs.js
├── node_externs.js
└── prelude.txt
├── src
└── com
│ └── cognitect
│ ├── transducers.js
│ └── transducers_amd.js
├── test
└── tests.js
├── transducers-js.iml
└── yuidoc.json
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | Hi! Thanks for your interest in contributing to this project.
2 |
3 | Because transducers-js may be incorporated into products or client
4 | projects, we prefer to do development internally and do not accept
5 | pull requests or patches. Issues can be filed using GitHub issues.
6 |
7 | - Contributing : https://github.com/cognitect-labs/transducers-js#contributing
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | docs
2 | npm-debug.log
3 | deps
4 | node_modules
5 | target/*
6 | .idea
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | /*global module:false*/
2 | module.exports = function(grunt) {
3 |
4 | // Project configuration.
5 | grunt.initConfig({
6 | // Metadata.
7 | pkg: grunt.file.readJSON('package.json'),
8 | banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
9 | '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
10 | '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
11 | '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
12 | ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
13 | // Task configuration.
14 | concat: {
15 | options: {
16 | banner: '<%= banner %>',
17 | stripBanners: true
18 | },
19 | dist: {
20 | src: ['lib/<%= pkg.name %>.js'],
21 | dest: 'dist/<%= pkg.name %>.js'
22 | }
23 | },
24 | jshint: {
25 | options: {
26 | curly: true,
27 | eqeqeq: true,
28 | immed: true,
29 | latedef: true,
30 | newcap: true,
31 | noarg: true,
32 | sub: true,
33 | undef: true,
34 | unused: true,
35 | boss: true,
36 | eqnull: true,
37 | globals: {}
38 | },
39 | gruntfile: {
40 | src: 'Gruntfile.js'
41 | },
42 | lib_test: {
43 | src: ['lib/**/*.js', 'test/**/*.js']
44 | }
45 | },
46 | nodeunit: {
47 | files: ['test/**/*.js']
48 | },
49 | watch: {
50 | gruntfile: {
51 | files: '<%= jshint.gruntfile.src %>',
52 | tasks: ['jshint:gruntfile']
53 | },
54 | lib_test: {
55 | files: '<%= jshint.lib_test.src %>',
56 | tasks: ['jshint:lib_test', 'nodeunit']
57 | }
58 | }
59 | });
60 |
61 | // These plugins provide necessary tasks.
62 | grunt.loadNpmTasks('grunt-contrib-concat');
63 | grunt.loadNpmTasks('grunt-contrib-nodeunit');
64 | grunt.loadNpmTasks('grunt-contrib-jshint');
65 | grunt.loadNpmTasks('grunt-contrib-watch');
66 |
67 | // Default task.
68 | grunt.registerTask('default', ['jshint', 'nodeunit', 'concat', 'uglify']);
69 |
70 | };
71 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # This library is no longer maintained, feel free to fork and update as per the license
2 |
3 | # transducers-js
4 |
5 | A high performance
6 | [Transducers](http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming)
7 | implementation for JavaScript.
8 |
9 | Transducers are composable algorithmic transformations. They are
10 | independent from the context of their input and output sources and
11 | specify only the essence of the transformation in terms of an
12 | individual element. Because transducers are decoupled from input or
13 | output sources, they can be used in many different processes -
14 | collections, streams, channels, observables, etc. Transducers compose
15 | directly, without awareness of input or creation of intermediate
16 | aggregates.
17 |
18 | For further details about Transducers see the following resources:
19 | * ["Transducers are coming" announce blog post](http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming)
20 | * [Rich Hickey's Transducers StrangeLoop presentation](https://www.youtube.com/watch?v=6mTbuzafcII)
21 | * [API Docs](http://cognitect-labs.github.io/transducers-js/classes/transducers.html)
22 |
23 | transducers-js is brought to you by [Cognitect Labs](http://cognitect-labs.github.io/).
24 |
25 | ## Releases and Dependency Information
26 |
27 | * Latest release: 0.4.180
28 |
29 | ### JavaScript
30 |
31 | You can include either the [release](http://cdn.cognitect.com/transducers/transducers-0.4.180-min.js) (2K gzipped) or [development](http://cdn.cognitect.com/transducers/transducers-0.4.180.js) build of transducers-js on your webpage. We also provide [Require.js](http://requirejs.org) compatible [release](http://cdn.cognitect.com/transducers/transducers-0.4.180-amd-min.js) and [dev](http://cdn.cognitect.com/transducers/transducers-0.4.180-amd.js) builds.
32 |
33 | ### Node.js
34 |
35 | transducers-js is released to [npm](https://www.npmjs.org). Add transducers-js to your `package.json` dependencies:
36 |
37 | ```javascript
38 | {...
39 | "dependencies": {
40 | "transducers-js": "0.4.180"
41 | }
42 | ...}
43 | ```
44 |
45 | ### Bower
46 |
47 | You can also include transducers-js in your `bower.json` dependencies:
48 |
49 | ```javascript
50 | {...
51 | "dependencies": {
52 | "transducers-js": "0.4.180"
53 | }
54 | ...}
55 | ```
56 |
57 | ## Usage
58 |
59 | ### Requiring
60 |
61 | To import the library under Node.js you can just use `require`:
62 |
63 | ```js
64 | var t = require("transducers-js");
65 | ```
66 |
67 | The browser release of the library simply exports a top level
68 | `transducers` object:
69 |
70 | ```js
71 | var t = transducers;
72 | ```
73 |
74 | ### Basic Usage
75 |
76 | With <=ES5:
77 |
78 | ```js
79 | var map = t.map,
80 | filter = t.filter,
81 | comp = t.comp,
82 | into = t.into;
83 |
84 | var inc = function(n) { return n + 1; };
85 | var isEven = function(n) { return n % 2 == 0; };
86 | var xf = comp(map(inc), filter(isEven));
87 |
88 | console.log(into([], xf, [0,1,2,3,4])); // [2,4]
89 | ```
90 |
91 | With ES6:
92 |
93 | ```js
94 | let {map, filter, comp, into} = t;
95 |
96 | let inc = (n) => n + 1;
97 | let isEven = (n) => n % 2 == 0;
98 | let xf = comp(map(inc), filter(isEven));
99 |
100 | console.log(into([], xf, [0,1,2,3,4])); // [2,4]
101 | ```
102 |
103 | ## Documentation
104 |
105 | Documentation can be found [here](http://cognitect-labs.github.io/transducers-js/classes/transducers.html)
106 |
107 | ## Integration
108 |
109 | transducers-js can also easily be used in combination with *existing*
110 | reduce implementations, whether native or the shims provided by
111 | [Underscore](http://underscorejs.org) and
112 | [Lodash](http://lodash.com). Doing so with native and Underscore can
113 | deliver significant performance benefits. Transducers may be easily
114 | converted from their object representation into the necessary
115 | two-arity function via `toFn`.
116 |
117 | ```js
118 | var arr = [0,1,2,3,4,5,6,7,8,9,10],
119 | apush = function(arr, x) { arr.push(x); return arr; },
120 | xf = comp(map(inc), filter(isEven)),
121 | toFn = t.toFn;
122 |
123 | arr.reduce(toFn(xf, apush), []); // native
124 | _(arr).reduce(toFn(xf, apush), []); // underscore or lodash
125 | ```
126 |
127 | ### Immutable-js
128 |
129 | transducers-js can work with custom collection types and still
130 | deliver the same performance benefits, for example with Immutable-js:
131 |
132 | ```js
133 | var Immutable = require("immutable"),
134 | t = require("transducers-js"),
135 | comp = t.comp,
136 | map = t.map,
137 | filter = t.filter,
138 | transduce = t.transduce;
139 |
140 | var inc = function(n) { return n + 1; };
141 | var isEven = function(n) { return n % 2 == 0; };
142 | var sum = function(a,b) { return a+b; };
143 |
144 | var largeVector = Immutable.List();
145 |
146 | for(var i = 0; i < 1000000; i++) {
147 | largeVector = largeVector.push(i);
148 | }
149 |
150 | // built in Immutable-js functionality
151 | largeVector.map(inc).filter(isEven).reduce(sum);
152 |
153 | // faster with transducers
154 | var xf = comp(map(inc),filter(isEven));
155 | transduce(xf, sum, 0, largeVector);
156 | ```
157 |
158 | ### ES6 Collections
159 |
160 | ES6 collections return iterators and therefore can be
161 | reduced/transduced. For example with
162 | [transit-js](https://github.com/cognitect/transit-js) collections
163 | which satisfy many of the proposed Map/Set methods:
164 |
165 | ```js
166 | var transit = require("transit-js"),
167 | t = require("transducers-js"),
168 | m = transit.map(["foo", "bar", "baz", "woz"]),
169 | vUC = function(kv) { return [kv[0], kv[1].toUpperCase()]; },
170 | xf = t.map(vUC);
171 | madd = function(m, kv) { m.set(kv[0], kv[1]); return m; };
172 |
173 | transduce(xf, madd, transit.map(), m.entries()); // Map ["foo", "BAR", "baz", "WOZ"]
174 | ```
175 |
176 | ## The Transducer Protocol
177 |
178 | It is a goal that all JavaScript transducer implementations
179 | interoperate regardless of the surface level API. Towards this end the
180 | following outlines the protocol all transducers must follow.
181 |
182 | ### Transducer composition
183 |
184 | Transducers are simply a function of one arity. The only argument
185 | is another transducer *transformer* (labeled `xf` in the code base).
186 | Note the distinction between the *transducer* which is a function of
187 | one argument and the *transformer* an object whose methods we'll
188 | describe in the following section.
189 |
190 | For example the following simplified definition of `map`:
191 |
192 | ```js
193 | var map = function(f) {
194 | return function(xf) {
195 | return Map(f, xf);
196 | };
197 | };
198 | ```
199 |
200 | Since transducers are simply functions of one argument they can be
201 | composed easily via function composition to create transformer
202 | pipelines. Note that transducers return transformers when invoked.
203 |
204 | ### Transformer protocol
205 |
206 | Transformers are objects. They must implement 3 methods, `@@transducer/init`,
207 | `@@transducer/result` and `@@transducer/step`. If a transformer is intended to
208 | be composed with other transformers they should either close over the next
209 | transformer or store it in a field.
210 |
211 | For example the `Map` transformer could look something like the
212 | following:
213 |
214 | ```js
215 | var Map = function(f, xf) {
216 | return {
217 | "@@transducer/init": function() {
218 | return xf["@@transducer/init"]();
219 | },
220 | "@@transducer/result": function(result) {
221 | return xf["@@transducer/result"](result);
222 | },
223 | "@@transducer/step": function(result, input) {
224 | return xf["@@transducer/step"](result, f(input));
225 | }
226 | };
227 | };
228 | ```
229 |
230 | Note how we take care to call the next transformer in the pipeline. We
231 | could have of course created `Map` as a proper JavaScript type with
232 | prototype methods - this is in fact how it is done in transducers-js.
233 |
234 | ### Reduced
235 |
236 | Detecting the reduced state is critical to short circuiting a
237 | reduction/transduction. A reduced value is denoted by any JavaScript
238 | object that has the property `@@transducer/reduced` set to `true`.
239 | The reduced value should be stored in the `@@transducer/value` property of this
240 | object.
241 |
242 | ### Iteration
243 |
244 | Anything which implements `@@iterator` which returns an ES6 compliant
245 | iterator is reducible/transducible. An ES6 iterator may also just be given directly to `reduce` or `transduce`.
246 |
247 | ## Building
248 |
249 | Fetch the dependencies:
250 |
251 | ```
252 | bin/deps
253 | ```
254 |
255 | To build for Node.js
256 |
257 | ```
258 | bin/build_release_node
259 | ```
260 |
261 | To build for the browser
262 |
263 | ```
264 | bin/build_release_browser
265 | ```
266 |
267 | ## Running the tests
268 |
269 | Make sure you've first fetched the dependencies, then:
270 |
271 | ```
272 | bin/test
273 | ```
274 |
275 | ## Contributing
276 |
277 | This library is open source, developed internally by [Cognitect](http://cognitect.com). Issues can be filed using [GitHub Issues](https://github.com/cognitect-labs/transducers-js/issues).
278 |
279 | This project is provided without support or guarantee of continued development.
280 | Because transducers-js may be incorporated into products or client projects, we prefer to do development internally and do not accept pull requests or patches.
281 |
282 | ## Copyright and License
283 |
284 | Copyright © 2014-2015 Cognitect
285 |
286 | Licensed under the Apache License, Version 2.0 (the "License");
287 | you may not use this file except in compliance with the License.
288 | You may obtain a copy of the License at
289 |
290 | http://www.apache.org/licenses/LICENSE-2.0
291 |
292 | Unless required by applicable law or agreed to in writing, software
293 | distributed under the License is distributed on an "AS IS" BASIS,
294 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
295 | See the License for the specific language governing permissions and
296 | limitations under the License.
297 |
--------------------------------------------------------------------------------
/VERSION_PREFIX:
--------------------------------------------------------------------------------
1 | 0.4
--------------------------------------------------------------------------------
/bench/bench.js:
--------------------------------------------------------------------------------
1 | // Copyright 2014-2015 Cognitect. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS-IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | "use strict";
16 |
17 | var t = null;
18 | var ld = null;
19 | var ud = null;
20 |
21 | if(typeof require != "undefined") {
22 | t = require("../target/transducers.js");
23 | ld = require("../node_modules/lodash/lodash.js");
24 | ud = require("../node_modules/underscore/underscore.js");
25 | } else {
26 | if(typeof _ != "undefined") {
27 | ld = _;
28 | }
29 | t = transducers;
30 | }
31 |
32 | var map = t.map,
33 | filter = t.filter,
34 | reduce = t.reduce,
35 | transduce = t.transduce,
36 | mapcat = t.mapcat,
37 | reduced = t.reduced,
38 | isReduced = t.isReduced,
39 | comp = t.comp;
40 |
41 | function log(varArgs) {
42 | if(typeof console != "undefined") {
43 | console.log.apply(console, Array.prototype.slice.call(arguments, 0));
44 | } else {
45 | print(Array.prototype.slice.call(arguments, 0).join(" "));
46 | }
47 | }
48 |
49 | function time(f, iters) {
50 | iters = iters || 1;
51 | for(var i = 0; i < iters; i++) {
52 | var s = new Date();
53 | var ret = f();
54 | log(ret, "elapsed "+((new Date()).valueOf()-s.valueOf())+"ms");
55 | log("----------");
56 | }
57 | }
58 |
59 | function inc(n) { return n + 1; };
60 | function isEven(n) { return n % 2 == 0; };
61 | function apush(arr, x) { arr.push(x); return arr; };
62 | function addEntry(obj, entry) { obj[entry[0]] = entry[1]; return obj; };
63 | function ucKeys(entry) { return [entry[0].toUpperCase(), entry[1]]; };
64 | function doubleN(n) { return n + n; };
65 | function squareN(n) { return n * n; };
66 | function reverse(arr) {
67 | var clone = Array.prototype.slice.call(arr, 0);
68 | clone.reverse();
69 | return clone;
70 | };
71 |
72 | log(comp(doubleN,squareN)(3));
73 | log(transduce(map(inc), apush, [], [0,1,2,3,4,5,6,7,8,9]));
74 | log(transduce(filter(isEven), apush, [], [0,1,2,3,4,5,6,7,8,9]));
75 | log(transduce(comp(map(inc), filter(isEven)), apush, [], [0,1,2,3,4,5,6,7,8,9]));
76 | log(transduce(mapcat(reverse), apush, [], [[0,1,2],[3,4,5],[6,7,8]]));
77 | log(transduce(map(ucKeys), addEntry, {}, {foo: 1, bar:2}));
78 |
79 | var xf = comp(map(inc), map(inc), map(inc));
80 |
81 | log(transduce(xf, apush, [], [1,2,3]));
82 |
83 | var largeArray = [];
84 | for(var i = 0; i < 1000000; i++) {
85 | largeArray.push(i);
86 | }
87 |
88 | log("for loop, 1 op")
89 | time(function() {
90 | var ret = [];
91 | for(var i = 0; i < largeArray.length; i++) {
92 | ret.push(inc(largeArray[i]));
93 | }
94 | return ret.length;
95 | });
96 |
97 | log("native map array, 1 op")
98 | time(function() {
99 | return largeArray.map(inc).length;
100 | });
101 |
102 | log("transduce map large array, 1 op")
103 | time(function() {
104 | return transduce(map(inc), apush, [], largeArray).length;
105 | });
106 |
107 | log("for loop, 2 ops")
108 | time(function() {
109 | var ret = [];
110 | for(var i = 0; i < largeArray.length; i++) {
111 | var n = inc(largeArray[i]);
112 | if(isEven(n)) {
113 | ret.push(n);
114 | }
115 | }
116 | return ret.length;
117 | }, 10);
118 |
119 | log("native map/filter array, 2 ops")
120 | time(function() {
121 | return largeArray.map(inc).filter(isEven).length;
122 | }, 10);
123 |
124 | log("transduce map/filter large array, 2 ops")
125 | time(function() {
126 | return transduce(comp(map(inc),filter(isEven)), apush, [], largeArray).length;
127 | }, 10);
128 |
129 | if(ld != null) {
130 | log("lodash map/filter large array, 2 ops")
131 | time(function() {
132 | return ld.chain(largeArray).map(inc).filter(isEven).value().length;
133 | }, 10);
134 | }
135 |
136 | log("transduce map/filter large array, 5 ops")
137 | time(function() {
138 | return transduce(comp(map(inc),map(doubleN),map(inc),map(doubleN)), apush, [], largeArray).length;
139 | },10);
140 |
141 | if(ld != null) {
142 | log("lodash map/filter large array, 5 ops")
143 | time(function () {
144 | return ld.chain(largeArray).map(inc).filter(doubleN).map(inc).map(doubleN).value().length;
145 | }, 10);
146 | }
147 |
--------------------------------------------------------------------------------
/bin/build_dev_browser:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -e
4 |
5 | cd `dirname $0`/..
6 |
7 | mkdir -p target
8 |
9 | prefix=`cat VERSION_PREFIX`
10 | suffix=`build/revision`
11 | version=$prefix.$suffix
12 | prelude=`bin/prelude`
13 | preludenl=$prelude.$'\n'
14 |
15 | java -jar deps/closure-compiler/compiler.jar -O SIMPLE --formatting PRETTY_PRINT \
16 | --generate_exports --output_wrapper "$preludenl;(function(){%output%})();" \
17 | -D TRANSDUCERS_BROWSER_TARGET=true --externs=resources/node_externs.js \
18 | --manage_closure_dependencies --only_closure_dependencies \
19 | --closure_entry_point=com.cognitect.transducers \
20 | --js_output_file=target/transducers-$version.js \
21 | 'deps/closure-library/closure/**.js' 'src/**.js'
22 |
--------------------------------------------------------------------------------
/bin/build_dev_browser_amd:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -e
4 |
5 | cd `dirname $0`/..
6 |
7 | mkdir -p target
8 |
9 | prefix=`cat VERSION_PREFIX`
10 | suffix=`build/revision`
11 | version=$prefix.$suffix
12 | prelude=`bin/prelude`
13 | preludenl=$prelude.$'\n'
14 |
15 | java -jar deps/closure-compiler/compiler.jar -O SIMPLE --formatting PRETTY_PRINT \
16 | --generate_exports --output_wrapper "$preludenl;(function(){%output%})();" \
17 | -D TRANSDUCERS_BROWSER_AMD_TARGET=true --manage_closure_dependencies \
18 | --only_closure_dependencies --closure_entry_point=com.cognitect.transducers.amd \
19 | --js_output_file=target/transducers-$version-amd.js \
20 | 'deps/closure-library/closure/**.js' 'src/**.js'
21 |
--------------------------------------------------------------------------------
/bin/build_dev_node:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -e
4 |
5 | cd `dirname $0`/..
6 |
7 | mkdir -p target
8 |
9 | prefix=`cat VERSION_PREFIX`
10 | suffix=`build/revision`
11 | version=$prefix.$suffix
12 | prelude=`bin/prelude`
13 | preludenl=$prelude.$'\n'
14 |
15 | java -jar deps/closure-compiler/compiler.jar -O SIMPLE --formatting PRETTY_PRINT \
16 | --generate_exports --output_wrapper "$preludenl%output%" -D TRANSDUCERS_NODE_TARGET=true \
17 | --externs=resources/node_externs.js --manage_closure_dependencies \
18 | --only_closure_dependencies --closure_entry_point=com.cognitect.transducers \
19 | --js_output_file=target/transducers.js \
20 | 'deps/closure-library/closure/**.js' 'src/**.js'
--------------------------------------------------------------------------------
/bin/build_jar:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -e
4 |
5 | cd src
6 |
7 | jar cf transducers-js.jar .
8 |
9 | mkdir -p ../target
10 |
11 | mv transducers-js.jar ../target/
--------------------------------------------------------------------------------
/bin/build_release_browser:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -e
4 |
5 | cd `dirname $0`/..
6 |
7 | mkdir -p target
8 |
9 | prefix=`cat VERSION_PREFIX`
10 | suffix=`build/revision`
11 | version=$prefix.$suffix
12 | prelude=`bin/prelude`
13 | preludenl=$prelude.$'\n'
14 |
15 | java -jar deps/closure-compiler/compiler.jar -O ADVANCED --generate_exports \
16 | --output_wrapper "$preludenl;(function(){%output%})();" \
17 | -D TRANSDUCERS_BROWSER_TARGET=true -D TRANSDUCERS_DEV=false \
18 | --externs=resources/externs.js --manage_closure_dependencies \
19 | --only_closure_dependencies --closure_entry_point=com.cognitect.transducers \
20 | --js_output_file=target/transducers-$version-min.js \
21 | 'deps/closure-library/closure/**.js' 'src/**.js'
--------------------------------------------------------------------------------
/bin/build_release_browser_amd:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -e
4 |
5 | cd `dirname $0`/..
6 |
7 | mkdir -p target
8 |
9 | prefix=`cat VERSION_PREFIX`
10 | suffix=`build/revision`
11 | version=$prefix.$suffix
12 | prelude=`bin/prelude`
13 | preludenl=$prelude.$'\n'
14 |
15 | java -jar deps/closure-compiler/compiler.jar -O ADVANCED --generate_exports \
16 | --output_wrapper "$preludenl;(function(){%output%})();" \
17 | -D TRANSDUCERS_BROWSER_AMD_TARGET=true -D TRANSDUCERS_DEV=false \
18 | --externs=resources/amd_externs.js --manage_closure_dependencies \
19 | --only_closure_dependencies --closure_entry_point=com.cognitect.transducers.amd \
20 | --js_output_file=target/transducers-$version-amd-min.js \
21 | 'deps/closure-library/closure/**.js' 'src/**.js'
22 |
--------------------------------------------------------------------------------
/bin/build_release_node:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -e
4 |
5 | cd `dirname $0`/..
6 |
7 | mkdir -p target
8 |
9 | prefix=`cat VERSION_PREFIX`
10 | suffix=`build/revision`
11 | version=$prefix.$suffix
12 | prelude=`bin/prelude`
13 | preludenl=$prelude.$'\n'
14 |
15 | java -jar deps/closure-compiler/compiler.jar -O ADVANCED --generate_exports \
16 | --output_wrapper "$preludenl%output%" -D TRANSDUCERS_NODE_TARGET=true \
17 | -D TRANSDUCERS_DEV=false --externs=resources/node_externs.js \
18 | --manage_closure_dependencies --only_closure_dependencies \
19 | --closure_entry_point=com.cognitect.transducers \
20 | --js_output_file=target/transducers.js \
21 | 'deps/closure-library/closure/**.js' 'src/**.js'
22 |
--------------------------------------------------------------------------------
/bin/closure_deps_graph.clj:
--------------------------------------------------------------------------------
1 | (ns closure-deps-graph
2 | (:require [clojure.java.io :as io])
3 | (:import [java.io File]
4 | [com.google.javascript.jscomp SourceFile BasicErrorManager]
5 | [com.google.javascript.jscomp.deps DepsGenerator DepsGenerator$InclusionStrategy]))
6 |
7 | (defn js-files-in
8 | "Return a sequence of all .js files in the given directory."
9 | [dir]
10 | (filter
11 | #(let [name (.getName ^File %)]
12 | (and (.endsWith name ".js")
13 | (not= \. (first name))))
14 | (file-seq dir)))
15 |
16 | (spit (io/file "deps/closure-library/closure/goog/transducers_deps.js")
17 | (.computeDependencyCalls
18 | (DepsGenerator. (map #(SourceFile/fromFile (io/file %)) '("deps/closure-library/closure/goog/deps.js"))
19 | (map #(SourceFile/fromFile %)
20 | (mapcat (comp js-files-in io/file)
21 | ["src"]))
22 | DepsGenerator$InclusionStrategy/ALWAYS
23 | (.getAbsolutePath (io/file "deps/closure-library/closure/goog"))
24 | (proxy [BasicErrorManager] []
25 | (report [level error]
26 | (println error))
27 | (println [level error]
28 | (println error))))))
--------------------------------------------------------------------------------
/bin/deps:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -e
4 |
5 | cd `dirname $0`/..
6 |
7 | echo "Installing Nodej.s dependencies"
8 |
9 | npm install
10 | npm install grunt-cli
11 |
12 | echo "Installing JVM dependencies"
13 |
14 | rm -rf deps
15 |
16 | mkdir -p deps/closure-compiler
17 | cd deps/closure-compiler
18 | curl -O -s http://dl.google.com/closure-compiler/compiler-latest.zip
19 | unzip -qu compiler-latest.zip
20 | rm compiler-latest.zip
21 | cd ../..
22 |
23 | git clone https://github.com/google/closure-library.git deps/closure-library
24 |
25 | mkdir -p deps/clojure
26 | curl -O http://repo1.maven.org/maven2/org/clojure/clojure/1.6.0/clojure-1.6.0.zip
27 | unzip -qu clojure-1.6.0.zip
28 | mv clojure-1.6.0/clojure-1.6.0.jar deps/clojure
29 | rm -rf clojure-1.6.0 clojure-1.6.0.zip
30 |
--------------------------------------------------------------------------------
/bin/docs:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -e
4 |
5 | cd `dirname $0`/..
6 |
7 | node_modules/.bin/yuidoc src --themedir doctheme -o docs
8 |
--------------------------------------------------------------------------------
/bin/make_deps_js:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | java -cp deps/closure-compiler/compiler.jar:deps/clojure/clojure-1.6.0.jar clojure.main -i bin/closure_deps_graph.clj
--------------------------------------------------------------------------------
/bin/prelude:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 |
5 | prefix=`cat VERSION_PREFIX`
6 | suffix=`build/revision`
7 | version=$prefix.$suffix
8 |
9 | sed "s/\$VERSION/$version/g" resources/prelude.txt
10 |
--------------------------------------------------------------------------------
/bin/test:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -e
4 |
5 | cd `dirname $0`/..
6 |
7 | bin/make_deps_js
8 | node_modules/.bin/grunt nodeunit
9 |
--------------------------------------------------------------------------------
/build/package_local:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 |
5 | echo "Cleaning..."
6 | rm -rf ./target
7 |
8 | echo "Calculating version..."
9 | prefix=`cat VERSION_PREFIX`
10 | suffix=`build/revision`
11 | version=$prefix.$suffix
12 | echo $version
13 |
14 | echo "Packaging..."
15 | bin/build_jar
16 | mvn versions:set -DnewVersion=${version}
17 | mvn install:install-file -Dfile=./target/transducers-js.jar -DpomFile=pom.xml
18 | mvn versions:revert
19 |
20 | echo "Package done!"
--------------------------------------------------------------------------------
/build/release:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 |
5 | echo "Cleaning..."
6 | rm -rf ./target
7 |
8 | echo "Calculating version..."
9 | prefix=`cat VERSION_PREFIX`
10 | suffix=`build/revision`
11 | version=$prefix.$suffix
12 | echo $version
13 |
14 | target_name=transducers-js-${version}
15 |
16 | echo "Releasing..."
17 | mvn versions:set -DnewVersion=${version}
18 | mvn clean deploy
19 | mvn versions:revert
20 |
21 | echo "Tagging..."
22 | git tag -a v${version} -m "Release ${version}"
23 | git push origin v${version}
24 |
25 | echo "Building browser .js to cdn"
26 | bin/build_release_browser
27 | bin/build_release_browser_amd
28 | bin/build_dev_browser
29 | bin/build_dev_browser_amd
30 |
31 | echo "Pushing browser .js to cdn in s3"
32 | aws s3 --profile transit-upload sync ./target s3://cdn.cognitect.com/transducers --exclude "*" --include "transducers-${version}*.js" --content-type text/plain
33 |
34 | echo "Updating README.md versions"
35 | sed -i '' "s/[[:digit:]]\{1,2\}\.[[:digit:]]\{1,2\}\.[[:digit:]]\{2,4\}/${version}/g" README.md
36 | git commit -v -m "Update README.md with ${version}" README.md
37 | git push
38 |
39 | # echo "Building new api docs"
40 | # bin/docs
41 |
42 | echo -e "Updating bower version\n"
43 | rm -rf bower-transducers-js
44 | git clone --quiet git@github.com:cognitect-labs/bower-transducers-js.git bower-transducers-js > /dev/null
45 | cd bower-transducers-js
46 | cp ../target/transducers-${version}.js ./transducers.js
47 | cp ../target/transducers-${version}-min.js ./transducers-min.js
48 | cp ../target/transducers-${version}-amd.js ./transducers-amd.js
49 | cp ../target/transducers-${version}-amd-min.js ./transducers-amd-min.js
50 | git add -f transducers.js
51 | git add -f transducers-min.js
52 | git add -f transducers-amd.js
53 | git add -f transducers-amd-min.js
54 | sed -e "s/\"version\": \"[[:digit:]]\{1,2\}\.[[:digit:]]\{1,2\}\.[[:digit:]]\{2,4\}/\"version\": \"${version}/g" package.json > package.json.tmp
55 | rm package.json
56 | mv package.json.tmp package.json
57 | git add -f package.json
58 | sed -e "s/\"version\": \"[[:digit:]]\{1,2\}\.[[:digit:]]\{1,2\}\.[[:digit:]]\{2,4\}/\"version\": \"${version}/g" bower.json > bower.json.tmp
59 | rm bower.json
60 | mv bower.json.tmp bower.json
61 | git add -f bower.json
62 | git commit -m "${version}"
63 | git push -fq > /dev/null
64 | git tag ${version}
65 | git push --tags > /dev/null
66 | cd ..
67 | rm -rf bower-transducers-js
68 |
69 | echo "Updating npm version\n"
70 | bin/build_dev_node
71 | rm -rf npm-transducers-js
72 | git clone --quiet git@github.com:cognitect-labs/npm-transducers-js.git npm-transducers-js > /dev/null
73 | cd npm-transducers-js
74 | cp ../target/transducers.js ./transducers.js
75 | cp -R ../src/* ./src/
76 | git add -f transducers.js
77 | sed -e "s/\"version\": \"[[:digit:]]\{1,2\}\.[[:digit:]]\{1,2\}\.[[:digit:]]\{2,4\}/\"version\": \"${version}/g" package.json > package.json.tmp
78 | rm package.json
79 | mv package.json.tmp package.json
80 | git add -f package.json
81 | git commit -m "${version}"
82 | git push -fq > /dev/null
83 | git tag ${version}
84 | git push --tags > /dev/null
85 | echo "Releasing npm package\n"
86 | # Need help on this command!
87 | npm publish
88 | cd ..
89 | rm -rf npm-transducers-js
90 |
91 | echo "Release done!"
92 |
--------------------------------------------------------------------------------
/build/revision:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Returns the revision number used for deployment.
4 |
5 | set -e
6 |
7 | REVISION=`git --no-replace-objects describe --tags --match v0.0`
8 |
9 | # Extract the version number from the string. Do this in two steps so
10 | # it is a little easier to understand.
11 | REVISION=${REVISION:5} # drop the first 5 characters
12 | REVISION=${REVISION:0:${#REVISION}-9} # drop the last 9 characters
13 |
14 | echo $REVISION
15 |
--------------------------------------------------------------------------------
/doctheme/assets/css/cognitect.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cognitect-labs/transducers-js/f21cb186b6163697fe3c8c6d98125c6f66cb7632/doctheme/assets/css/cognitect.jpg
--------------------------------------------------------------------------------
/doctheme/assets/css/external-small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cognitect-labs/transducers-js/f21cb186b6163697fe3c8c6d98125c6f66cb7632/doctheme/assets/css/external-small.png
--------------------------------------------------------------------------------
/doctheme/assets/css/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cognitect-labs/transducers-js/f21cb186b6163697fe3c8c6d98125c6f66cb7632/doctheme/assets/css/logo.png
--------------------------------------------------------------------------------
/doctheme/assets/css/main.css:
--------------------------------------------------------------------------------
1 | /*
2 | Font sizes for all selectors other than the body are given in percentages,
3 | with 100% equal to 13px. To calculate a font size percentage, multiply the
4 | desired size in pixels by 7.6923076923.
5 |
6 | Here's a quick lookup table:
7 |
8 | 10px - 76.923%
9 | 11px - 84.615%
10 | 12px - 92.308%
11 | 13px - 100%
12 | 14px - 107.692%
13 | 15px - 115.385%
14 | 16px - 123.077%
15 | 17px - 130.769%
16 | 18px - 138.462%
17 | 19px - 146.154%
18 | 20px - 153.846%
19 | */
20 |
21 | html {
22 | background: #fff;
23 | color: #333;
24 | overflow-y: scroll;
25 | }
26 |
27 | body {
28 | font: 13px/1.4 'Lucida Grande', 'Lucida Sans Unicode', 'DejaVu Sans', 'Bitstream Vera Sans', 'Helvetica', 'Arial', sans-serif;
29 | margin: 0;
30 | padding: 0;
31 | }
32 |
33 | /* -- Links ----------------------------------------------------------------- */
34 | a {
35 | color: #356de4;
36 | text-decoration: none;
37 | }
38 |
39 | a:hover { text-decoration: underline; }
40 |
41 | /* "Jump to Table of Contents" link is shown to assistive tools, but hidden from
42 | sight until it's focused. */
43 | .jump {
44 | position: absolute;
45 | padding: 3px 6px;
46 | left: -99999px;
47 | top: 0;
48 | }
49 |
50 | .jump:focus { left: 40%; }
51 |
52 | /* -- Paragraphs ------------------------------------------------------------ */
53 | p { margin: 1.3em 0; }
54 | dd p, td p { margin-bottom: 0; }
55 | dd p:first-child, td p:first-child { margin-top: 0; }
56 |
57 | /* -- Headings -------------------------------------------------------------- */
58 | h1, h2, h3, h4, h5, h6 {
59 | color: #D98527;/*was #f80*/
60 | font-family: 'Trebuchet MS', sans-serif;
61 | font-weight: bold;
62 | line-height: 1.1;
63 | margin: 1.1em 0 0.5em;
64 | }
65 |
66 | h1 {
67 | font-size: 184.6%;
68 | color: #30418C;
69 | margin: 0.75em 0 0.5em;
70 | }
71 |
72 | h2 {
73 | font-size: 153.846%;
74 | color: #E48A2B;
75 | }
76 |
77 | h3 { font-size: 138.462%; }
78 |
79 | h4 {
80 | border-bottom: 1px solid #DBDFEA;
81 | color: #E48A2B;
82 | font-size: 115.385%;
83 | font-weight: normal;
84 | padding-bottom: 2px;
85 | }
86 |
87 | h5, h6 { font-size: 107.692%; }
88 |
89 | /* -- Code and examples ----------------------------------------------------- */
90 | code, kbd, pre, samp {
91 | font-family: Menlo, Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;
92 | font-size: 92.308%;
93 | line-height: 1.35;
94 | }
95 |
96 | p code, p kbd, p samp, li code {
97 | background: #FCFBFA;
98 | border: 1px solid #EFEEED;
99 | padding: 0 3px;
100 | }
101 |
102 | a code, a kbd, a samp,
103 | pre code, pre kbd, pre samp,
104 | table code, table kbd, table samp,
105 | .intro code, .intro kbd, .intro samp,
106 | .toc code, .toc kbd, .toc samp {
107 | background: none;
108 | border: none;
109 | padding: 0;
110 | }
111 |
112 | pre.code, pre.terminal, pre.cmd {
113 | overflow-x: auto;
114 | *overflow-x: scroll;
115 | padding: 0.3em 0.6em;
116 | }
117 |
118 | pre.code {
119 | background: #FCFBFA;
120 | border: 1px solid #EFEEED;
121 | border-left-width: 5px;
122 | }
123 |
124 | pre.terminal, pre.cmd {
125 | background: #F0EFFC;
126 | border: 1px solid #D0CBFB;
127 | border-left: 5px solid #D0CBFB;
128 | }
129 |
130 | /* Don't reduce the font size of Caveats: please properly escape less-thans. x<y
46 | instead of x<y, and use " instead of
47 | " for string delimiters.// elements inside
66 |
67 |
131 | blocks. */
132 | pre code, pre kbd, pre samp { font-size: 100%; }
133 |
134 | /* Used to denote text that shouldn't be selectable, such as line numbers or
135 | shell prompts. Guess which browser this doesn't work in. */
136 | .noselect {
137 | -moz-user-select: -moz-none;
138 | -khtml-user-select: none;
139 | -webkit-user-select: none;
140 | -o-user-select: none;
141 | user-select: none;
142 | }
143 |
144 | /* -- Lists ----------------------------------------------------------------- */
145 | dd { margin: 0.2em 0 0.7em 1em; }
146 | dl { margin: 1em 0; }
147 | dt { font-weight: bold; }
148 |
149 | /* -- Tables ---------------------------------------------------------------- */
150 | caption, th { text-align: left; }
151 |
152 | table {
153 | border-collapse: collapse;
154 | width: 100%;
155 | }
156 |
157 | td, th {
158 | border: 1px solid #fff;
159 | padding: 5px 12px;
160 | vertical-align: top;
161 | }
162 |
163 | td { background: #E6E9F5; }
164 | td dl { margin: 0; }
165 | td dl dl { margin: 1em 0; }
166 | td pre:first-child { margin-top: 0; }
167 |
168 | th {
169 | background: #D2D7E6;/*#97A0BF*/
170 | border-bottom: none;
171 | border-top: none;
172 | color: #000;/*#FFF1D5*/
173 | font-family: 'Trebuchet MS', sans-serif;
174 | font-weight: bold;
175 | line-height: 1.3;
176 | white-space: nowrap;
177 | }
178 |
179 |
180 | /* -- Layout and Content ---------------------------------------------------- */
181 | #doc {
182 | margin: auto;
183 | min-width: 1024px;
184 | }
185 |
186 | #main { width: 754px; }
187 | #sidebar { width: 270px; margin: 0 15px; }
188 |
189 | .content { padding: 0 20px 0 25px; }
190 |
191 | /* -- Sidebar --------------------------------------------------------------- */
192 | .sidebox {
193 | background: #F9F9FC;/*E6E9F5*/
194 | border: 1px solid #D4D8EB;
195 |
196 | -moz-border-radius: 4px;
197 | -webkit-border-radius: 4px;
198 | border-radius: 4px;
199 | -moz-box-shadow: 0 0 6px rgba(0, 0, 0, 0.15);
200 | -webkit-box-shadow: 0 0 6px rgba(0, 0, 0, 0.15);
201 | box-shadow: 0 0 6px rgba(0, 0, 0, 0.15);
202 | font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', 'Helvetica', 'Arial', sans-serif;
203 | margin: 0 0 15px 0;
204 | padding-bottom: 1px;
205 | }
206 |
207 | .sidebox h2 {
208 | background: #E5E6F1;
209 | -moz-border-radius: 4px 4px 0 0;
210 | -webkit-border-radius: 4px 4px 0 0;
211 | border-radius: 4px 4px 0 0;
212 | color: #5E6BA4;
213 | font-weight: bold;
214 | font-size: 107.692%;
215 | margin: 0;
216 | padding: 4px 7px 5px;
217 | }
218 |
219 | .sidebox .bd {
220 | font-size: 84.615%;
221 | padding: 0 5px 0 8px;
222 | }
223 |
224 | .sidebox li { list-style-type: disc; color:#D4D5E3; }
225 |
226 | .sidebox ol, .sidebox ul {
227 | margin-left: 0;
228 | padding-left: 16px;
229 | }
230 |
231 | .sidebox ol ol, .sidebox ol ul,
232 | .sidebox ul ol, .sidebox ul ul {
233 | margin: 0;
234 | padding-left: 16px;
235 | }
236 |
237 | /* -- Table of Contents ----------------------------------------------------- */
238 |
239 | /* The #toc id refers to the single global table of contents, while the .toc
240 | class refers to generic TOC lists that could be used throughout the page. */
241 |
242 | .toc code, .toc kbd, .toc samp { font-size: 100%; }
243 | .toc li { font-weight: bold; }
244 | .toc li li { font-weight: normal; }
245 |
246 | /* -- Intro and Example Boxes ----------------------------------------------- */
247 | .intro, .example { margin-bottom: 2em; }
248 |
249 | .example {
250 | -moz-border-radius: 4px;
251 | -webkit-border-radius: 4px;
252 | border-radius: 4px;
253 | -moz-box-shadow: 0 0 5px #bfbfbf;
254 | -webkit-box-shadow: 0 0 5px #bfbfbf;
255 | box-shadow: 0 0 5px #bfbfbf;
256 | padding: 1em;
257 | }
258 |
259 | .intro {
260 | background: none repeat scroll 0 0 #F0F1F8; border: 1px solid #D4D8EB; padding: 0 1em;
261 | }
262 |
263 | /* -- Other Styles ---------------------------------------------------------- */
264 |
265 | /* These are probably YUI-specific, and should be moved out of Selleck's default
266 | theme. */
267 |
268 | .button {
269 | border: 1px solid #dadada;
270 | -moz-border-radius: 3px;
271 | -webkit-border-radius: 3px;
272 | border-radius: 3px;
273 | color: #444;
274 | display: inline-block;
275 | font-family: Helvetica, Arial, sans-serif;
276 | font-size: 92.308%;
277 | font-weight: bold;
278 | padding: 4px 13px 3px;
279 | -moz-text-shadow: 1px 1px 0 #fff;
280 | -webkit-text-shadow: 1px 1px 0 #fff;
281 | text-shadow: 1px 1px 0 #fff;
282 | white-space: nowrap;
283 |
284 | background: #EFEFEF; /* old browsers */
285 | background: -moz-linear-gradient(top, #f5f5f5 0%, #efefef 50%, #e5e5e5 51%, #dfdfdf 100%); /* firefox */
286 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f5f5f5), color-stop(50%,#efefef), color-stop(51%,#e5e5e5), color-stop(100%,#dfdfdf)); /* webkit */
287 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f5f5f5', endColorstr='#dfdfdf',GradientType=0 ); /* ie */
288 | }
289 |
290 | .button:hover {
291 | border-color: #466899;
292 | color: #fff;
293 | text-decoration: none;
294 | -moz-text-shadow: 1px 1px 0 #222;
295 | -webkit-text-shadow: 1px 1px 0 #222;
296 | text-shadow: 1px 1px 0 #222;
297 |
298 | background: #6396D8; /* old browsers */
299 | background: -moz-linear-gradient(top, #6396D8 0%, #5A83BC 50%, #547AB7 51%, #466899 100%); /* firefox */
300 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6396D8), color-stop(50%,#5A83BC), color-stop(51%,#547AB7), color-stop(100%,#466899)); /* webkit */
301 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6396D8', endColorstr='#466899',GradientType=0 ); /* ie */
302 | }
303 |
304 | .newwindow { text-align: center; }
305 |
306 | .header .version em {
307 | display: block;
308 | text-align: right;
309 | }
310 |
311 | .yui3-skin-sam #classdocs .yui3-tabview-panel {
312 | background-color: transparent;
313 | }
314 |
315 | .yui3-skin-sam #classdocs .yui3-tabview-panel {
316 | border: none;
317 | }
318 |
319 | .yui3-skin-sam .yui3-tabview .yui3-tab,
320 | .yui3-skin-sam .yui3-tabview .yui3-tab-selected,
321 | .yui3-skin-sam .yui3-tabview .yui3-tab-hover {
322 | background: -moz-linear-gradient(center top , #F4F0EC 0%, #D6D2CE 100%) repeat scroll 0 0 transparent;
323 | border-bottom: 1px solid #DEDCD9;
324 | border-right: 1px solid #CDCBC8;
325 | border-left: 1px solid #CDCBC8;
326 | border-top: 1px solid #DADADA;
327 | color: #333333;
328 | text-decoration: none;
329 | }
330 | .yui3-skin-sam .yui3-tabview .yui3-tab-label,
331 | .yui3-skin-sam .yui3-tabview .yui3-tab-selected .yui3-tab-label {
332 | border: none;
333 | background: none;
334 | font-size: 100%;
335 | color: #000;
336 | }
337 |
338 | .yui3-skin-sam .yui3-tabview .yui3-tab-selected,
339 | .yui3-skin-sam .yui3-tabview .yui3-tab-hover {
340 | background: none;
341 | background-color: #fff;
342 | border-bottom-color: #FFFFFF;
343 | border-top: 2px solid #8193C9;
344 | font-weight: bold;
345 | color: #000;
346 |
347 | }
348 |
349 | .yui3-skin-sam .yui3-tabview-list {
350 | border-color: #DFDFDF;
351 | border-width: 0 0 1px;
352 | }
353 |
354 |
355 | a.external {
356 | background-image: url(external-small.png);
357 | background-repeat: no-repeat;
358 | background-position: 0 0;
359 | padding-left: 16px;
360 | }
361 |
362 | #classdocs .item {
363 | border-bottom: 1px solid #466899;
364 | margin: 1em 0;
365 | padding: 1.5em;
366 | }
367 |
368 | #classdocs .item .params p,
369 | #classdocs .item .returns p,{
370 | display: inline;
371 | }
372 |
373 | #classdocs .item em code, #classdocs .item em.comment {
374 | color: green;
375 | }
376 |
377 | #classdocs .item em.comment a {
378 | color: green;
379 | text-decoration: underline;
380 | }
381 |
382 | #classdocs .foundat {
383 | font-size: 11px;
384 | font-style: normal;
385 | }
386 |
387 | .attrs .emits {
388 | margin-left: 2em;
389 | padding: .5em;
390 | border-left: 1px dashed #ccc;
391 | }
392 |
393 | abbr {
394 | border-bottom: 1px dashed #ccc;
395 | font-size: 80%;
396 | cursor: help;
397 | }
398 |
399 | .prettyprint li.L0,
400 | .prettyprint li.L1,
401 | .prettyprint li.L2,
402 | .prettyprint li.L3,
403 | .prettyprint li.L5,
404 | .prettyprint li.L6,
405 | .prettyprint li.L7,
406 | .prettyprint li.L8 {
407 | list-style: decimal;
408 | }
409 |
410 | ul li p {
411 | margin-top: 0;
412 | }
413 |
414 | .method .name {
415 | font-size: 110%;
416 | }
417 |
418 | #hd {
419 | background: -moz-linear-gradient(center top , #DCDBD9 0%, #F6F5F3 100%) repeat scroll 0 0 transparent;
420 | border-bottom: 1px solid #DFDFDF;
421 | padding: 0 15px 1px 20px;
422 | margin-bottom: 15px;
423 | }
424 |
425 | #hd img {
426 | margin-right: 10px;
427 | vertical-align: middle;
428 | }
429 |
430 |
--------------------------------------------------------------------------------
/doctheme/assets/js/tabs.js:
--------------------------------------------------------------------------------
1 | YUI({
2 | insertBefore: 'site_styles'
3 | }).use('tabview', function(Y) {
4 | var classdocs = Y.one('#classdocs'),
5 | tabviewIndexTable = {};
6 | if (classdocs) {
7 | if (classdocs.all('li').size()) {
8 | var tabview = new Y.TabView({ srcNode: classdocs });
9 | tabview.render();
10 | classdocs.all('li a').each(function (item, index) {
11 | var hash = item.get(['hash']);
12 | type = hash.substring(1);
13 | if (!tabviewIndexTable[type]) {
14 | tabviewIndexTable[type] = index;
15 | }
16 | })
17 | Y.all('.sidebox.on-page').each(function (item, index) {
18 | var children = item.all('li a');
19 | children.each(function (cItem, cIndex) {
20 | return function () {
21 | var handleClick = function (e) {
22 | var node = Y.one(this),
23 | hash = node.get(['hash']),
24 | hashValue = hash.substring(1).split('_'),
25 | type = hashValue.shift(),
26 | ogKey = hashValue.join('_'); // in case the hash had other underscores
27 | if (tabviewIndexTable[type] > -1 && tabviewIndexTable[type] !== currentTab) {
28 | currentTab = tabviewIndexTable[type];
29 | tabview.selectChild(tabviewIndexTable[type]);
30 | }
31 | }
32 | Y.on('click', handleClick, cItem)
33 | }()
34 | })
35 | });
36 | }
37 | }
38 | });
39 |
--------------------------------------------------------------------------------
/doctheme/assets/js/yui-prettify.js:
--------------------------------------------------------------------------------
1 | YUI().use('node', function(Y) {
2 | var code = Y.all('.prettyprint.linenums');
3 | if (code.size()) {
4 | code.each(function(c) {
5 | var lis = c.all('ol li'),
6 | l = 1;
7 | lis.each(function(n) {
8 | n.prepend('');
9 | l++;
10 | });
11 | });
12 | var h = location.hash;
13 | location.hash = '';
14 | h = h.replace('LINE_', 'LINENUM_');
15 | location.hash = h;
16 | }
17 | });
18 |
--------------------------------------------------------------------------------
/doctheme/assets/vendor/prettify/CHANGES.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
Known Issues
10 |
11 |
22 |
23 | <code>
elements with newlines in the text
15 | which use CSS to specify white-space:pre
will have the newlines
16 | improperly stripped if the element is not attached to the document at the time
17 | the stripping is done. Also, on IE 6, all newlines will be stripped from
18 | <code>
elements because of the way IE6 produces
19 | innerHTML
. Workaround: use <pre>
for code with
20 | newlines.
21 | Change Log
24 | 29 March 2007
25 |
26 |
56 | prettyPrintOne
was not halting. This was not
33 | reachable through the normal entry point.
34 |
45 |
49 | is no longer applicable.
50 | 4 Jul 2008
57 |
58 |
63 | lang-<language-file-extension>
'''string'''
61 | /
in regex [charsets] should not end regex
62 | 5 Jul 2008
64 |
65 |
nocode
spans to allow embedding of line
71 | numbers and code annotations which should not be styled or otherwise
72 | affect the tokenization of prettified code.
73 | See the issue 22
74 | testcase.
75 | <code>
blocks with embedded newlines.
104 |  
instead of
124 |
so that the output works when embedded in XML.
125 | Bug
126 | 108.29 | <link href="prettify.css" type="text/css" rel="stylesheet" /> 30 | <script type="text/javascript" src="prettify.js"></script>31 |
onload="prettyPrint()"
to your
32 | document's body tag.
33 | Put code snippets in 38 | <pre class="prettyprint">...</pre> 39 | or <code class="prettyprint">...</code> 40 | and it will automatically be pretty printed. 41 | 42 |
The original 45 | | Prettier 46 | |
---|---|
class Voila { 49 | public: 50 | // Voila 51 | static const string VOILA = "Voila"; 52 | 53 | // will not interfere with embedded tags. 54 | }55 | 56 | | class Voila { 57 | public: 58 | // Voila 59 | static const string VOILA = "Voila"; 60 | 61 | // will not interfere with embedded tags. 62 | }63 | |
The comments in prettify.js are authoritative but the lexer 68 | should work on a number of languages including C and friends, 69 | Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, and Makefiles. 70 | It works passably on Ruby, PHP, VB, and Awk and a decent subset of Perl 71 | and Ruby, but, because of commenting conventions, doesn't work on 72 | Smalltalk, or CAML-like languages.
73 | 74 |LISPy languages are supported via an extension:
75 | lang-lisp.js
.
And similarly for
78 | CSS
,
80 | Haskell
,
82 | Lua
,
84 | OCAML, SML, F#
,
86 | Visual Basic
,
88 | SQL
,
90 | Protocol Buffers
, and
92 | WikiText
..
94 |
95 |
If you'd like to add an extension for your favorite language, please 96 | look at src/lang-lisp.js and file an 97 | issue including your language extension, and a testcase.
99 | 100 |You don't need to specify the language since prettyprint()
102 | will guess. You can specify a language by specifying the language extension
103 | along with the prettyprint
class like so:
<pre class="prettyprint lang-html"> 106 | The lang-* class specifies the language file extensions. 107 | File extensions supported by default include 108 | "bsh", "c", "cc", "cpp", "cs", "csh", "cyc", "cv", "htm", "html", 109 | "java", "js", "m", "mxml", "perl", "pl", "pm", "py", "rb", "sh", 110 | "xhtml", "xml", "xsl". 111 | </pre>112 | 113 |
Yes. Prettifying obfuscated code is like putting lipstick on a pig 115 | — i.e. outside the scope of this tool.
116 | 117 |It's been tested with IE 6, Firefox 1.5 & 2, and Safari 2.0.4. 119 | Look at the test page to see if it 120 | works in your browser.
121 | 122 |See the change log
124 | 125 |Apparently wordpress does "smart quoting" which changes close quotes. 127 | This causes end quotes to not match up with open quotes. 128 |
This breaks prettifying as well as copying and pasting of code samples. 129 | See 130 | WordPress's help center for info on how to stop smart quoting of code 132 | snippets.
133 | 134 |You can use the linenums
class to turn on line
136 | numbering. If your code doesn't start at line number 1, you can
137 | add a colon and a line number to the end of that class as in
138 | linenums:52
.
139 |
140 |
For example 141 |
<pre class="prettyprint linenums:4" 142 | >// This is line 4. 143 | foo(); 144 | bar(); 145 | baz(); 146 | boo(); 147 | far(); 148 | faz(); 149 | <pre>150 | produces 151 |
// This is line 4. 153 | foo(); 154 | bar(); 155 | baz(); 156 | boo(); 157 | far(); 158 | faz(); 159 |160 | 161 |
You can use the nocode
class to identify a span of markup
163 | that is not code.
164 |
<pre class=prettyprint> 165 | int x = foo(); /* This is a comment <span class="nocode">This is not code</span> 166 | Continuation of comment */ 167 | int y = bar(); 168 | </pre>169 | produces 170 |
171 | int x = foo(); /* This is a comment This is not code
172 | Continuation of comment */
173 | int y = bar();
174 |
175 |
176 | For a more complete example see the issue22 177 | testcase.
178 | 179 |If you are calling prettyPrint
via an event handler, wrap it in a function.
181 | Instead of doing
182 |
183 | addEventListener('load', prettyPrint, false);
185 |
186 | wrap it in a closure like
187 |
188 | addEventListener('load', function (event) { prettyPrint() }, false);
190 |
191 | so that the browser does not pass an event object to prettyPrint
which
192 | will confuse it.
193 |
194 |