Skip to content

Commit d7323c1

Browse files
committed
feat: init
0 parents  commit d7323c1

File tree

14 files changed

+332
-0
lines changed

14 files changed

+332
-0
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*.cr]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [GeopJr, hugopl]

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Specs & Lint
2+
3+
on: [push, pull_request]
4+
jobs:
5+
ci:
6+
runs-on: ubuntu-latest
7+
container: alpine:edge
8+
steps:
9+
- uses: actions/checkout@v3
10+
- name: Install dependencies
11+
run: apk add webkit2gtk-5.0-dev gobject-introspection-dev crystal shards yaml-dev
12+
- name: Shards install
13+
run: shards install
14+
- name: Generate bindings
15+
run: ./bin/gi-crystal
16+
- name: Spec
17+
run: crystal spec --order random || exit 1
18+
- name: Check formatting
19+
run: crystal tool format --check

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/docs/
2+
/lib/
3+
/bin/
4+
/.shards/
5+
*.dwarf
6+
/shard.lock

CODE_OF_CONDUCT.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our
6+
community a harassment-free experience for everyone, regardless of age, body
7+
size, visible or invisible disability, ethnicity, sex characteristics, gender
8+
identity and expression, level of experience, education, socio-economic status,
9+
nationality, personal appearance, race, caste, color, religion, or sexual identity
10+
and orientation.
11+
12+
We pledge to act and interact in ways that contribute to an open, welcoming,
13+
diverse, inclusive, and healthy community.
14+
15+
## Our Standards
16+
17+
Examples of behavior that contributes to a positive environment for our
18+
community include:
19+
20+
* Demonstrating empathy and kindness toward other people
21+
* Being respectful of differing opinions, viewpoints, and experiences
22+
* Giving and gracefully accepting constructive feedback
23+
* Accepting responsibility and apologizing to those affected by our mistakes,
24+
and learning from the experience
25+
* Focusing on what is best not just for us as individuals, but for the
26+
overall community
27+
28+
Examples of unacceptable behavior include:
29+
30+
* The use of sexualized language or imagery, and sexual attention or
31+
advances of any kind
32+
* Trolling, insulting or derogatory comments, and personal or political attacks
33+
* Public or private harassment
34+
* Publishing others' private information, such as a physical or email
35+
address, without their explicit permission
36+
* Other conduct which could reasonably be considered inappropriate in a
37+
professional setting
38+
39+
## Enforcement Responsibilities
40+
41+
Community leaders are responsible for clarifying and enforcing our standards of
42+
acceptable behavior and will take appropriate and fair corrective action in
43+
response to any behavior that they deem inappropriate, threatening, offensive,
44+
or harmful.
45+
46+
Community leaders have the right and responsibility to remove, edit, or reject
47+
comments, commits, code, wiki edits, issues, and other contributions that are
48+
not aligned to this Code of Conduct, and will communicate reasons for moderation
49+
decisions when appropriate.
50+
51+
## Scope
52+
53+
This Code of Conduct applies within all community spaces, and also applies when
54+
an individual is officially representing the community in public spaces.
55+
Examples of representing our community include using an official e-mail address,
56+
posting via an official social media account, or acting as an appointed
57+
representative at an online or offline event.
58+
59+
## Enforcement
60+
61+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
62+
reported to the community leaders responsible for enforcement at
63+
coc@geopjr.dev.
64+
All complaints will be reviewed and investigated promptly and fairly.
65+
66+
All community leaders are obligated to respect the privacy and security of the
67+
reporter of any incident.
68+
69+
## Enforcement Guidelines
70+
71+
Community leaders will follow these Community Impact Guidelines in determining
72+
the consequences for any action they deem in violation of this Code of Conduct:
73+
74+
### 1. Correction
75+
76+
**Community Impact**: Use of inappropriate language or other behavior deemed
77+
unprofessional or unwelcome in the community.
78+
79+
**Consequence**: A private, written warning from community leaders, providing
80+
clarity around the nature of the violation and an explanation of why the
81+
behavior was inappropriate. A public apology may be requested.
82+
83+
### 2. Warning
84+
85+
**Community Impact**: A violation through a single incident or series
86+
of actions.
87+
88+
**Consequence**: A warning with consequences for continued behavior. No
89+
interaction with the people involved, including unsolicited interaction with
90+
those enforcing the Code of Conduct, for a specified period of time. This
91+
includes avoiding interactions in community spaces as well as external channels
92+
like social media. Violating these terms may lead to a temporary or
93+
permanent ban.
94+
95+
### 3. Temporary Ban
96+
97+
**Community Impact**: A serious violation of community standards, including
98+
sustained inappropriate behavior.
99+
100+
**Consequence**: A temporary ban from any sort of interaction or public
101+
communication with the community for a specified period of time. No public or
102+
private interaction with the people involved, including unsolicited interaction
103+
with those enforcing the Code of Conduct, is allowed during this period.
104+
Violating these terms may lead to a permanent ban.
105+
106+
### 4. Permanent Ban
107+
108+
**Community Impact**: Demonstrating a pattern of violation of community
109+
standards, including sustained inappropriate behavior, harassment of an
110+
individual, or aggression toward or disparagement of classes of individuals.
111+
112+
**Consequence**: A permanent ban from any sort of public interaction within
113+
the community.
114+
115+
## Attribution
116+
117+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118+
version 2.1, available at
119+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120+
121+
Community Impact Guidelines were inspired by
122+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123+
124+
For answers to common questions about this code of conduct, see the FAQ at
125+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
126+
at [https://www.contributor-covenant.org/translations][translations].
127+
128+
[homepage]: https://www.contributor-covenant.org
129+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130+
[Mozilla CoC]: https://github.com/mozilla/diversity
131+
[FAQ]: https://www.contributor-covenant.org/faq
132+
[translations]: https://www.contributor-covenant.org/translations

LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2022, Evangelos "GeopJr" Paterakis
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<p align="center">
2+
<img width="256" alt="JavaScriptCore.cr logo" src="https://raw.githubusercontent.com/GeopJr/JavaScriptCore.cr/main/logo.svg" />
3+
</p>
4+
<h1 align="center">JavaScriptCore.cr</h1>
5+
<h4 align="center">JavaScriptCore bindings for Crystal</h4>
6+
<p align="center">
7+
<br />
8+
<a href="https://github.com/GeopJr/JavaScriptCore.cr/blob/main/CODE_OF_CONDUCT.md"><img src="https://img.shields.io/badge/Contributor%20Covenant-v2.1-ffb500.svg?style=for-the-badge&labelColor=007AFF" alt="Code Of Conduct" /></a>
9+
<a href="https://github.com/GeopJr/JavaScriptCore.cr/blob/main/LICENSE"><img src="https://img.shields.io/badge/LICENSE-BSD--2--Clause-ff9d00.svg?style=for-the-badge&labelColor=007AFF" alt="BSD-2-Clause Licensed" /></a>
10+
<a href="https://github.com/GeopJr/JavaScriptCore.cr/actions"><img src="https://img.shields.io/github/workflow/status/GeopJr/JavaScriptCore.cr/Specs%20&%20Lint/main?labelColor=ff9d00&style=for-the-badge" alt="ci action status" /></a>
11+
</p>
12+
13+
#
14+
15+
## What is this?
16+
17+
JavaScriptCore is a framework that provides a JavaScript engine for WebKit implementations, and provides this type of scripting in other contexts within macOS. JavaScriptCore is originally derived from KDE's JavaScript engine (KJS) library (which is part of the KDE project) and the PCRE regular expression library. Since forking from KJS and PCRE, JavaScriptCore has been improved with many new features and greatly improved performance.
18+
19+
> from: https://en.wikipedia.org/wiki/WebKit#JavaScriptCore
20+
21+
This shard provides bindings for it, allowing you to evaluate JS from Crystal!
22+
23+
Bindings are being generated using [gi-crystal](https://github.com/hugopl/gi-crystal).
24+
25+
#
26+
27+
## Dependencies
28+
29+
You need **`JavaScriptCore 5.0`**. Your distro might provide it as `libjavascriptcoregtk-5_0` or `typelib-1_0-JavaScriptCore-5_0`. If it doesn't then try installing `webkit2gtk` (the latest, -dev or -devel version if available). Doc generation will probably only be availble by installing one of the `webkit2gtk` packages.
30+
31+
#
32+
33+
## Installation
34+
35+
1. Add the dependency to your `shard.yml`:
36+
37+
```yaml
38+
dependencies:
39+
javascriptcore:
40+
github: GeopJr/JavaScriptCore.cr
41+
```
42+
43+
2. Run `shards install`
44+
3. Run `./bin/gi-crystal` to generate the bindings
45+
46+
#
47+
48+
## Usage
49+
50+
There's a lot you can do with the bindings, but here's a simple evaluation:
51+
52+
```crystal
53+
require "javascriptcore"
54+
55+
context = JavaScriptCore::Context.new
56+
script = "['Java', 'Script', 'Core'].join('')"
57+
result = context.evaluate(script, -1)
58+
59+
p result.to_s #=> "JavaScriptCore"
60+
```
61+
62+
There might be more examples on [`./spec`](./spec/).
63+
64+
#
65+
66+
## Contributing
67+
68+
1. Read the [Code of Conduct](https://github.com/GeopJr/JavaScriptCore.cr/blob/main/CODE_OF_CONDUCT.md)
69+
2. Fork it ( https://github.com/GeopJr/JavaScriptCore.cr/fork )
70+
3. Create your feature branch (git checkout -b my-new-feature)
71+
4. Commit your changes (git commit -am 'Add some feature')
72+
5. Push to the branch (git push origin my-new-feature)
73+
6. Create a new Pull Request

logo.svg

Lines changed: 1 addition & 0 deletions
Loading

shard.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: javascriptcore
2+
version: 1.0.0
3+
4+
authors:
5+
- Evangelos Paterakis <evan@geopjr.dev>
6+
7+
dependencies:
8+
gi-crystal:
9+
github: hugopl/gi-crystal
10+
11+
crystal: 1.5.0
12+
13+
license: BSD-2-Clause

spec/javascriptcore_spec.cr

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require "./spec_helper"
2+
3+
describe JavaScriptCore do
4+
it "should compile JS correctly" do
5+
n1 = Random.rand(9999)
6+
n2 = Random.rand(9999)
7+
should_equal = n1 + n2
8+
9+
script = <<-JS
10+
function add(n1, n2) {
11+
return n1 + n2
12+
}
13+
14+
add(#{n1}, #{n2})
15+
JS
16+
context = JavaScriptCore::Context.new
17+
result = context.evaluate(script, -1)
18+
19+
result.to_i.should eq(should_equal)
20+
end
21+
end

0 commit comments

Comments
 (0)