nyoibo 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -3,11 +3,6 @@ module NyoiboHelper
|
|
3
3
|
options[:html] ||= {}
|
4
4
|
options[:html][:id] ||= 'ws-form'
|
5
5
|
output = ''
|
6
|
-
output << javascript_tag(<<EOS)
|
7
|
-
WEB_SOCKET_DEBUG = true;
|
8
|
-
WEB_SOCKET_SWF_LOCATION = '/WebSocketMain.swf';
|
9
|
-
var nyoibo = #{I18n.t('nyoibo').to_json};
|
10
|
-
EOS
|
11
6
|
output << form_for(model, options, &block)
|
12
7
|
output << content_tag(:div, '', :id => 'ws-progress')
|
13
8
|
output.html_safe
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'rails'
|
2
2
|
require 'rails/generators'
|
3
|
+
|
3
4
|
module Nyoibo
|
4
5
|
module Generators
|
5
|
-
class InstallGenerator < Rails::Generators::Base
|
6
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
7
|
source_root File.expand_path("../templates", __FILE__)
|
7
8
|
|
8
9
|
desc "Creates a Nyoibo initializer and copy javascript and locale files to your application."
|
@@ -10,10 +11,10 @@ module Nyoibo
|
|
10
11
|
template "nyoibo.rb.erb", "config/initializers/nyoibo.rb"
|
11
12
|
template "nyoibo_en.yml", "config/locales/nyoibo_en.yml"
|
12
13
|
template "nyoibo.js.coffee", "app/assets/javascripts/nyoibo.js.coffee"
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
copy_file "../../../../vendor/html5jp/progress.js", "app/assets/javascripts/progress.js"
|
15
|
+
copy_file "../../../../vendor/web-socket-js/web_socket.js", "app/assets/javascripts/web_socket.js"
|
16
|
+
copy_file "../../../../vendor/web-socket-js/swfobject.js", "app/assets/javascripts/swfobject.js"
|
17
|
+
copy_file "../../../../vendor/web-socket-js/WebSocketMain.swf", "public/WebSocketMain.swf"
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
@@ -1,6 +1,30 @@
|
|
1
|
+
`WEB_SOCKET_DEBUG = true;
|
2
|
+
WEB_SOCKET_SWF_LOCATION = '/WebSocketMain.swf';`
|
3
|
+
|
4
|
+
jQuery.fn.serializeObject = () ->
|
5
|
+
arrayData = this.serializeArray()
|
6
|
+
objectData = {}
|
7
|
+
|
8
|
+
$.each arrayData, () ->
|
9
|
+
if this.value?
|
10
|
+
value = this.value
|
11
|
+
else
|
12
|
+
value = ''
|
13
|
+
|
14
|
+
if objectData[this.name]?
|
15
|
+
unless objectData[this.name].push
|
16
|
+
objectData[this.name] = [objectData[this.name]]
|
17
|
+
|
18
|
+
objectData[this.name].push value
|
19
|
+
else
|
20
|
+
objectData[this.name] = value
|
21
|
+
|
22
|
+
return objectData
|
23
|
+
|
1
24
|
jQuery ($)->
|
2
|
-
|
3
|
-
|
25
|
+
if $("#ws-progress").length > 0
|
26
|
+
progress = new html5jp.progress("ws-progress")
|
27
|
+
progress.draw()
|
4
28
|
|
5
29
|
form = $('#ws-form')
|
6
30
|
progress_bar = $("#ws-progress")
|
@@ -35,6 +59,8 @@ jQuery ($)->
|
|
35
59
|
switch evt.data
|
36
60
|
when 'OK Ready'
|
37
61
|
params = {filename: file.name, comment: $('#post_comment').val(), size: max_length, session_string: $('#session_string').val()}
|
62
|
+
for k, v of form.serializeObject()
|
63
|
+
params[k] = v
|
38
64
|
ws.send("JSON: " + JSON.stringify(params))
|
39
65
|
when 'OK Bye'
|
40
66
|
ws.close()
|
data/lib/nyoibo/version.rb
CHANGED
data/nyoibo.gemspec
CHANGED
@@ -23,4 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_dependency("json", "~>1.5.3")
|
24
24
|
s.add_development_dependency('em-http-request', '~> 0.2.6')
|
25
25
|
s.add_development_dependency('railties')
|
26
|
+
s.add_development_dependency('coffee-script')
|
27
|
+
s.add_development_dependency('sinatra')
|
28
|
+
s.add_development_dependency('sinatra-reloader')
|
26
29
|
end
|
data/test/example.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
require File.expand_path('../../app/helpers/nyoibo_helper', __FILE__)
|
3
|
+
require 'sinatra'
|
4
|
+
require 'sinatra/reloader'
|
5
|
+
require 'action_view'
|
6
|
+
require 'active_model'
|
7
|
+
require 'coffee-script'
|
8
|
+
include ActionView::Helpers::FormHelper
|
9
|
+
extend NyoiboHelper
|
10
|
+
|
11
|
+
class Post
|
12
|
+
extend ActiveModel::Naming
|
13
|
+
attr_accessor :file
|
14
|
+
|
15
|
+
include Nyoibo::Callback
|
16
|
+
uploaded "/" do |params, binary|
|
17
|
+
File.open('/tmp/test.jpg', 'w:binary') do |f|
|
18
|
+
f.write(binary)
|
19
|
+
end
|
20
|
+
|
21
|
+
File.open('/tmp/test.json', 'w:binary') do |f|
|
22
|
+
f.write(params)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
Nyoibo.configure do
|
27
|
+
host 'localhost'
|
28
|
+
port 3030
|
29
|
+
end
|
30
|
+
Process.fork do
|
31
|
+
Nyoibo.run
|
32
|
+
end
|
33
|
+
get '/' do
|
34
|
+
@post = Post.new
|
35
|
+
erubis <<EOS
|
36
|
+
<!DOCTYPE html>
|
37
|
+
<html>
|
38
|
+
<head>
|
39
|
+
<title>nyoibo</title>
|
40
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
|
41
|
+
<script>
|
42
|
+
#{File.read File.expand_path('../../vendor/html5jp/progress.js', __FILE__)}
|
43
|
+
</script>
|
44
|
+
<script>
|
45
|
+
#{CoffeeScript.compile(File.read(File.expand_path('../../lib/generators/nyoibo/templates/nyoibo.js.coffee', __FILE__)))}
|
46
|
+
</script>
|
47
|
+
</head>
|
48
|
+
<body>
|
49
|
+
|
50
|
+
|
51
|
+
<form id="ws-form">
|
52
|
+
<input type="file">
|
53
|
+
<input type="submit">
|
54
|
+
<input type="text" name="name" value="yalab">
|
55
|
+
</form>
|
56
|
+
<div id="ws-progress"></div>
|
57
|
+
</body>
|
58
|
+
EOS
|
59
|
+
|
60
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: nyoibo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- yalab
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-06 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: em-websocket
|
@@ -56,6 +56,39 @@ dependencies:
|
|
56
56
|
version: "0"
|
57
57
|
type: :development
|
58
58
|
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: coffee-script
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: sinatra
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: sinatra-reloader
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
type: :development
|
91
|
+
version_requirements: *id007
|
59
92
|
description: ""
|
60
93
|
email:
|
61
94
|
- rudeboyjet@gmail.com
|
@@ -83,6 +116,7 @@ files:
|
|
83
116
|
- lib/nyoibo/railtie.rb
|
84
117
|
- lib/nyoibo/version.rb
|
85
118
|
- nyoibo.gemspec
|
119
|
+
- test/example.rb
|
86
120
|
- test/fixtures/test.jpg
|
87
121
|
- test/test_helper.rb
|
88
122
|
- test/unit/callback_test.rb
|