socky-client-rails 0.4.3 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,16 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ## 0.4.5 / 2011-05-12
5
+
6
+ - support for Rails 3.1
7
+
8
+ ## 0.4.4 / 2011-03-22
9
+
10
+ - moved documentation to readme
11
+ - added gemspec to repo - bundler require that
12
+ - fix downloading scripts from repo
13
+
4
14
  ## 0.4.3 / 2010-11-05
5
15
 
6
16
  - new features:
data/README.md CHANGED
@@ -3,20 +3,91 @@ Socky - client bindings for Ruby on Rails
3
3
 
4
4
  Socky is push server for Ruby based on WebSockets. It allows you to break border between your application and client browser by letting the server initialize a connection and push data to the client.
5
5
 
6
- ## Getting Started
6
+ ## Example
7
7
 
8
- - [Install](http://github.com/socky/socky-client-rails/wiki/install) the gem
9
- - Read up about its [Usage](http://github.com/socky/socky-client-rails/wiki/usage), [Configuration](http://github.com/socky/socky-client-rails/wiki/configuration) and [Customizing JavaScript](http://github.com/socky/socky-js/wiki/Customizing-JavaScript)
10
- - Try [Example Application](http://github.com/socky/socky-example) or [demo page](http://sockydemo.imanel.org)
11
- - Fork and Contribute your own modifications
12
- - See [sites using socky](http://github.com/socky/socky-server-ruby/wiki/sites)
13
- - Discuss on [google group](http://groups.google.com/group/socky-framework)
8
+ You can try [live example](http://sockydemo.imanel.org) or view its [source code](http://github.com/socky/socky-example)
9
+
10
+ Also important information can be found on our [google group](http://groups.google.com/group/socky-users).
11
+
12
+ ## Install
13
+
14
+ The best way to install Socky Ruby on Rails bindings is via RubyGems:
15
+
16
+ gem install socky-client-rails
17
+
18
+ Socky Ruby on Rails bindings require the [socky-client](http://github.com/socky/socky-client-ruby) gem. It is automatically installed by the gem install command.
19
+
20
+ You can also build it after clonning(this will require Jeweler gem)
21
+
22
+ git clone git://github.com/socky/socky-client-rails.git
23
+ rake gemspec
24
+ rake build
25
+
26
+ ## Configuration
27
+
28
+ Configuration file is located in application config directory:
29
+
30
+ config/socky_hosts.yml
31
+
32
+ If it isn't exists then you will need to generate it. In Rails 3 you can use rake task:
33
+
34
+ rake socky:install
35
+
36
+ which also install Socky JS files.
37
+
38
+ If you are using Rails 2 then you will need to generate rake tasks first(this will be required only once):
39
+
40
+ script/generate socky
41
+
42
+ More about configuraton can be found in [socky-client-ruby](http://github.com/socky/socky-client-ruby).
43
+
44
+ ## Usage
45
+
46
+ ### View
47
+
48
+ Socky Ruby on Rails bindings provide `socky` helper for views and :socky javascript expansion.
49
+
50
+ At first you will need set of javascripts providing bridge between browser and WebSocket connection.
51
+
52
+ <%= javascript_include_tag :socky %>
53
+
54
+ This will also load javascripts that will use flash to simulate WebSocket if browser don't support it.
55
+
56
+ After that you can use @socky@ helper to create connection with Socky server.
57
+
58
+ <%= socky %>
59
+
60
+ Helper is accepting following options in hash form:
61
+
62
+ | *Option* | *Value format* | *Description* |
63
+ | -------------- | ------------------ | ------------- |
64
+ | `:host` | `[string]` | IP or hostname of Socky server - at default random server from socky_hosts.yml is taken
65
+ | `:port` | `[integer]` | Port on with Socky server listens - at default random server from socky_hosts.yml is taken
66
+ | `:user_id` | `[string/integer]` | Hash by with user will be identified
67
+ | `:user_secret` | `[string]` | Hash by with user will be authenticated
68
+ | `:channels` | `[array]` | List of channels to with user will be connected
69
+
70
+ ### Model and controller
71
+
72
+ Socky Ruby on Rails bindings offers all functionality of [socky-client-ruby](http://github.com/socky/socky-client-ruby) and additional method to send data via `Socky.send` command. You can use block of code and passed object will be standard Rails JavaScript generator.
73
+
74
+ Socky.send do |page|
75
+ page.alert('ok!')
76
+ end
77
+
78
+ Note that you can as usually use old methods and connect them with new method:
79
+
80
+ Socky.send :users => ["user1", "user2"] do |page|
81
+ page.alert('ok!')
82
+ end
83
+
84
+ Also note that if you use block version any data passed as body will be overwritten.
14
85
 
15
86
  ## License
16
87
 
17
88
  (The MIT License)
18
89
 
19
- Copyright (c) 2010 Bernard Potocki
90
+ Copyright (c) 2010 Bernard Potocki
20
91
 
21
92
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
22
93
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.4.5
@@ -1,27 +1,35 @@
1
+ require 'rails'
1
2
  require 'yaml'
2
3
  require 'socky-client'
3
- require File.dirname(__FILE__) + '/socky-client-rails/helper'
4
- require File.dirname(__FILE__) + '/socky-client-rails/java_script_generator'
5
4
  require 'socky-client-rails/railtie' if defined?(Rails::Railtie)
6
5
 
7
6
  module Socky
8
-
7
+ ROOT = File.expand_path(File.dirname(__FILE__))
8
+
9
+ autoload :Helper, "#{ROOT}/socky-client-rails/helper"
10
+ autoload :JavaScriptGenerator, "#{ROOT}/socky-client-rails/java_script_generator"
11
+
9
12
  class << self
10
13
 
11
14
  def config_path
12
15
  @config_path ||= Rails.root.join("config","socky_hosts.yml")
13
16
  end
14
17
 
15
- def send(data = nil, options = {}, &block)
16
- options = normalize_options(data, options)
17
- options[:data] = JavaScriptGenerator.new(&block).to_s unless block.nil?
18
- send_message(options.delete(:data), options)
19
- end
20
-
21
18
  def random_host
22
19
  hosts[rand(hosts.size)]
23
20
  end
24
21
 
22
+ # Javascript will not work in Rails >= 3.1 due to removing PrototypeHelper
23
+ unless Rails.version >= '3.1'
24
+ def send(data = nil, options = {}, &block)
25
+ options = normalize_options(data, options)
26
+ options[:data] = JavaScriptGenerator.new(&block).to_s unless block.nil?
27
+ send_message(options.delete(:data), options)
28
+ end
29
+ end
30
+
25
31
  end
32
+ end
26
33
 
27
- end
34
+ ActionView::Base.send(:include, Socky::Helper)
35
+ ActionView::Helpers::AssetTagHelper.register_javascript_expansion :socky => ['socky']
@@ -1,5 +1,3 @@
1
- require 'action_view'
2
-
3
1
  module Socky
4
2
  module Helper
5
3
 
@@ -14,6 +12,3 @@ module Socky
14
12
 
15
13
  end
16
14
  end
17
-
18
- ActionView::Base.send(:include, Socky::Helper)
19
- ActionView::Helpers::AssetTagHelper.register_javascript_expansion :socky => ['socky']
@@ -1,11 +1,16 @@
1
1
  require 'fileutils'
2
2
 
3
+ RAILS_ASSET_PATH = Rails.version >= '3.1' ? 'app/assets' : 'public'
4
+ RAILS_ASSET_URL = Rails.version >= '3.1' ? 'assets' : 'javascripts'
5
+
3
6
  SOCKY_JS_VERSION = File.read(File.dirname(__FILE__) + '/../../VERSION').strip.split('.')[0,2].join('.')
4
- SOCKY_JS_SERVER = 'https://github.com/socky/socky-js/raw'
5
- SOCKY_JS_DEST = Rails.root.join('public', 'javascripts').to_s
7
+ SOCKY_JS_SERVER = 'http://js.socky.org'
8
+ SOCKY_JS_DEST = Rails.root.join(RAILS_ASSET_PATH, 'javascripts').to_s
6
9
  SOCKY_JS_FILES = {
7
10
  'socky.js' => 'socky.js',
8
- 'WebSocketMain.swf' => 'socky/WebSocketMain.swf'
11
+ 'assets/flashfallback.js' => 'socky/flashfallback.js',
12
+ 'assets/json2.js' => 'socky/json2.js',
13
+ 'assets/WebSocketMain.swf' => 'socky/WebSocketMain.swf'
9
14
  }
10
15
 
11
16
  CONFIG_PATH = File.join(File.dirname(__FILE__), '..', '..', 'assets', 'socky_hosts.yml')
@@ -40,7 +45,7 @@ namespace :socky do
40
45
  puts 'Downloading files...'
41
46
  SOCKY_JS_FILES.each do |source, dest|
42
47
  begin
43
- uri = URI.parse(SOCKY_JS_SERVER + '/v' + SOCKY_JS_VERSION + '-stable/' + source)
48
+ uri = URI.parse(SOCKY_JS_SERVER + '/v' + SOCKY_JS_VERSION + '/' + source)
44
49
  file = File.join(SOCKY_JS_DEST, dest)
45
50
  puts ' + ' + dest
46
51
  FileUtils.mkdir_p(File.dirname(file))
@@ -58,7 +63,7 @@ namespace :socky do
58
63
  puts 'Updating assets info'
59
64
  text = File.read(script_file)
60
65
  open(script_file, 'wb') do |f|
61
- f.write text.gsub('WEB_SOCKET_SWF_LOCATION = "WebSocketMain.swf"', 'WEB_SOCKET_SWF_LOCATION = "/javascripts/socky/WebSocketMain.swf"')
66
+ f.write text.gsub(/SOCKY_ASSET_LOCATION = '(.+)';/, "SOCKY_ASSET_LOCATION = \"/#{RAILS_ASSET_URL}/socky\";")
62
67
  end
63
68
  end
64
69
  puts "Done"
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{socky-client-rails}
8
+ s.version = "0.4.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Bernard Potocki"]
12
+ s.date = %q{2011-05-12}
13
+ s.description = %q{Socky is a WebSocket server and client for Ruby}
14
+ s.email = %q{bernard.potocki@imanel.org}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "CHANGELOG.md",
20
+ "README.md",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "assets/socky_hosts.yml",
24
+ "generators/socky/socky_generator.rb",
25
+ "generators/socky/templates/socky.rake",
26
+ "init.rb",
27
+ "lib/socky-client-rails.rb",
28
+ "lib/socky-client-rails/helper.rb",
29
+ "lib/socky-client-rails/java_script_generator.rb",
30
+ "lib/socky-client-rails/railtie.rb",
31
+ "lib/tasks/socky-client-rails.rake",
32
+ "socky-client-rails.gemspec",
33
+ "spec/socky-client-rails_spec.rb",
34
+ "spec/spec_helper.rb",
35
+ "spec/support/config.rb",
36
+ "spec/support/config/socky_hosts.yml"
37
+ ]
38
+ s.homepage = %q{http://imanel.org/projects/socky}
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.6.1}
41
+ s.summary = %q{Socky is a WebSocket server and client for Ruby}
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<socky-client>, ["~> 0.4.2"])
48
+ s.add_development_dependency(%q<rspec>, ["~> 2.0"])
49
+ else
50
+ s.add_dependency(%q<socky-client>, ["~> 0.4.2"])
51
+ s.add_dependency(%q<rspec>, ["~> 2.0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<socky-client>, ["~> 0.4.2"])
55
+ s.add_dependency(%q<rspec>, ["~> 2.0"])
56
+ end
57
+ end
58
+
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socky-client-rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 4
9
- - 3
10
- version: 0.4.3
4
+ prerelease:
5
+ version: 0.4.5
11
6
  platform: ruby
12
7
  authors:
13
8
  - Bernard Potocki
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2010-11-04 00:00:00 +01:00
13
+ date: 2011-05-12 00:00:00 +02:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,11 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ~>
28
23
  - !ruby/object:Gem::Version
29
- hash: 11
30
- segments:
31
- - 0
32
- - 4
33
- - 2
34
24
  version: 0.4.2
35
25
  type: :runtime
36
26
  version_requirements: *id001
@@ -42,10 +32,6 @@ dependencies:
42
32
  requirements:
43
33
  - - ~>
44
34
  - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 2
48
- - 0
49
35
  version: "2.0"
50
36
  type: :development
51
37
  version_requirements: *id002
@@ -71,6 +57,7 @@ files:
71
57
  - lib/socky-client-rails/java_script_generator.rb
72
58
  - lib/socky-client-rails/railtie.rb
73
59
  - lib/tasks/socky-client-rails.rake
60
+ - socky-client-rails.gemspec
74
61
  - spec/socky-client-rails_spec.rb
75
62
  - spec/spec_helper.rb
76
63
  - spec/support/config.rb
@@ -80,8 +67,8 @@ homepage: http://imanel.org/projects/socky
80
67
  licenses: []
81
68
 
82
69
  post_install_message:
83
- rdoc_options:
84
- - --charset=UTF-8
70
+ rdoc_options: []
71
+
85
72
  require_paths:
86
73
  - lib
87
74
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -89,27 +76,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
76
  requirements:
90
77
  - - ">="
91
78
  - !ruby/object:Gem::Version
92
- hash: 3
93
- segments:
94
- - 0
95
79
  version: "0"
96
80
  required_rubygems_version: !ruby/object:Gem::Requirement
97
81
  none: false
98
82
  requirements:
99
83
  - - ">="
100
84
  - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
85
  version: "0"
105
86
  requirements: []
106
87
 
107
88
  rubyforge_project:
108
- rubygems_version: 1.3.7
89
+ rubygems_version: 1.6.1
109
90
  signing_key:
110
91
  specification_version: 3
111
92
  summary: Socky is a WebSocket server and client for Ruby
112
- test_files:
113
- - spec/socky-client-rails_spec.rb
114
- - spec/spec_helper.rb
115
- - spec/support/config.rb
93
+ test_files: []
94
+