Skip to content

Commit e996f27

Browse files
committed
Add Closure JS implementation
1 parent 13c805e commit e996f27

File tree

9 files changed

+1186
-69
lines changed

9 files changed

+1186
-69
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Ignore backup and swap files.
2+
*~
3+
.*.swp
4+
# Ignore all bazel-* links.
5+
/bazel-*
6+
# Ignore outputs generated during Bazel bootstrapping.
7+
/output/

CONTRIBUTING.md

Lines changed: 72 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,72 @@
1-
Want to contribute? Great! First, read this page (including the small print at the end).
2-
3-
## Before you contribute
4-
Before we can use your code, you must sign the
5-
[Google Individual Contributor License Agreement](https://developers.google.com/open-source/cla/individual?csw=1)
6-
(CLA), which you can do online.
7-
8-
The CLA is necessary mainly because you own the
9-
copyright to your changes, even after your contribution becomes part of our
10-
codebase, so we need your permission to use and distribute your code. We also
11-
need to be sure of various other things—for instance that you'll tell us if you
12-
know that your code infringes on other people's patents.
13-
14-
You don't have to sign
15-
the CLA until after you've submitted your code for review and a member has
16-
approved it, but you must do it before we can put your code into our codebase.
17-
Before you start working on a larger contribution, you should get in touch with
18-
us first through the issue tracker with your idea so that we can help out and
19-
possibly guide you. Coordinating up front makes it much easier to avoid
20-
frustration later on.
21-
22-
## Writing a new implementation
23-
24-
Before you start writing a new implementation, look at some of the existing ones. If you copy the
25-
code structure from them, you are more likely to have fewer bugs and an easier review cycle.
26-
27-
If you create new algorithms to encode or decode, then your reviewer will have to spend more time
28-
trying to understand your code in a language they may not be familiar with, and the review cycle
29-
will take longer.
30-
31-
The reason we say this is because once code is accepted into our repository, we have the responsibility
32-
to maintain and look after it. You are not writing the code for you, but for the OLC project team.
33-
34-
## Code reviews
35-
All submissions, including submissions by project members, require review. We
36-
use Github pull requests for this purpose.
37-
38-
## Code Style
39-
Programs written in Go must be formatted with `gofmt`. For other languages, we use the
40-
[Google style guides](https://google.github.io/styleguide/) for code styling. Specifically, this means:
41-
42-
* Line length: 80 chars (Java 100)
43-
* No extra whitespace around arguments `(code)` not `( code )`
44-
* K & R style braces:
45-
```java
46-
if (condition()) {
47-
something();
48-
} else {
49-
somethingElse();
50-
}
51-
```
52-
53-
## The small print
54-
Contributions made by corporations are covered by a different agreement than
55-
the one above, the Software Grant and Corporate Contributor License Agreement.
1+
# Contributing to Open Location Code
2+
3+
The Open Location Code project strongly encourages technical contributions.
4+
5+
We hope you'll become an ongoing participant in our open source community but we also welcome one-off contributions for the issues you're particularly passionate about.
6+
7+
- [Filing issues](#filing-issues)
8+
* [Bugs](#bugs)
9+
* [Suggestions](#suggestions)
10+
- [Contributing code](#contributing-code)
11+
- [Contributing a new implementation](#contributing-a-new-implementation)
12+
- [Contributor License Agreement](#contributor-license-agreement)
13+
- [Ongoing participation](#ongoing-participation)
14+
* [Discussion channels](#discussion-channels)
15+
16+
## Filing issues
17+
18+
### Bugs
19+
20+
If you find a bug in an Open Location Code library, please [file an issue](https://github.com/google/open-location-code/issues/new). Members of the community are regularly monitoring issues and will try to fix open bugs quickly.
21+
22+
The best bug reports provide a detailed description of the issue, step-by-step instructions for predictably reproducing the issue, and possibly even a working example that demonstrates the issue.
23+
24+
Please note that questions about how to use Open Location Code or other general questions should be asked on the [Open Location Code Google Group](https://groups.google.com/forum/#!forum/open-location-code)<!-- Uncomment if this becomes sensible --><!-- or [Stack Overflow under the Open Location Code tag](http://stackoverflow.com/questions/tagged/open-location-code) -->
25+
instead of filing an issue here.
26+
27+
### Suggestions
28+
29+
The Open Location Code project is meant to evolve with feedback. The project and its users appreciate your thoughts on ways to improve the design or features or creative ways to use the codes.
30+
31+
To make a suggestion [file an issue](https://github.com/google/open-location-code/issues/new).
32+
33+
If you are intending to implement, please see the [Contributing code](#contributing-code) section below for next steps.
34+
35+
If you are adding Open Location Codes to your project, please contact the [Open Location Code Google Group](https://groups.google.com/forum/#!forum/open-location-code) so we can suggest how you can make the most of the codes.
36+
37+
## Contributing code
38+
39+
The Open Location Code project accepts and greatly appreciates code contributions!
40+
41+
If you are contributing code to the project consider [joining the Open Location Code project on GitHub](https://goo.gl/forms/T65peVtfQfEoDWeD3).
42+
43+
A few things to note:
44+
45+
* The Open Location Code project follows the [fork & pull](https://help.github.com/articles/using-pull-requests/#fork--pull) model for accepting contributions.
46+
* We follow [Google's JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html). More generally make sure to follow the same comment and coding style as the rest of the project.
47+
* Include [tests](TESTING.md) when contributing code. There are tests that you can use as examples.
48+
49+
## Contributing a new implementation
50+
51+
Follow this process for contributing a new implementation:
52+
53+
* Look at the existing implementations, to get an idea of the usage and how much work is involved.
54+
* If you copy the code structure and algorithms from an existing implementation, you'll have a much shorter review cycle.
55+
* [Create a new GitHub issue](https://github.com/google/open-location-code/issues/new) to start discussion of the new feature.
56+
* Follow the guidelines for [Contributing code](#contributing-code) described above.
57+
58+
## Contributor License Agreement
59+
60+
The Open Location Code project hosted at GitHub requires all contributors to sign a Contributor License Agreement ([individual](https://developers.google.com/open-source/cla/individual) or [corporation](https://developers.google.com/open-source/cla/corporate)) in order to protect contributors, users and Google in issues of intellectual property.
61+
62+
When you create a Pull Request a check will be run to ensure that you have signed the CLA. Make sure that you sign the CLA with the same email address you associate with your commits (likely via the `user.email` Git config as described on GitHub's [Set up Git](https://help.github.com/articles/set-up-git/) page).
63+
64+
## Ongoing participation
65+
66+
We actively encourage ongoing participation by community members.
67+
68+
### Discussion channels
69+
70+
Technical issues, designs, etc. are discussed on [GitHub issues](https://github.com/google/open-location-code/issues) and [pull requests](https://github.com/google/open-location-code/pulls),
71+
or the [Open Location Code Google Group](https://groups.google.com/forum/#!forum/open-location-code)<!-- Uncomment if this becomes sensible --><!-- and [Stack Overflow under the Open Location Code tag](http://stackoverflow.com/questions/tagged/open-location-code) -->.
72+

TESTING.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
1-
# Automated Integration Testing
1+
# Testing
2+
The preferred mechanism for testing is using the [Bazel](https://bazel.build/)
3+
build system. This uses files called `BUILD` ([example](https://github.com/google/open-location-code/blob/master/BUILD)
4+
to provide rules to build code and run tests.
5+
6+
Create a `BUILD` file in your code directory with a [test rule](https://bazel.build/versions/master/docs/test-encyclopedia.html).
7+
You can then test your code by running:
8+
9+
```sh
10+
blaze test <dir>:<rule>
11+
```
12+
13+
All tests can be run with:
14+
15+
```sh
16+
blaze test ...:all
17+
```
18+
19+
## Automated Integration Testing
220
Changes are sent to [Travis CI](https://travis-ci.org)
321
for integration testing after pushes, and you can see the current test status
422
[here](https://travis-ci.org/google/open-location-code).
523

624
The testing configuration is controlled by two files:
725
[`travis.yml`](.travis.yml) and [`run_tests.sh`](run_tests.sh).
826

9-
## [.travis.yml](.travis.yml)
27+
### [.travis.yml](.travis.yml)
1028
This file defines the prerequisites required for testing, and the list of
1129
directories to be tested. (The directories listed are tested in parallel.)
1230

1331
The same script ([run_tests.sh](run_tests.sh)) is executed for all directories.
1432

15-
## [run_tests.sh](run_tests.sh)
33+
### [run_tests.sh](run_tests.sh)
1634
This file is run once for _each_ directory defined in
1735
`.travis.yml`. The directory name being tested is passed in the environment
1836
variable `TEST_DIR`.)
@@ -23,7 +41,7 @@ commands to test the relevant implementation. The commands that do the testing
2341
return zero, even if they output error messages, will be considered by the
2442
testing framework as a success_.
2543

26-
## Adding Your Tests
44+
### Adding Your Tests
2745
Add your directory to the [`.travis.yml`](.travis.yml) file:
2846
```
2947
# Define the list of directories to execute tests in.
@@ -49,7 +67,7 @@ the script will return the same status as the tests. If this status is zero,
4967
the test will be marked successful. If not, the test will be marked as a
5068
failure.
5169

52-
## Testing Multiple Languages
70+
### Testing Multiple Languages
5371
[Travis CI](https://travis-ci.org) assumes that each github project has only
5472
a single language. That language is specified in the [.travis.yml](.travis.yml)
5573
file (`language: node_js`).

WORKSPACE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
workspace(name = "openlocationcode")
2+
3+
# Include the Google Test framework for C++ testing.
4+
# See https://github.com/google/googletest
5+
new_http_archive(
6+
name = "gtest",
7+
url = "https://github.com/google/googletest/archive/release-1.8.0.zip",
8+
sha256 = "f3ed3b58511efd272eb074a3a6d6fb79d7c2e6a0e374323d1e6bcbcc1ef141bf",
9+
build_file = "cpp/gtest.BUILD",
10+
strip_prefix = "googletest-release-1.8.0/googletest",
11+
)
12+
13+
# Include the Bazel Closure rules for javascript testing..
14+
# See https://github.com/bazelbuild/rules_closure
15+
http_archive(
16+
name = "io_bazel_rules_closure",
17+
url = "http://mirror.bazel.build/github.com/bazelbuild/rules_closure/archive/0.4.1.tar.gz",
18+
sha256 = "ba5e2e10cdc4027702f96e9bdc536c6595decafa94847d08ae28c6cb48225124",
19+
strip_prefix = "rules_closure-0.4.1",
20+
)
21+
22+
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
23+
24+
closure_repositories()

cpp/WORKSPACE

Lines changed: 0 additions & 9 deletions
This file was deleted.

js/closure/BUILD

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_binary", "closure_js_library", "closure_js_test")
3+
#load("//closure/compiler:closure_js_library.bzl", "closure_js_library")
4+
5+
6+
7+
closure_js_library(
8+
name = "openlocationcode_lib",
9+
srcs = ["openlocationcode.js"],
10+
deps = [
11+
"@io_bazel_rules_closure//closure/library",
12+
],
13+
)
14+
15+
closure_js_test(
16+
name = "openlocationcode_test",
17+
timeout = "short",
18+
srcs = ["openlocationcode_test.js"],
19+
entry_points = ["goog:openlocationcode_test"],
20+
deps = [
21+
":openlocationcode_lib",
22+
"@io_bazel_rules_closure//closure/library:testing",
23+
],
24+
)

js/closure/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Closure Library
2+
3+
This is a version of the Open Location Code javascript library for use with the
4+
[Google Closure Compiler](https://github.com/google/closure-compiler).
5+
6+
You can use it in Closure projects like this:
7+
8+
```javascript
9+
const openlocationcode = goog.require('google.openlocationcode');
10+
...
11+
var code = openlocationcode.encode(47.36628,8.52513);
12+
```
13+
14+
## Building and Testing
15+
16+
Included is a `BUILD` file that uses the [Bazel](https://bazel.build/) build system to produce a Javascript library and to run tests. You will need to install Bazel on your system to run the tests.
17+
18+
The tests use the [Closure Rules for Basel](https://github.com/bazelbuild/rules_closure) project although this is retrieved automatically and you don't have to install anything.
19+
20+
The test cases have been copied from the [`test_data`](https://github.com/google/open-location-code/tree/master/test_data) directory due to restrictions on loading data files within the test runner.
21+
22+
Run the tests from the top-level github directory with:
23+
24+
```
25+
$ bazel test js/closure:openlocationcode_test
26+
INFO: Found 1 test target...
27+
Target //js/closure:openlocationcode_test up-to-date:
28+
bazel-bin/js/closure/openlocationcode_test
29+
INFO: Elapsed time: 0.174s, Critical Path: 0.00s
30+
//js/closure:openlocationcode_test PASSED in 1.1s
31+
32+
Executed 0 out of 1 test: 1 test passes.
33+
$
34+
```
35+

0 commit comments

Comments
 (0)