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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8437f52585aa5e235a4aeabc77778b7aecada629
4
- data.tar.gz: a5888ca7dea71281b22813af3141e8173e3ea557
3
+ metadata.gz: dd782a7a3726759ec5cbd3eec6a12c90a63a5db4
4
+ data.tar.gz: 69eab3dbe410e976a3537c1fb34e507c18e2201d
5
5
  SHA512:
6
- metadata.gz: 7dcae6112ec5222f8eadf02b63b01a12a00b5f2a0862ba0d9c3d0bd44057050c1e34d51e31dcf3666da57db2dc1e95b25ab5748551f9c8939850effd9ad67fc6
7
- data.tar.gz: c88caca36a2681bbc062ace60cca8a5a13106e9ae0da4c5bb2bc1b780be578cef44197c04b685daa222152f2bf33613ca2f7387624373b363f42d8e15f35d012
6
+ metadata.gz: 68935d847520bcea700230b37f7a33c2879f7465f7119f4670810770e23f4f9f84171fc3249d004b402e3d21ade4a690ea7b51e3ff1a2aafb2b55b3722330287
7
+ data.tar.gz: 10437fb26dad723be5a0bcecc94392ee2c6c09529f335fcba0c1ddd6976277133b7fe3cb0442e0a079bd7561ee82af211ae6034fcd479378f1163cbac0c65f9b
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+ .ruby-version
data/.irbrc ADDED
@@ -0,0 +1,3 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'emoruby'
3
+ Emoruby.register
@@ -1,2 +1,8 @@
1
1
  language: 'ruby'
2
+ rvm:
3
+ - 2.1
2
4
  script: 'bundle exec rspec'
5
+ env:
6
+ CODECLIMATE_REPO_TOKEN: f1127e31b44ca68eddc49a828269943dd40ba378c4f4356ca07690a71442f6dc
7
+ sudo: false
8
+ cache: bundler
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
- ``` emoruby
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
- ``` ruby
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
- ``` shell
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
- ``` ruby
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). The next planned release is ✊.
141
+ The initial release was 💩 (in honor of @tenderlove's 💩-lang). After that, was released. Next up is, of course, 🐷.
@@ -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
@@ -26,4 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rspec", '~> 2.99'
27
27
  spec.add_development_dependency "rspec-given"
28
28
  spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "codeclimate-test-reporter"
30
+
29
31
  end
@@ -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 call(source)
16
- chars = clean_chars(scan_and_translate_constants(source).chars)
15
+ def initialize(source)
16
+ @source = source
17
+ end
17
18
 
18
- translate_chars(chars) do |char|
19
- next unless emoji_name = emoji_name_for(char)
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 scan_and_translate_constants(source)
27
- constant_map = Hash[source.split(/\s+/).each_cons(2).map do |operator, emo_constant|
28
- next unless ["class", "module"].include?(emoji_name_for(operator))
29
- [emo_constant, Util::String.classify(emo_constant.chars.map {|c| emoji_name_for(c) }.join)]
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 emoji_name_for(char)
36
- return unless emoji = EmojiData.find_by_str(char).first
37
- TRANSLATIONS[emoji.to_s] || emoji.short_name
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 |original_char, i|
46
- if new_char = yield(original_char, i)
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
@@ -9,7 +9,7 @@ module Emoruby
9
9
  end
10
10
 
11
11
  def to_ruby
12
- @ruby ||= ConvertsEmojiToRuby.new.call(@source)
12
+ @ruby ||= ConvertsEmojiToRuby.new(@source).call
13
13
  end
14
14
 
15
15
  def eval
@@ -1,3 +1,3 @@
1
1
  module Emoruby
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -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 'translating source' do
11
- When(:result) { Emoruby.emoji_to_ruby(emo_source) }
12
- Then { expect(result).to match_all_the_characters_of(expected_ruby) }
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
- Given(:source_with_stripped_puts) { emo_source.gsub(EmojiData.find_by_short_name("eyes").first.to_s, "") }
17
- When(:result) { Emoruby.eval(source_with_stripped_puts) }
18
- Then { Heart.new.wave == "smiley earth_asia" }
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
@@ -1,3 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ require 'emoruby'
4
+
1
5
  describe Emoruby do
2
6
  Given(:source) { load_fixture("2_module_with_addition") }
3
7
  When { Emoruby.eval(source) }
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ require 'emoruby'
4
+
5
+ describe Emoruby do
6
+ Given(:source) { load_fixture("3_stabby_proc") }
7
+ When(:result) { Emoruby.eval(source) }
8
+ Then { expect(result).to eq("smiley") }
9
+ 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,3 @@
1
+ 👉 🔨
2
+ 💬😃💬
3
+ 🔚▪️📞
@@ -0,0 +1,3 @@
1
+ -> do
2
+ "smiley"
3
+ end.call
@@ -0,0 +1,20 @@
1
+ 📋 ❤️
2
+ ⛔️ 🔜 👋
3
+ 👀 💬😃 🌏💬
4
+ 🔚
5
+ 🔚
6
+
7
+ 📋 ⛄️
8
+ 🔓
9
+ 🔜 🍭
10
+ 🔚
11
+
12
+ 🔒
13
+ 🔜 💾
14
+ 🔚
15
+
16
+ ⛔️
17
+ 🔜 👋
18
+ 👀 💬😃 🌏💬
19
+ 🔚
20
+ 🔚
@@ -0,0 +1,20 @@
1
+ class Heart
2
+ private def wave
3
+ puts "smiley earth_asia"
4
+ end
5
+ end
6
+
7
+ class Snowman
8
+ public
9
+ def lollipop
10
+ end
11
+
12
+ protected
13
+ def floppy_disk
14
+ end
15
+
16
+ private
17
+ def wave
18
+ puts "smiley earth_asia"
19
+ end
20
+ end
@@ -0,0 +1 @@
1
+ 💭 Comment! 👋
@@ -0,0 +1 @@
1
+ # Comment! 👋
@@ -1,23 +1,11 @@
1
1
  require 'rspec/given'
2
- require 'support/file_helpers'
3
2
 
4
- RSpec::Matchers.define :match_all_the_characters_of do |expected|
5
- match do |actual|
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
- failure_message_for_should do |actual|
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.2
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-22 00:00:00.000000000 Z
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
- - ".ruby-version"
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
@@ -1 +0,0 @@
1
- 2.1.1