magic_mirror 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f53fb81e7a002b62787268865bd46a523b8afb8
4
+ data.tar.gz: 2b822cf1abf30c1fb9fcf070ebe922a89e696a8c
5
+ SHA512:
6
+ metadata.gz: 0f2a7fe1f79837d8d418cdb1c2227dd347c14ec362dc0e98cd644e021e684f881ca766c5e146dad9b11c3b2f9c813e857afff25c16ef2df4fa7b6b29efa461d6
7
+ data.tar.gz: 23b4f15ea87c3e6710bc7f44964a9eb2ba9e3a3075e7cd7c06a936d97b796663d0140b4d7bda96a05bdd9d0c377529f48f001c2ebb01329a49fc1971e035c422
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in magic_mirror.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 TheNotary
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # MagicMirror
2
+
3
+ Have you ever wanted to add a GUI to your ruby command line application. Didn't want to go the ncurses route? Well with Ruby's new Magic Mirror gem, you can build a stunning UI with html. No need to rewrite your code and do a massive MVC re-write, just require this gem, point it to an html public directory that includes and html index (and optionally javascripts and css files) and your UI is all set and standing by on 127.0.0.1:4567 by default.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'magic_mirror'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ rt = RubyTube.new
20
+
21
+ # Point RubyTube to where the html public directory is
22
+ rt.www_root = "gui/"
23
+
24
+ # Possibly some routes setup for Sinatra
25
+ # rt...
26
+
27
+
28
+ # start sinatra, faye/websockets and prints "browse to 127.0.0.1:4567"
29
+ rt.run!
30
+
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( https://github.com/[my-github-username]/magic_mirror/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'rake'
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+
8
+ desc "Run unit specs"
9
+ RSpec::Core::RakeTask.new(:unit) do |t|
10
+ t.rspec_opts = %w(-fd -c)
11
+ t.pattern = "./spec/unit/**/*_spec.rb"
12
+ end
13
+
14
+ desc "Run integration specs that are very high level"
15
+ RSpec::Core::RakeTask.new(:integration) do |t|
16
+ t.rspec_opts = %w(-fd -c)
17
+ t.pattern = "./spec/integration/**/*_spec.rb"
18
+ end
19
+
20
+ desc "Run all specs"
21
+ RSpec::Core::RakeTask.new(:spec) do |t|
22
+ t.rspec_opts = %w(-fd -c)
23
+ end
24
+
25
+ # this is for running tests that you've marked current... eg: it 'should work', :current => true do
26
+ RSpec::Core::RakeTask.new(:current) do |spec|
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ spec.rspec_opts = ['--tag current']
29
+ end
30
+
31
+ # alias for current
32
+ RSpec::Core::RakeTask.new(:c) do |spec|
33
+ spec.pattern = 'spec/**/*_spec.rb'
34
+ spec.rspec_opts = ['--tag current']
35
+ end
36
+
37
+ task :default => :spec
38
+ task :test => :spec
39
+
40
+
data/changelog ADDED
@@ -0,0 +1,18 @@
1
+ ** 0.0.x **
2
+ TODO: List off what features you'll be including at some point in the
3
+ future.
4
+
5
+ - Think of other popular uses for rendering...
6
+ - secure by making servers listen only on localhost
7
+
8
+ Currently:
9
+
10
+
11
+ Finished:
12
+
13
+
14
+
15
+ ** 0.0.1 **
16
+ - got websockets online
17
+ - Setup command_cache
18
+ - Setup javascript for drawing to canvas
@@ -0,0 +1,7 @@
1
+ class CommandCache < Array
2
+ def <<(value)
3
+ #puts "you pushed"
4
+ MagicMirror.mirror.speak_into(value)
5
+ super
6
+ end
7
+ end
@@ -0,0 +1,72 @@
1
+ module MagicMirror
2
+ FAYE_PORT = 4555
3
+ class Mirror
4
+ def initialize
5
+
6
+ end
7
+
8
+ def init_servers
9
+ threads = []
10
+ # start sinatra
11
+ threads << start_sinatra
12
+ threads << start_faye
13
+
14
+ threads
15
+ end
16
+
17
+ def start_sinatra
18
+ Thread.new {
19
+ SinatraSilver::App.run!
20
+ }
21
+ end
22
+
23
+ def start_faye
24
+ # binding.pry
25
+
26
+
27
+
28
+ Thread.new {
29
+ bayeux = Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)
30
+ bayeux.listen(FAYE_PORT)
31
+ run bayeux
32
+ }
33
+
34
+ #wait_until_faye_is_up
35
+
36
+ end
37
+
38
+ def get_faye_app
39
+
40
+ end
41
+
42
+ # sends messages through faye server to web interface
43
+ def speak_into(msg)
44
+ channel = "/0001"
45
+
46
+ message = {:channel => channel, :data => msg}
47
+ uri = URI.parse("http://localhost:#{FAYE_PORT}/faye")
48
+ begin
49
+ Net::HTTP.post_form(uri, :message => message.to_json)
50
+ rescue
51
+ end
52
+
53
+ end
54
+
55
+ def wait_until_faye_is_up
56
+ while(true) do
57
+ begin
58
+ uri = URI.parse("http://localhost:#{FAYE_PORT}/faye")
59
+ # Shortcut
60
+ response = Net::HTTP.get_response(uri)
61
+ rescue
62
+
63
+ end
64
+ #binding.pry
65
+ sleep 1
66
+ break if response and response.code == 400 and response.body == "Bad request"
67
+ end
68
+ end
69
+
70
+
71
+ end
72
+ end
@@ -0,0 +1,16 @@
1
+ require 'tilt'
2
+
3
+ module SinatraSilver
4
+ class App < Sinatra::Base
5
+ set :root, MagicMirror.sinatra_root
6
+ # set :app_file, MagicMirror.sinatra_root
7
+ # set :views, MagicMirror.sinatra_root
8
+ set :views, Proc.new { File.join(MagicMirror.sinatra_root, "lib", "views") }
9
+ #set :public_folder, Proc.new { File.join(MagicMirror.sinatra_root, "lib", "views") }
10
+
11
+ get '/' do
12
+ @command_cache = MagicMirror.command_cache.to_json
13
+ erb :index # 'Hello world!'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module MagicMirror
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,49 @@
1
+ require 'json'
2
+ require 'rack'
3
+ require 'thin'
4
+ require 'faye'
5
+ require 'sinatra'
6
+ require 'tilt'
7
+ require 'tilt/erb'
8
+
9
+ require "magic_mirror/version"
10
+ require "magic_mirror/mirror"
11
+ require "magic_mirror/command_cache"
12
+
13
+ module MagicMirror
14
+ @@mirror = nil
15
+ @@command_cache = CommandCache.new # unless @@command_cache
16
+
17
+ def self.new
18
+ @sinatra_root = File.expand_path('../..', __FILE__) if sinatra_root.nil?
19
+ @@mirror = Mirror.new
20
+ end
21
+
22
+ def self.mirror
23
+ @@mirror
24
+ end
25
+
26
+ def self.sinatra_root=(value)
27
+ @sinatra_root = value
28
+ end
29
+
30
+ def self.sinatra_root
31
+ @sinatra_root
32
+ end
33
+
34
+ def self.command_cache
35
+ # [ "RenderingCanvas.new('myCanvas', { title: 'trtl', minsize: [800, 600], is_test: true })",
36
+ # "RenderingcLine.new('myCanvas', 0, 0, 50, 50)"
37
+ # ]
38
+ @@command_cache
39
+ end
40
+
41
+ def self.command_cache=(value)
42
+ @@command_cache=value
43
+ end
44
+
45
+ end
46
+
47
+
48
+ # lol, hoisting problem in ruby??? thx sinatra...
49
+ require 'magic_mirror/sinatra_silver'
@@ -0,0 +1,2 @@
1
+ I'm in magic_mirror's lib folder.
2
+ You should specify MagicMirror.sinatra_root to be the root of *YOUR* gem instead of letting it default.
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'magic_mirror/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "magic_mirror"
8
+ spec.version = MagicMirror::VERSION
9
+ spec.authors = ["TheNotary"]
10
+ spec.email = ["no@mail.plz"]
11
+
12
+ spec.summary = %q{ A library that makes it easy to add an HTML based GUI to your ruby library}
13
+ spec.homepage = "https://github.com/TheNotary/magic_mirror"
14
+ spec.license = "MIT" # uncomment this line if MIT is the best license for your situation
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+
21
+ spec.add_dependency "sinatra", "~> 1.4"
22
+ spec.add_dependency "faye", "0.8.6"
23
+ spec.add_dependency "rack", "~> 1.6"
24
+ spec.add_dependency "thin", "~> 1.6"
25
+ spec.add_dependency "tilt", "~> 2.0"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.10"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.3"
30
+ spec.add_development_dependency "pry"
31
+ end
data/rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magic_mirror
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - TheNotary
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faye
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
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: thin
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: tilt
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.3'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - no@mail.plz
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".travis.yml"
148
+ - CODE_OF_CONDUCT.md
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - changelog
154
+ - lib/magic_mirror.rb
155
+ - lib/magic_mirror/command_cache.rb
156
+ - lib/magic_mirror/mirror.rb
157
+ - lib/magic_mirror/sinatra_silver.rb
158
+ - lib/magic_mirror/version.rb
159
+ - lib/views/index.erb
160
+ - magic_mirror.gemspec
161
+ - rspec
162
+ homepage: https://github.com/TheNotary/magic_mirror
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.4.4
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: A library that makes it easy to add an HTML based GUI to your ruby library
186
+ test_files: []