emoruby 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ab9827dc3bc5757c6b5b6b48fcd052612ad0335
4
+ data.tar.gz: 9e713b0d9d1bec3ab53287594a87422581334418
5
+ SHA512:
6
+ metadata.gz: 5710e95755df5bcf2870e32e64fcf420e7fd405586f4d42392f540dc330fa439121a71f193dcb2441dfc8d08dc17d2e912dedcfbd564ee10489e315788446aa1
7
+ data.tar.gz: baab73de95107668beb4947e291a25d9e626cd9ba4489af13f5be7f19395fcd53a4b33dd77866f08692f13168bff65e28b9e4cdb2bffd90899069b56f6d19bf1
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
@@ -0,0 +1 @@
1
+ 2.1.1
@@ -0,0 +1,2 @@
1
+ language: 'ruby'
2
+ script: 'bundle exec rspec'
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Justin Searls
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,75 @@
1
+ # emoruby
2
+
3
+ A little language that compiles Emoji down to Ruby. It's just Ruby. Really.
4
+
5
+ ## The Language
6
+
7
+ If I were a real language designer, I would have put a lot of thought into the syntax, semantics, and structure of emoruby. Instead I basically implemented an inefficient find-and-replace from a static dictionary. (🐄🎩!)
8
+
9
+ Anyway, here is an example hello world program:
10
+
11
+ ``` emoruby
12
+ 📋 ❤️
13
+ 🔜 👋
14
+ 👀 💬😃 🌏💬
15
+ 🔚
16
+ 🔚
17
+
18
+ ❤️▪️🐣▪️👋
19
+ ```
20
+
21
+ which is equivalent to this Ruby:
22
+
23
+ ``` ruby
24
+ class Heart
25
+ def wave
26
+ puts "smiley earth_asia"
27
+ end
28
+ end
29
+
30
+ Heart.new.wave
31
+ ```
32
+
33
+ ## Using the gem
34
+
35
+ ### registering the ".emoruby" file extension
36
+
37
+ 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
+
39
+ ``` ruby
40
+ > require 'emoruby'
41
+ => true
42
+ > Emoruby.register
43
+ => nil
44
+ > require 'hello_world'
45
+ smiley earth_asia
46
+ => true
47
+ ```
48
+
49
+ ### command line
50
+
51
+ You can run emoruby from the command line by passing an emoruby file as the first argument:
52
+
53
+ ``` shell
54
+ $ emoruby spec/fixtures/1_hello_world.emoruby
55
+ smiley earth_asia
56
+ ```
57
+
58
+ ### API
59
+
60
+ The API allows both evaluation of emoruby code as well as translation to Ruby.
61
+
62
+ ``` ruby
63
+ > source = "💬😃 🌏💬"
64
+ => "💬😃 🌏💬"
65
+ > Emoruby.eval(source)
66
+ => "smiley earth_asia"
67
+ Emoruby.emoji_to_ruby(source)
68
+ => "\"smiley earth_asia\""
69
+ ```
70
+
71
+ ## Versioning
72
+
73
+ The Emoruby team embraces and advocates the adoption of the the emerging iconographic versioning standard ("icover" for short).
74
+
75
+ The initial release was 💩 (in honor of @tenderlove's 💩-lang). The next planned release is ✊.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'emoruby'
4
+ require 'pathname'
5
+
6
+ if path_arg = ARGV.first
7
+ path = Pathname.new(path_arg).exist? ? Pathname.new(path_arg) : Pathname.pwd.join(path_arg)
8
+ Emoruby.eval(File.read(path))
9
+ else
10
+ puts "Usage:"
11
+ puts " emoruby \"path/to/some.emoruby\""
12
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'emoruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "emoruby"
8
+ spec.version = Emoruby::VERSION
9
+ spec.authors = ["Justin Searls"]
10
+ spec.email = ["searls@gmail.com"]
11
+ spec.summary = %q{A little emoji language that compiles down to Ruby}
12
+ spec.description = %q{A little emoji language that compiles down to Ruby. "It's just ruby."}
13
+ spec.homepage = "https://github.com/searls/emoruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "emoji_data"
22
+ spec.add_dependency "polyglot"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec", '~> 2.99'
27
+ spec.add_development_dependency "rspec-given"
28
+ spec.add_development_dependency "pry"
29
+ end
@@ -0,0 +1,22 @@
1
+ require "emoruby/version"
2
+ require "emoruby/emoji_script"
3
+
4
+ # TODO there has to be a better way to eval on top of the world, right?
5
+ def __emoruby_top_level_binding_eval(source)
6
+ binding.eval(source)
7
+ end
8
+
9
+ module Emoruby
10
+ def self.emoji_to_ruby(source)
11
+ EmojiScript.new(source).to_ruby
12
+ end
13
+
14
+ def self.eval(source)
15
+ __emoruby_top_level_binding_eval(emoji_to_ruby(source))
16
+ end
17
+
18
+ def self.register(file_extension = "emoruby")
19
+ require 'emoruby/require'
20
+ Require.register(file_extension)
21
+ end
22
+ end
@@ -0,0 +1,58 @@
1
+ require 'emoji_data'
2
+ require 'emoruby/util/string'
3
+
4
+ module Emoruby
5
+ class ConvertsEmojiToRuby
6
+ TRANSLATIONS = {
7
+ "clipboard" => "class",
8
+ "soon" => "def",
9
+ "eyes" => "puts",
10
+ "speech_balloon" => "\"",
11
+ "black_small_square" => ".",
12
+ "hatching_chick" => "new"
13
+ }
14
+
15
+ GARBAGE = [
16
+ [239,184,143] # evil problematic whitespace where is it from where am i what even
17
+ ]
18
+
19
+ def call(source)
20
+ chars = clean_chars(scan_and_translate_constants(source).chars)
21
+
22
+ translate_chars(chars) do |char|
23
+ next unless emoji_name = emoji_name_for(char)
24
+ emoji_name
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def scan_and_translate_constants(source)
31
+ constant_map = Hash[source.split(/\s+/).each_cons(2).map do |operator, emo_constant|
32
+ next unless ["class", "module"].include?(emoji_name_for(operator))
33
+ [emo_constant, Util::String.classify(emo_constant.chars.map {|c| emoji_name_for(c) }.join)]
34
+ end.compact]
35
+
36
+ source.gsub(Regexp.new(constant_map.keys.map { |x| Regexp.escape(x) }.join('|')), constant_map)
37
+ end
38
+
39
+ def emoji_name_for(char)
40
+ return unless emoji = EmojiData.find_by_str(char).first
41
+ TRANSLATIONS[emoji.short_name] || emoji.short_name
42
+ end
43
+
44
+ def clean_chars(source)
45
+ source.reject {|c| GARBAGE.include?(c.bytes) }
46
+ end
47
+
48
+ def translate_chars(chars)
49
+ chars.each_with_index.map do |original_char, i|
50
+ if new_char = yield(original_char, i)
51
+ new_char
52
+ else
53
+ original_char
54
+ end
55
+ end.join
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,19 @@
1
+ require 'emoruby/converts_emoji_to_ruby'
2
+
3
+ module Emoruby
4
+ class EmojiScript
5
+ attr_reader :source
6
+
7
+ def initialize(source)
8
+ @source = source
9
+ end
10
+
11
+ def to_ruby
12
+ @ruby ||= ConvertsEmojiToRuby.new.call(@source)
13
+ end
14
+
15
+ def eval
16
+ eval(to_ruby)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Emoruby
2
+ class Require
3
+ def self.load(filename, options = nil)
4
+ Emoruby.eval(File.read(filename))
5
+ end
6
+
7
+ def self.register(file_extension)
8
+ require 'polyglot'
9
+ Polyglot.register(file_extension, Emoruby::Require)
10
+ return
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ # Ripped pretty much right out of activesupport 4.1.8
2
+ # activesupport/lib/active_support/inflector/methods.rb
3
+
4
+ module Emoruby
5
+ module Util
6
+ module String
7
+ def self.classify(string)
8
+ camelize(string.sub(/.*\./, ''))
9
+ end
10
+
11
+ private
12
+
13
+ def self.camelize(term)
14
+ string = term.to_s
15
+ string = string.sub(/^[a-z\d]*/) { $&.capitalize }
16
+ string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
17
+ string.gsub!('/', '::')
18
+ string
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Emoruby
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ require 'emoruby'
4
+
5
+ describe Emoruby do
6
+ Given(:emo_path) { Pathname.pwd.join("spec","fixtures","#{file_name}.emoruby") }
7
+ Given(:emo_source) { File.read(emo_path) }
8
+ Given(:expected_ruby_path) { Pathname.pwd.join("spec","fixtures","#{file_name}.rb") }
9
+ Given(:expected_ruby) { File.read(expected_ruby_path) }
10
+
11
+ context "a hello world app" do
12
+ Given(:file_name) { "1_hello_world" }
13
+
14
+ describe 'translating source' do
15
+ When(:result) { Emoruby.emoji_to_ruby(emo_source) }
16
+ Then { expect(result).to match_all_the_characters_of(expected_ruby) }
17
+ end
18
+
19
+ describe 'evaluating source' do
20
+ Given(:source_with_stripped_puts) { emo_source.gsub(EmojiData.find_by_short_name("eyes").first.to_s, "") }
21
+ When(:result) { Emoruby.eval(source_with_stripped_puts) }
22
+ Then { Heart.new.wave == "smiley earth_asia" }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ 📋 ❤️
2
+ 🔜 👋
3
+ 👀 💬😃 🌏💬
4
+ 🔚
5
+ 🔚
6
+
7
+ ❤️▪️🐣▪️👋
@@ -0,0 +1,7 @@
1
+ class Heart
2
+ def wave
3
+ puts "smiley earth_asia"
4
+ end
5
+ end
6
+
7
+ Heart.new.wave
@@ -0,0 +1,18 @@
1
+ require 'rspec/given'
2
+
3
+ RSpec::Matchers.define :match_all_the_characters_of do |expected|
4
+ match do |actual|
5
+ expected.chars.each_with_index.all? do |c, i|
6
+ actual[i] == c
7
+ end
8
+ end
9
+
10
+ failure_message_for_should do |actual|
11
+ expected.chars.each_with_index.reject { |c, i| actual[i] == c }.map do |c,i|
12
+ "expected that character #{i} would be #{c} but was #{actual[i]} (near '#{actual[i-5..i+5]}')"
13
+ end.join("\n")
14
+ end
15
+ end
16
+
17
+ # other junk
18
+ require 'pry'
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emoruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Searls
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: emoji_data
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: polyglot
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.99'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.99'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-given
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A little emoji language that compiles down to Ruby. "It's just ruby."
112
+ email:
113
+ - searls@gmail.com
114
+ executables:
115
+ - emoruby
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".ruby-version"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/emoruby
127
+ - emoruby.gemspec
128
+ - lib/emoruby.rb
129
+ - lib/emoruby/converts_emoji_to_ruby.rb
130
+ - lib/emoruby/emoji_script.rb
131
+ - lib/emoruby/require.rb
132
+ - lib/emoruby/util/string.rb
133
+ - lib/emoruby/version.rb
134
+ - spec/1_hello_world_spec.rb
135
+ - spec/fixtures/1_hello_world.emoruby
136
+ - spec/fixtures/1_hello_world.rb
137
+ - spec/spec_helper.rb
138
+ homepage: https://github.com/searls/emoruby
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.2.2
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: A little emoji language that compiles down to Ruby
162
+ test_files:
163
+ - spec/1_hello_world_spec.rb
164
+ - spec/fixtures/1_hello_world.emoruby
165
+ - spec/fixtures/1_hello_world.rb
166
+ - spec/spec_helper.rb