motion-live 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +18 -0
- data/README.md +0 -0
- data/lib/motion-live.rb +21 -0
- data/lib/motion/project/live.rb +166 -0
- metadata +97 -0
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2012 Fabio Angelo Pelosin
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
File without changes
|
data/lib/motion-live.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Copyright (c) 2012 Fabio Angelo Pelosin
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
# subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
|
21
|
+
require 'motion/project/live'
|
@@ -0,0 +1,166 @@
|
|
1
|
+
# Copyright (c) 2012 Fabio Angelo Pelosin
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
# subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
|
21
|
+
unless defined?(Motion::Project::Config)
|
22
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'pty'
|
26
|
+
require 'rubygems'
|
27
|
+
require 'colored'
|
28
|
+
require 'rb-fsevent'
|
29
|
+
require 'fileutils'
|
30
|
+
|
31
|
+
class Live
|
32
|
+
def initialize
|
33
|
+
@buffered_output = ''
|
34
|
+
end
|
35
|
+
|
36
|
+
def run
|
37
|
+
create_scratch_pad_if_needed
|
38
|
+
# TODO: running rake inside rake is very lame,
|
39
|
+
# need to do something about it.
|
40
|
+
PTY.spawn("rake", 'simulator') do |stdout, stdin, pid|
|
41
|
+
@stdout, @stdin = stdout, stdin
|
42
|
+
console_attach
|
43
|
+
welcome "Welcome to liveconding"
|
44
|
+
print console_self
|
45
|
+
start_watching
|
46
|
+
end
|
47
|
+
rescue PTY::ChildExited
|
48
|
+
adieu "[LIVE] Terminating as the simulator quitted"
|
49
|
+
# TODO: need to trap interrupt to exit gracefully.
|
50
|
+
# rescue Interrupt
|
51
|
+
# adieu "Bye Bye"
|
52
|
+
end
|
53
|
+
|
54
|
+
def start_watching
|
55
|
+
fsevent = FSEvent.new
|
56
|
+
fsevent.watch Dir.pwd do |dirs|
|
57
|
+
send_changes
|
58
|
+
end
|
59
|
+
fsevent.run
|
60
|
+
end
|
61
|
+
|
62
|
+
def send_changes
|
63
|
+
code = find_changed_lines
|
64
|
+
return if code.empty?
|
65
|
+
puts "\n\n#{code.join("\n")}\n".magenta
|
66
|
+
print console_self
|
67
|
+
code.each { |l| console_put l }
|
68
|
+
wait_console_result
|
69
|
+
puts "\n\n Changes processed \n\n".reversed
|
70
|
+
print console_self
|
71
|
+
end
|
72
|
+
|
73
|
+
def find_changed_lines
|
74
|
+
new = scratch_pad
|
75
|
+
if @old_code && !new.include?('#nodiff')
|
76
|
+
delta = new.split("\n") - @old_code.split("\n")
|
77
|
+
else
|
78
|
+
delta = new.split("\n")
|
79
|
+
end
|
80
|
+
@old_code = new
|
81
|
+
# reject comments
|
82
|
+
delta.reject{ |l| l =~ /^\s*$/ || l =~ /^\s*#/ }
|
83
|
+
end
|
84
|
+
|
85
|
+
### Helpers
|
86
|
+
|
87
|
+
def create_scratch_pad_if_needed
|
88
|
+
FileUtils.touch(scratchpad_file) unless File.exist?(scratchpad_file)
|
89
|
+
end
|
90
|
+
|
91
|
+
def scratch_pad
|
92
|
+
File.read(scratchpad_file)
|
93
|
+
end
|
94
|
+
|
95
|
+
def scratchpad_file
|
96
|
+
'LiveScratchpad.rb'
|
97
|
+
end
|
98
|
+
|
99
|
+
def dirs
|
100
|
+
Dir.pwd
|
101
|
+
end
|
102
|
+
|
103
|
+
### Interactions with the ruby motion REPL
|
104
|
+
|
105
|
+
def console_self
|
106
|
+
wait_console
|
107
|
+
@buffered_output[/\(.*\)>/] + ' '
|
108
|
+
end
|
109
|
+
|
110
|
+
def console_put(input)
|
111
|
+
wait_console
|
112
|
+
@stdin.puts input
|
113
|
+
@buffered_output = ''
|
114
|
+
wait_console
|
115
|
+
end
|
116
|
+
|
117
|
+
def wait_console
|
118
|
+
until @buffered_output =~ /\(.*\)[>,?]/
|
119
|
+
# Wait
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def wait_console_result
|
124
|
+
until @buffered_output =~ /=> .*/
|
125
|
+
# Wait
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def console_attach
|
130
|
+
Thread.new do
|
131
|
+
loop do
|
132
|
+
buffer = ''
|
133
|
+
@stdout.readpartial(4096, buffer)
|
134
|
+
@buffered_output << buffer
|
135
|
+
print colorize_console_output(buffer)
|
136
|
+
STDOUT.flush
|
137
|
+
end
|
138
|
+
end
|
139
|
+
wait_console
|
140
|
+
end
|
141
|
+
|
142
|
+
def colorize_console_output(string)
|
143
|
+
color = string.include?('Error') ? :yellow : :green
|
144
|
+
string.gsub(/\n*(=> .*)/,"\n" + '\1'.send(color))
|
145
|
+
end
|
146
|
+
|
147
|
+
### Custom output
|
148
|
+
|
149
|
+
def welcome(string)
|
150
|
+
puts
|
151
|
+
puts
|
152
|
+
puts "-> #{string}".green
|
153
|
+
puts
|
154
|
+
end
|
155
|
+
|
156
|
+
def adieu(string)
|
157
|
+
puts
|
158
|
+
puts string.yellow
|
159
|
+
puts
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
desc "Live code"
|
164
|
+
task :live do
|
165
|
+
Live.new.run
|
166
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-live
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Fabio Angelo Pelosin
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-05-21 00:00:00 Z
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
prerelease: false
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 11
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
version: "1.2"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
name: colored
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 57
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
- 9
|
45
|
+
- 1
|
46
|
+
version: 0.9.1
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
name: rb-fsevent
|
50
|
+
description: Write you code in a scratch pad file and have the changes reflected in your application running in the simulator. Suited for prototyping user interfaces.
|
51
|
+
email: fabiopelosin@gmail.com
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- lib/motion/project/live.rb
|
60
|
+
- lib/motion-live.rb
|
61
|
+
- README.md
|
62
|
+
- LICENSE
|
63
|
+
homepage: https://github.com/irrationalfab/motion-live
|
64
|
+
licenses: []
|
65
|
+
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.8.21
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: Live coding for RubyMotion projects.
|
96
|
+
test_files: []
|
97
|
+
|