emoruby 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.irbrc +3 -0
- data/.travis.yml +6 -0
- data/README.md +71 -5
- data/config/translations.yml +13 -1
- data/emoruby.gemspec +2 -0
- data/lib/emoruby/converts_emoji_to_ruby.rb +36 -20
- data/lib/emoruby/emoji_script.rb +1 -1
- data/lib/emoruby/version.rb +1 -1
- data/spec/1_hello_world_spec.rb +17 -6
- data/spec/2_module_with_addition_spec.rb +4 -0
- data/spec/3_stabby_proc_spec.rb +9 -0
- data/spec/5_comments_spec.rb +10 -0
- data/spec/fixtures/3_stabby_proc.emoruby +3 -0
- data/spec/fixtures/3_stabby_proc.rb +3 -0
- data/spec/fixtures/4_method_access.emoruby +20 -0
- data/spec/fixtures/4_method_access.rb +20 -0
- data/spec/fixtures/5_comments.emoruby +1 -0
- data/spec/fixtures/5_comments.rb +1 -0
- data/spec/spec_helper.rb +4 -16
- metadata +33 -3
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd782a7a3726759ec5cbd3eec6a12c90a63a5db4
|
4
|
+
data.tar.gz: 69eab3dbe410e976a3537c1fb34e507c18e2201d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68935d847520bcea700230b37f7a33c2879f7465f7119f4670810770e23f4f9f84171fc3249d004b402e3d21ade4a690ea7b51e3ff1a2aafb2b55b3722330287
|
7
|
+
data.tar.gz: 10437fb26dad723be5a0bcecc94392ee2c6c09529f335fcba0c1ddd6976277133b7fe3cb0442e0a079bd7561ee82af211ae6034fcd479378f1163cbac0c65f9b
|
data/.gitignore
CHANGED
data/.irbrc
ADDED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# emoruby
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/searls/emoruby.svg?branch=master)](https://travis-ci.org/searls/emoruby) [![Code Climate](https://codeclimate.com/github/searls/emoruby/badges/gpa.svg)](https://codeclimate.com/github/searls/emoruby) [![Test Coverage](https://codeclimate.com/github/searls/emoruby/badges/coverage.svg)](https://codeclimate.com/github/searls/emoruby)
|
4
|
+
|
3
5
|
A little language that compiles Emoji down to Ruby. It's just Ruby. Really.
|
4
6
|
|
5
7
|
## The Language
|
@@ -8,7 +10,7 @@ If I were a real language designer, I would have put a lot of thought into the s
|
|
8
10
|
|
9
11
|
Anyway, here is an example hello world program:
|
10
12
|
|
11
|
-
```
|
13
|
+
```emoruby
|
12
14
|
📋 ❤️
|
13
15
|
🔜 👋
|
14
16
|
👀 💬😃 🌏💬
|
@@ -30,13 +32,77 @@ end
|
|
30
32
|
Heart.new.wave
|
31
33
|
```
|
32
34
|
|
35
|
+
You can also define things like Procs and comments:
|
36
|
+
|
37
|
+
```emoruby
|
38
|
+
💭 Comment! 👋
|
39
|
+
👉 🔨
|
40
|
+
💬😃💬
|
41
|
+
🔚▪️📞
|
42
|
+
```
|
43
|
+
|
44
|
+
which is equivalent to this Ruby:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
# Comment! 👋
|
48
|
+
-> do
|
49
|
+
"smiley"
|
50
|
+
end.call
|
51
|
+
```
|
52
|
+
|
53
|
+
You can define private and protected methods:
|
54
|
+
|
55
|
+
```emoruby
|
56
|
+
📋 ❤️
|
57
|
+
🔓 🔜 👖
|
58
|
+
👀 💬👛💬
|
59
|
+
🔚
|
60
|
+
|
61
|
+
🔒️ 🔜 👕
|
62
|
+
👀 💬💛💬
|
63
|
+
🔚
|
64
|
+
|
65
|
+
⛔️ 🔜 👋
|
66
|
+
👀 💬😃 🌏💬
|
67
|
+
🔚
|
68
|
+
🔚
|
69
|
+
|
70
|
+
❤️▪️🐣▪️👋
|
71
|
+
```
|
72
|
+
|
73
|
+
which is equivalent to this Ruby:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
class Heart
|
77
|
+
public def jeans
|
78
|
+
puts "purse"
|
79
|
+
end
|
80
|
+
|
81
|
+
protected def shirt
|
82
|
+
puts "yellow_heart"
|
83
|
+
end
|
84
|
+
|
85
|
+
private def wave
|
86
|
+
puts "smiley earth_asia"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
Heart.new.wave
|
91
|
+
```
|
92
|
+
|
93
|
+
Which will result in an exception:
|
94
|
+
|
95
|
+
```
|
96
|
+
NoMethodError: private method `wave' called for #<Heart:0x007f81eb840138>
|
97
|
+
```
|
98
|
+
|
33
99
|
## Using the gem
|
34
100
|
|
35
101
|
### registering the ".emoruby" file extension
|
36
102
|
|
37
103
|
Emoruby uses polyglot to enable `require` to be used on `.emoruby` files just as you do with Ruby source `.rb` files. To register the file extension, simply:
|
38
104
|
|
39
|
-
```
|
105
|
+
```ruby
|
40
106
|
> require 'emoruby'
|
41
107
|
=> true
|
42
108
|
> Emoruby.register
|
@@ -50,7 +116,7 @@ smiley earth_asia
|
|
50
116
|
|
51
117
|
You can run emoruby from the command line by passing an emoruby file as the first argument:
|
52
118
|
|
53
|
-
```
|
119
|
+
```shell
|
54
120
|
$ emoruby spec/fixtures/1_hello_world.emoruby
|
55
121
|
smiley earth_asia
|
56
122
|
```
|
@@ -59,7 +125,7 @@ smiley earth_asia
|
|
59
125
|
|
60
126
|
The API allows both evaluation of emoruby code as well as translation to Ruby.
|
61
127
|
|
62
|
-
```
|
128
|
+
```ruby
|
63
129
|
> source = "💬😃 🌏💬"
|
64
130
|
=> "💬😃 🌏💬"
|
65
131
|
> Emoruby.eval(source)
|
@@ -72,4 +138,4 @@ Emoruby.emoji_to_ruby(source)
|
|
72
138
|
|
73
139
|
The Emoruby team embraces and advocates the adoption of the the emerging iconographic versioning standard ("icover" for short).
|
74
140
|
|
75
|
-
The initial release was 💩 (in honor of @tenderlove's 💩-lang).
|
141
|
+
The initial release was 💩 (in honor of @tenderlove's 💩-lang). After that, ✊ was released. Next up is, of course, 🐷.
|
data/config/translations.yml
CHANGED
@@ -4,6 +4,14 @@
|
|
4
4
|
🔜: def
|
5
5
|
🔚: end
|
6
6
|
🚣: self
|
7
|
+
✋: yield
|
8
|
+
🔓: public
|
9
|
+
🔒: protected
|
10
|
+
⛔️: private
|
11
|
+
👉: "->"
|
12
|
+
🔨: do
|
13
|
+
➿: loop
|
14
|
+
🎡: while
|
7
15
|
|
8
16
|
# symbols
|
9
17
|
💬: "\""
|
@@ -11,9 +19,13 @@
|
|
11
19
|
↪️: "("
|
12
20
|
↩️: ")"
|
13
21
|
➰: ","
|
22
|
+
💭: '#'
|
14
23
|
|
15
24
|
# conveniences
|
16
25
|
👀: puts
|
17
26
|
🐣: new
|
18
27
|
💥: raise
|
19
|
-
➕: +
|
28
|
+
➕: +
|
29
|
+
🚰: tap
|
30
|
+
📞: call
|
31
|
+
⚠️: warn
|
data/emoruby.gemspec
CHANGED
@@ -12,29 +12,44 @@ module Emoruby
|
|
12
12
|
[239,184,143] # evil problematic whitespace where is it from where am i what even
|
13
13
|
]
|
14
14
|
|
15
|
-
def
|
16
|
-
|
15
|
+
def initialize(source)
|
16
|
+
@source = source
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
emoji_name
|
21
|
-
end
|
19
|
+
def call
|
20
|
+
translate_lines(@source.lines).join("")
|
22
21
|
end
|
23
22
|
|
24
23
|
private
|
25
24
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end.compact]
|
25
|
+
def translate_lines(lines)
|
26
|
+
lines.map do |line|
|
27
|
+
chars = clean_chars(scan_and_translate_constants(line).chars)
|
28
|
+
comments = false
|
31
29
|
|
30
|
+
translate_chars(chars) do |char|
|
31
|
+
next if comments
|
32
|
+
emo_char = emoji_name_for(char)
|
33
|
+
comments ||= (emo_char == '#')
|
34
|
+
emo_char
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def scan_and_translate_constants(source)
|
32
40
|
source.gsub(Regexp.new(constant_map.keys.map { |x| Regexp.escape(x) }.join('|')), constant_map)
|
33
41
|
end
|
34
42
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
43
|
+
def constant_map
|
44
|
+
@constant_map ||= Hash[
|
45
|
+
@source.split(/\s+/).each_cons(2).map do |operator, emo_constant|
|
46
|
+
next unless ['class', 'module'].include?(emoji_name_for(operator))
|
47
|
+
[
|
48
|
+
emo_constant,
|
49
|
+
Util::String.classify(emo_constant.chars.map {|c| emoji_name_for(c) }.join)
|
50
|
+
]
|
51
|
+
end.compact
|
52
|
+
]
|
38
53
|
end
|
39
54
|
|
40
55
|
def clean_chars(source)
|
@@ -42,13 +57,14 @@ module Emoruby
|
|
42
57
|
end
|
43
58
|
|
44
59
|
def translate_chars(chars)
|
45
|
-
chars.each_with_index.map do |
|
46
|
-
|
47
|
-
new_char
|
48
|
-
else
|
49
|
-
original_char
|
50
|
-
end
|
60
|
+
chars.each_with_index.map do |char, index|
|
61
|
+
yield(char, index) || char
|
51
62
|
end.join
|
52
63
|
end
|
64
|
+
|
65
|
+
def emoji_name_for(char)
|
66
|
+
return unless emoji = EmojiData.find_by_str(char).first
|
67
|
+
TRANSLATIONS[emoji.to_s] || emoji.short_name
|
68
|
+
end
|
53
69
|
end
|
54
70
|
end
|
data/lib/emoruby/emoji_script.rb
CHANGED
data/lib/emoruby/version.rb
CHANGED
data/spec/1_hello_world_spec.rb
CHANGED
@@ -3,19 +3,30 @@ require 'spec_helper'
|
|
3
3
|
require 'emoruby'
|
4
4
|
|
5
5
|
describe Emoruby do
|
6
|
+
Invariant { Emoruby.emoji_to_ruby(emo_source) == expected_ruby }
|
7
|
+
|
6
8
|
context "a hello world app" do
|
7
9
|
Given(:emo_source) { load_fixture("1_hello_world") }
|
8
10
|
Given(:expected_ruby) { load_fixture("1_hello_world","rb") }
|
9
11
|
|
10
|
-
describe '
|
11
|
-
When(:result) { Emoruby.
|
12
|
-
Then {
|
12
|
+
describe 'evaluating source' do
|
13
|
+
When(:result) { Emoruby.eval(emo_source_with_stripped_puts) }
|
14
|
+
Then { Heart.new.wave == "smiley earth_asia" }
|
13
15
|
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "a hello world app with a private & protected methods" do
|
19
|
+
Given(:emo_source) { load_fixture("4_method_access") }
|
20
|
+
Given(:expected_ruby) { load_fixture("4_method_access", "rb")}
|
14
21
|
|
15
22
|
describe 'evaluating source' do
|
16
|
-
|
17
|
-
|
18
|
-
|
23
|
+
When(:result) { Emoruby.eval(emo_source_with_stripped_puts) }
|
24
|
+
Then { expect(Heart).to be_private_method_defined(:wave) }
|
25
|
+
And { expect(Snowman).to be_public_method_defined(:lollipop) }
|
26
|
+
And { expect(Snowman).to be_protected_method_defined(:floppy_disk) }
|
27
|
+
And { expect(Snowman).to be_private_method_defined(:wave) }
|
19
28
|
end
|
20
29
|
end
|
30
|
+
|
31
|
+
Given(:emo_source_with_stripped_puts) { emo_source.gsub(EmojiData.find_by_short_name("eyes").first.to_s, "") }
|
21
32
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'emoruby'
|
4
|
+
|
5
|
+
describe Emoruby do
|
6
|
+
Given(:emo_source) { load_fixture("5_comments") }
|
7
|
+
Given(:expected_ruby) { load_fixture("5_comments","rb") }
|
8
|
+
When(:result) { Emoruby.emoji_to_ruby(emo_source) }
|
9
|
+
Then { result == expected_ruby }
|
10
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
💭 Comment! 👋
|
@@ -0,0 +1 @@
|
|
1
|
+
# Comment! 👋
|
data/spec/spec_helper.rb
CHANGED
@@ -1,23 +1,11 @@
|
|
1
1
|
require 'rspec/given'
|
2
|
-
require 'support/file_helpers'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
expected.chars.each_with_index.all? do |c, i|
|
7
|
-
actual[i] == c
|
8
|
-
end
|
9
|
-
end
|
3
|
+
require "codeclimate-test-reporter"
|
4
|
+
CodeClimate::TestReporter.start
|
10
5
|
|
11
|
-
|
12
|
-
expected.chars.each_with_index.reject { |c, i| actual[i] == c }.map do |c,i|
|
13
|
-
"expected that character #{i} would be #{c} but was #{actual[i]} (near '#{actual[i-5..i+5]}')"
|
14
|
-
end.join("\n")
|
15
|
-
end
|
16
|
-
end
|
6
|
+
require 'pry'
|
17
7
|
|
8
|
+
require 'support/file_helpers'
|
18
9
|
RSpec.configure do |c|
|
19
10
|
c.include FileHelpers
|
20
11
|
end
|
21
|
-
|
22
|
-
# other junk
|
23
|
-
require 'pry'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emoruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Searls
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: emoji_data
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: codeclimate-test-reporter
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: A little emoji language that compiles down to Ruby. "It's just ruby."
|
112
126
|
email:
|
113
127
|
- searls@gmail.com
|
@@ -117,7 +131,7 @@ extensions: []
|
|
117
131
|
extra_rdoc_files: []
|
118
132
|
files:
|
119
133
|
- ".gitignore"
|
120
|
-
- ".
|
134
|
+
- ".irbrc"
|
121
135
|
- ".travis.yml"
|
122
136
|
- Gemfile
|
123
137
|
- LICENSE.txt
|
@@ -134,9 +148,17 @@ files:
|
|
134
148
|
- lib/emoruby/version.rb
|
135
149
|
- spec/1_hello_world_spec.rb
|
136
150
|
- spec/2_module_with_addition_spec.rb
|
151
|
+
- spec/3_stabby_proc_spec.rb
|
152
|
+
- spec/5_comments_spec.rb
|
137
153
|
- spec/fixtures/1_hello_world.emoruby
|
138
154
|
- spec/fixtures/1_hello_world.rb
|
139
155
|
- spec/fixtures/2_module_with_addition.emoruby
|
156
|
+
- spec/fixtures/3_stabby_proc.emoruby
|
157
|
+
- spec/fixtures/3_stabby_proc.rb
|
158
|
+
- spec/fixtures/4_method_access.emoruby
|
159
|
+
- spec/fixtures/4_method_access.rb
|
160
|
+
- spec/fixtures/5_comments.emoruby
|
161
|
+
- spec/fixtures/5_comments.rb
|
140
162
|
- spec/spec_helper.rb
|
141
163
|
- spec/support/file_helpers.rb
|
142
164
|
homepage: https://github.com/searls/emoruby
|
@@ -166,8 +188,16 @@ summary: A little emoji language that compiles down to Ruby
|
|
166
188
|
test_files:
|
167
189
|
- spec/1_hello_world_spec.rb
|
168
190
|
- spec/2_module_with_addition_spec.rb
|
191
|
+
- spec/3_stabby_proc_spec.rb
|
192
|
+
- spec/5_comments_spec.rb
|
169
193
|
- spec/fixtures/1_hello_world.emoruby
|
170
194
|
- spec/fixtures/1_hello_world.rb
|
171
195
|
- spec/fixtures/2_module_with_addition.emoruby
|
196
|
+
- spec/fixtures/3_stabby_proc.emoruby
|
197
|
+
- spec/fixtures/3_stabby_proc.rb
|
198
|
+
- spec/fixtures/4_method_access.emoruby
|
199
|
+
- spec/fixtures/4_method_access.rb
|
200
|
+
- spec/fixtures/5_comments.emoruby
|
201
|
+
- spec/fixtures/5_comments.rb
|
172
202
|
- spec/spec_helper.rb
|
173
203
|
- spec/support/file_helpers.rb
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.1.1
|