swxruby 0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +21 -0
- data/LICENSE +20 -0
- data/README +143 -0
- data/Rakefile +111 -0
- data/bin/swxruby +58 -0
- data/examples/standalone/standalone.fla +0 -0
- data/examples/standalone/standalone.rb +37 -0
- data/examples/standalone/standalone.swf +0 -0
- data/init.rb +22 -0
- data/install.rb +69 -0
- data/lib/swxruby.rb +6 -0
- data/lib/swxruby/bytecode_converter.rb +139 -0
- data/lib/swxruby/core_extensions.rb +41 -0
- data/lib/swxruby/helper_module.rb +72 -0
- data/lib/swxruby/rails_integration/render_decorator.rb +20 -0
- data/lib/swxruby/rails_integration/swx.yml +18 -0
- data/lib/swxruby/rails_integration/swx_controller.rb +6 -0
- data/lib/swxruby/services/arithmetic.rb +9 -0
- data/lib/swxruby/services/discovery_service.rb +3 -0
- data/lib/swxruby/services/hello_world.rb +7 -0
- data/lib/swxruby/services/simple.rb +5 -0
- data/lib/swxruby/services/test_data_types.rb +94 -0
- data/lib/swxruby/swx_assembler.rb +138 -0
- data/lib/swxruby/swx_gateway.rb +104 -0
- data/lib/swxruby/version.rb +9 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/swxruby/bytecode_converter_spec.rb +162 -0
- data/spec/swxruby/core_extensions_spec.rb +16 -0
- data/spec/swxruby/fixtures/number_one_no_debug_compression_4.swx +0 -0
- data/spec/swxruby/fixtures/number_one_no_debug_no_compression.swx +0 -0
- data/spec/swxruby/fixtures/number_one_no_debug_no_compression_arbitrary_allow_domain.swx +0 -0
- data/spec/swxruby/fixtures/number_one_with_debug_compression_4.swx +0 -0
- data/spec/swxruby/fixtures/number_one_with_debug_no_compression.swx +0 -0
- data/spec/swxruby/rails_integration/init_spec.rb +0 -0
- data/spec/swxruby/rails_integration/render_decorator_spec.rb +73 -0
- data/spec/swxruby/rails_integration/swx_controller_spec.rb +5 -0
- data/spec/swxruby/swx_assembler_spec.rb +60 -0
- data/spec/swxruby/swx_gateway_spec.rb +160 -0
- metadata +108 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
== 0.7 2008-03-11
|
2
|
+
|
3
|
+
* 1 major enhancement:
|
4
|
+
* Gem Release
|
5
|
+
|
6
|
+
* 1 minor enhancement:
|
7
|
+
* Added handling of symbols
|
8
|
+
|
9
|
+
* Miscellaneous:
|
10
|
+
* Fleshed out README file quite a bit
|
11
|
+
|
12
|
+
== 0.5 2007-11-29
|
13
|
+
|
14
|
+
* 1 major enhancement:
|
15
|
+
* Rails controller integration (render :swx => @foo)
|
16
|
+
|
17
|
+
* 1 minor bugfix:
|
18
|
+
* Fixed handling of nil values in hash to bytecode conversion
|
19
|
+
|
20
|
+
* Miscellaneous:
|
21
|
+
* Added CHANGELOG, LICENSE, and README files
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Jed Hurt
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
= SWX Ruby 0.7
|
2
|
+
|
3
|
+
Primary Repo: http://github.com/meekish/swxruby
|
4
|
+
|
5
|
+
=== What is SWX?
|
6
|
+
|
7
|
+
SWX is the native data format for the Flash Platform.
|
8
|
+
|
9
|
+
SWX RPC is a remote procedure call protocol encoded in SWX and a viable alternative to XML and Flash Remoting. It's simple enough that you can get up and running with it in about five minutes. SWX RPC is perfect for building mashups (with easy-to-use APIs for Flickr, Twitter, and others), mobile applications (Flash Lite 2.0 and 2.1), and other data-driven Flash sites and applications. Official web site at http://swxformat.org
|
10
|
+
|
11
|
+
=== What is SWX Ruby?
|
12
|
+
|
13
|
+
SWX Ruby is the Ruby implementation of SWX RPC. It allows Rubyists to leverage their Ruby skills to build data-driven Flash applications using the wonderfully simple SWX data format. The current beta version assembles AVM1 SWF files (compatible with Flash 8 and below). By its 1.0 release, SWX Ruby will also assemble AVM2 SWF files. Official web site at http://swxruby.org
|
14
|
+
|
15
|
+
=== Installation
|
16
|
+
|
17
|
+
==== Gem
|
18
|
+
|
19
|
+
gem install swxruby
|
20
|
+
|
21
|
+
Note: The SWX Ruby gem declares 'json_pure' as a dependency. json_pure
|
22
|
+
is the pure Ruby variant of the JSON gem. If you have a C compiler and
|
23
|
+
would like better performance then do 'gem install json'
|
24
|
+
|
25
|
+
==== Rails plugin
|
26
|
+
|
27
|
+
After installing the gem, do:
|
28
|
+
|
29
|
+
swxruby --rails PATH_TO_ROOT_OF_YOUR_RAILS_APP
|
30
|
+
|
31
|
+
This will unpack a plugin into your Rails app. For further explanation of the files installed, see 'Rails Usage' below.
|
32
|
+
|
33
|
+
<b>Living on the Edge:</b> The Rails init script (init.rb) sits in the root of the SWX Ruby tree, thus you can simply throw the git HEAD into vendor/plugins/swxruby to run the plugin on edge
|
34
|
+
|
35
|
+
git clone git://github.com/meekish/swxruby.git vendor/plugins/swxruby
|
36
|
+
ruby vendor/plugins/swxruby/install.rb
|
37
|
+
|
38
|
+
=== Gem Usage (For Merb, Camping, Sinatra, et al.)
|
39
|
+
|
40
|
+
Require the SWX Ruby gem
|
41
|
+
|
42
|
+
require 'rubygems'
|
43
|
+
require 'swxruby'
|
44
|
+
|
45
|
+
Define a service class in the SwxServiceClasses namespace
|
46
|
+
|
47
|
+
module SwxServiceClasses
|
48
|
+
class Simple
|
49
|
+
def echo_data(data)
|
50
|
+
data
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Start making calls to SwxGateway#process
|
56
|
+
|
57
|
+
@swx_bytecode = SwxGateway.process(:serviceClass => 'Simple', :method => 'echo_data', :args => 'Hello World!', :debug => true)
|
58
|
+
# => Returns a binary string of SWX bytecode containing the result of SwxServiceClasses::Simple.new.echo_data('Hello World!')
|
59
|
+
|
60
|
+
Use your framework's preferred method to wrap the swx bytecode in a file shell and send it on its way. Here's how Rails and Merb do it:
|
61
|
+
|
62
|
+
send_data(@swx_bytecode, :filename => 'data.swf', :type => 'application/swf')
|
63
|
+
|
64
|
+
==== Example of Gem Usage
|
65
|
+
|
66
|
+
Here's a full Merb app (this and a Flash client are included in examples/standalone/)
|
67
|
+
|
68
|
+
# standalone.rb
|
69
|
+
|
70
|
+
require 'rubygems'
|
71
|
+
require 'swxruby'
|
72
|
+
|
73
|
+
# Service Class
|
74
|
+
class SwxServiceClasses::HelloMerb
|
75
|
+
def just_say_the_words
|
76
|
+
'Hello from Merb!'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Merb Application
|
81
|
+
Merb::Router.prepare { |r| r.match('/').to(:controller => 'swx_ruby', :action =>'gateway') }
|
82
|
+
|
83
|
+
class SwxRuby < Merb::Controller
|
84
|
+
def gateway
|
85
|
+
send_data(SwxGateway.process(params), :filename => 'data.swf', :type => 'application/swf')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Start with 'merb -I standalone.rb' and you're off!
|
90
|
+
|
91
|
+
=== Rails Plugin Usage
|
92
|
+
|
93
|
+
When running as a Rails plugin, SWX Ruby will look for your service classes in
|
94
|
+
RAILS_ROOT/app/services. Simply create standard Ruby classes and drop them
|
95
|
+
in this folder. SWX Ruby will instantiate your service class (while forcing
|
96
|
+
it into the SwxServiceClasses namespace), call the specified method, and
|
97
|
+
send the response back to the Flash Player.
|
98
|
+
|
99
|
+
Take a peek at services/hello_world.rb for a working service class example.
|
100
|
+
Alright, alright, I'll just show it to you here:
|
101
|
+
|
102
|
+
# hello_world.rb----------------------------------------
|
103
|
+
# Class and method names follow standard Ruby convention
|
104
|
+
class HelloWorld
|
105
|
+
# Service class methods are instance methods.
|
106
|
+
def just_say_the_words
|
107
|
+
'Hello World!'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
#-------------------------------------------------------
|
111
|
+
|
112
|
+
Here's an example to call HelloWorld#just_say_the_words from Flash
|
113
|
+
(place a MovieClip on stage with an instance name of 'loader' and
|
114
|
+
fire up your Rails development server):
|
115
|
+
|
116
|
+
//------------------------------------------------------
|
117
|
+
loader.serviceClass = "HelloWorld";
|
118
|
+
// Method names follow ActionScript convention
|
119
|
+
// (converted to underscored server-side)
|
120
|
+
loader.method = "justSayTheWords";
|
121
|
+
loader.debug = true;
|
122
|
+
loader.loadMovie("http://localhost:3000/swx", "POST");
|
123
|
+
|
124
|
+
function onEnterFrame() {
|
125
|
+
// Will output 'Hello World!' once the SWX file is loaded.
|
126
|
+
trace(loader.result);
|
127
|
+
}
|
128
|
+
//------------------------------------------------------
|
129
|
+
|
130
|
+
When you're ready for some robust ActionScriptery, head to
|
131
|
+
http://swxformat.org/download to grab the SWX ActionScript library.
|
132
|
+
|
133
|
+
Oh yeah, you may return ActiveRecord objects from your service classes;
|
134
|
+
SWX Ruby will happily serialize them for you. Go ahead, give it a try!
|
135
|
+
|
136
|
+
NOTE: You may notice some Security Sandbox Violations when testing the example
|
137
|
+
above in the Flash IDE. Rest assured, this is OK. Visit
|
138
|
+
http://swxformat.org/132 for further explanation.
|
139
|
+
|
140
|
+
=== Get In Touch
|
141
|
+
|
142
|
+
Please post bug reports/suggestions to http://groups.google.com/group/swxruby
|
143
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
require './lib/swxruby'
|
7
|
+
|
8
|
+
NAME = 'swxruby'
|
9
|
+
SUDO = 'sudo'
|
10
|
+
|
11
|
+
task :release do
|
12
|
+
sh("rubyforge add_release 4428 5478 #{SwxRuby::VERSION} ./pkg/swxruby-#{SwxRuby::VERSION}.gem")
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
# ==============================
|
17
|
+
# = Packaging and Installation =
|
18
|
+
# ==============================
|
19
|
+
CLEAN.include ["**/.*.swf", "pkg", "*.gem", "doc"]
|
20
|
+
|
21
|
+
spec = Gem::Specification.new do |s|
|
22
|
+
s.name = NAME
|
23
|
+
s.rubyforge_project = NAME
|
24
|
+
s.version = SwxRuby::VERSION
|
25
|
+
s.author = 'Jed Hurt'
|
26
|
+
s.email = 'jed.hurt@gmail.com'
|
27
|
+
s.homepage = 'http://swxruby.org'
|
28
|
+
s.summary = 'SWX Ruby: The Ruby Implementation of SWX RPC'
|
29
|
+
s.bindir = 'bin'
|
30
|
+
s.description = s.summary
|
31
|
+
s.executables = %w( swxruby )
|
32
|
+
s.require_path = 'lib'
|
33
|
+
s.files = %w( LICENSE README Rakefile CHANGELOG init.rb install.rb ) + Dir["{bin,spec,lib,examples}/**/*"]
|
34
|
+
|
35
|
+
# rdoc
|
36
|
+
s.has_rdoc = true
|
37
|
+
s.extra_rdoc_files = %w( README LICENSE CHANGELOG )
|
38
|
+
#s.rdoc_options += RDOC_OPTS + ["--exclude", "^(app|uploads)"]
|
39
|
+
|
40
|
+
# Dependencies
|
41
|
+
s.add_dependency "json_pure"
|
42
|
+
# Requirements
|
43
|
+
s.requirements << "install the json gem to get faster json parsing"
|
44
|
+
s.required_ruby_version = ">= 1.8.4"
|
45
|
+
end
|
46
|
+
|
47
|
+
Rake::GemPackageTask.new(spec) do |package|
|
48
|
+
package.gem_spec = spec
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'Run :package and install the resulting .gem'
|
52
|
+
task :install => :package do
|
53
|
+
sh %{#{SUDO} gem install --local pkg/#{NAME}-#{SwxRuby::VERSION}.gem --no-rdoc --no-ri}
|
54
|
+
end
|
55
|
+
|
56
|
+
desc 'Run :clean and uninstall the .gem'
|
57
|
+
task :uninstall => :clean do
|
58
|
+
sh %{#{SUDO} gem uninstall #{NAME}}
|
59
|
+
end
|
60
|
+
|
61
|
+
# ==================
|
62
|
+
# = Documentation =
|
63
|
+
# ==================
|
64
|
+
Rake::RDocTask.new(:rdoc) do |rd|
|
65
|
+
rd.main = 'README' # 'name' will be the initial page displayed
|
66
|
+
rd.rdoc_dir = 'doc' # set the output directory
|
67
|
+
rd.rdoc_files.add(['README', 'LICENSE', 'CHANGELOG', 'lib/**/*.rb', 'examples/**/*.rb']) # List of files to include in the rdoc generation
|
68
|
+
rd.title = 'SWX Ruby: The Ruby Implementation of SWX RPC' # Title of the RDoc documentation
|
69
|
+
rd.options << '--inline-source' # Show method source code inline, rather than via a popup link
|
70
|
+
rd.options << '--line-numbers' # Include line numbers in the source code
|
71
|
+
# rd.template = "html" # Name of the template to be used by rdoc
|
72
|
+
# rd.options << "--accessor accessorname[,..]" # comma separated list of additional class methods that should be treated like 'attr_reader' and friends.
|
73
|
+
# rd.options << "--all" # include all methods (not just public) in the output
|
74
|
+
# rd.options << "--charset charset" # specifies HTML character-set
|
75
|
+
# rd.options << "--debug" # displays lots on internal stuff
|
76
|
+
# rd.options << "--diagram" # Generate diagrams showing modules and classes using dot.
|
77
|
+
# rd.options << "--exclude pattern" # do not process files or directories matching pattern unless they're explicitly included
|
78
|
+
# rd.options << "--extension new=old" # Treat files ending with .new as if they ended with .old
|
79
|
+
# rd.options << "--fileboxes" # classes are put in boxes which represents files, where these classes reside.
|
80
|
+
# rd.options << "--force-update" # forces to scan all sources even if newer than the flag file.
|
81
|
+
# rd.options << "--fmt format name" # set the output formatter (html, chm, ri, xml)
|
82
|
+
# rd.options << "--image-format gif/png/jpg/jpeg" # Sets output image format for diagrams. Default is png.
|
83
|
+
# rd.options << "--include dir[,dir...]" # set (or add to) the list of directories to be searched.
|
84
|
+
# rd.options << "--merge" # when creating ri output, merge processed classes into previously documented classes of the name name
|
85
|
+
# rd.options << "--one-file" # put all the output into a single file
|
86
|
+
# rd.options << "--opname name" # Set the 'name' of the output. Has no effect for HTML format.
|
87
|
+
# rd.options << "--promiscuous" # Show module/class in the files page.
|
88
|
+
# rd.options << "--quiet" # don't show progress as we parse
|
89
|
+
# rd.options << "--ri" # generate output for use by 'ri.' local
|
90
|
+
# rd.options << "--ri-site" # generate output for use by 'ri.' sitewide
|
91
|
+
# rd.options << "--ri-system" # generate output for use by 'ri.' system wide, for Ruby installs.
|
92
|
+
# rd.options << "--show-hash" # A name of the form #name in a comment is a possible hyperlink to an instance method name. When displayed, the '#' is removed unless this option is specified
|
93
|
+
# rd.options << "--style stylesheet url" # specifies the URL of a separate stylesheet.
|
94
|
+
# rd.options << "--tab-width n" # Set the width of tab characters (default 8)
|
95
|
+
# rd.options << "--webcvs url" # Specify a URL for linking to a web frontend to CVS.
|
96
|
+
end
|
97
|
+
|
98
|
+
desc 'Sync docs at swxruby.org'
|
99
|
+
task :sync_docs => :rdoc do
|
100
|
+
sh('rsync -avz ./doc/* meekish@swxruby.org:/var/www/www.swxruby.org/web/docs/')
|
101
|
+
end
|
102
|
+
|
103
|
+
# =========
|
104
|
+
# = Specs =
|
105
|
+
# =========
|
106
|
+
desc 'Run all specs'
|
107
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
108
|
+
t.spec_opts = ['--format', 'specdoc', '--colour']
|
109
|
+
# t.libs = ["lib", "server/lib" ]
|
110
|
+
t.spec_files = Dir['spec/**/*_spec.rb'].sort
|
111
|
+
end
|
data/bin/swxruby
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
rescue LoadError
|
6
|
+
# no rubygems to load, so we fail silently
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
OPTIONS = {}
|
12
|
+
MANDATORY_OPTIONS = %w(rails_dir)
|
13
|
+
|
14
|
+
parser = OptionParser.new do |opts|
|
15
|
+
opts.banner = <<BANNER
|
16
|
+
Usage: #{File.basename($0)} [options]
|
17
|
+
|
18
|
+
Description:
|
19
|
+
This script will install the SWX Ruby Rails plugin in your Rails application.
|
20
|
+
|
21
|
+
Options are:
|
22
|
+
BANNER
|
23
|
+
opts.separator ""
|
24
|
+
opts.on('--rails RAILS_DIR',
|
25
|
+
"The root of your Rails application") { |rails_dir| OPTIONS[:rails_dir] = rails_dir }
|
26
|
+
opts.on('--essentials',
|
27
|
+
"Don't unpack example service classes") { OPTIONS[:essentials] = true }
|
28
|
+
opts.on("-h", "--help",
|
29
|
+
"Show this help message.") { puts opts; exit }
|
30
|
+
opts.parse!(ARGV)
|
31
|
+
|
32
|
+
if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
|
33
|
+
puts opts; exit
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# =====================================
|
39
|
+
# = Install the SWX Ruby Rails plugin =
|
40
|
+
# =====================================
|
41
|
+
require 'fileutils'
|
42
|
+
include FileUtils
|
43
|
+
|
44
|
+
RAILS_ROOT = File.expand_path(OPTIONS[:rails_dir])
|
45
|
+
SWX_RUBY_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
46
|
+
|
47
|
+
unless File.exist?("#{RAILS_ROOT}/vendor/plugins/swxruby")
|
48
|
+
puts '*** Creating vendor/plugins/swxruby directory ***'
|
49
|
+
mkdir("#{RAILS_ROOT}/vendor/plugins/swxruby")
|
50
|
+
end
|
51
|
+
|
52
|
+
unless File.exist?("#{RAILS_ROOT}/vendor/plugins/swxruby/init.rb")
|
53
|
+
puts '*** Copying initialisation file to vendor/plugins/swxruby/init.rb ***'
|
54
|
+
cp(File.join(SWX_RUBY_ROOT, 'init.rb'), "#{RAILS_ROOT}/vendor/plugins/swxruby/init.rb")
|
55
|
+
end
|
56
|
+
|
57
|
+
ESSENTIALS = OPTIONS[:essentials]
|
58
|
+
require File.join(SWX_RUBY_ROOT, 'install.rb')
|
Binary file
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# = Merb Standalone SWX Ruby Server
|
2
|
+
#
|
3
|
+
# An example of how simple it is to build a standalone SWX Ruby server using Merb.
|
4
|
+
#
|
5
|
+
# == Prerequisites
|
6
|
+
#
|
7
|
+
# * SWX Ruby Gem (gem install swxruby)
|
8
|
+
# * merb-core 0.9.1 or later (gem install merb-core)
|
9
|
+
#
|
10
|
+
# == Take it for a spin
|
11
|
+
#
|
12
|
+
# * Open a terminal in the examples/standalone directory and execute 'merb -I standalone.rb' to fire up the Merb server.
|
13
|
+
# * Open standalone.fla in Flash 8 or later.
|
14
|
+
# * Publish Preview (ctrl+enter on Windows; cmd+enter on OS X).
|
15
|
+
# * Watch as the output panel begins tracing "Hello from Merb!".
|
16
|
+
require 'rubygems'
|
17
|
+
require 'swxruby'
|
18
|
+
|
19
|
+
# =================
|
20
|
+
# = Service Class =
|
21
|
+
# =================
|
22
|
+
class SwxServiceClasses::HelloMerb
|
23
|
+
def just_say_the_words
|
24
|
+
'Hello from Merb!'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# ====================
|
29
|
+
# = Merb Application =
|
30
|
+
# ====================
|
31
|
+
Merb::Router.prepare { |r| r.match('/').to(:controller => 'swx_ruby_controller', :action =>'gateway') }
|
32
|
+
|
33
|
+
class SwxRubyController < Merb::Controller
|
34
|
+
def gateway
|
35
|
+
send_data(SwxGateway.process(params), :filename => 'data.swf', :type => 'application/swf')
|
36
|
+
end
|
37
|
+
end
|
Binary file
|
data/init.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
begin
|
2
|
+
require 'rubygems'
|
3
|
+
require 'swxruby'
|
4
|
+
rescue
|
5
|
+
# If the swxruby gem isn't installed, assume this plugin installation is
|
6
|
+
# running from a checkout of trunk and fail silently.
|
7
|
+
end
|
8
|
+
require 'swx_gateway'
|
9
|
+
require 'yaml'
|
10
|
+
|
11
|
+
# Tell SwxGateway where app root and config file are located
|
12
|
+
SwxGateway.app_root = RAILS_ROOT
|
13
|
+
SwxGateway.swx_config = YAML.load_file(File.join(RAILS_ROOT, 'config', 'swx.yml'))
|
14
|
+
|
15
|
+
# Load the service classes
|
16
|
+
SwxGateway.init_service_classes
|
17
|
+
|
18
|
+
# Initialize Rails controller integration (render :swx => 'my data')
|
19
|
+
require 'rails_integration/render_decorator'
|
20
|
+
|
21
|
+
# Register the SWX mime tytpe
|
22
|
+
Mime::Type.register "application/swf", :swx
|
data/install.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Taken from Railties
|
2
|
+
def gsub_file(relative_destination, regexp, *args, &block)
|
3
|
+
path = relative_destination
|
4
|
+
content = File.read(path).gsub(regexp, *args, &block)
|
5
|
+
File.open(path, 'wb') { |file| file.write(content) }
|
6
|
+
end
|
7
|
+
|
8
|
+
SWX_RUBY_ROOT ||= File.expand_path(File.dirname(__FILE__))
|
9
|
+
readme = IO.readlines(File.join(SWX_RUBY_ROOT, 'README'))
|
10
|
+
@rails_usage = readme.slice(readme.index("=== Rails Plugin Usage\n")..-1)
|
11
|
+
|
12
|
+
begin
|
13
|
+
require 'fileutils'
|
14
|
+
include FileUtils
|
15
|
+
|
16
|
+
# Copy config file
|
17
|
+
unless File.exist?("#{RAILS_ROOT}/config/swx.yml")
|
18
|
+
puts '*** Copying config file to config/swx.yml ***'
|
19
|
+
cp(File.join(SWX_RUBY_ROOT, 'lib', 'swxruby', 'rails_integration', 'swx.yml'), "#{RAILS_ROOT}/config/swx.yml")
|
20
|
+
end
|
21
|
+
|
22
|
+
# Copy SWX controller
|
23
|
+
unless File.exist?("#{RAILS_ROOT}/app/controllers/swx_controller.rb")
|
24
|
+
puts '*** Copying SWX controller to app/controllers/swx_controller.rb ***'
|
25
|
+
cp(File.join(SWX_RUBY_ROOT, 'lib', 'swxruby', 'rails_integration', 'swx_controller.rb'), "#{RAILS_ROOT}/app/controllers/swx_controller.rb")
|
26
|
+
end
|
27
|
+
|
28
|
+
# Create services directory
|
29
|
+
unless File.exist?("#{RAILS_ROOT}/app/services")
|
30
|
+
puts '*** Creating services directory at app/services ***'
|
31
|
+
mkdir("#{RAILS_ROOT}/app/services")
|
32
|
+
end
|
33
|
+
|
34
|
+
unless ESSENTIALS
|
35
|
+
# Copy TestDataTypes class to app/services
|
36
|
+
unless File.exist?("#{RAILS_ROOT}/app/services/test_data_types.rb")
|
37
|
+
puts '*** Copying TestDataTypes service class to app/services ***'
|
38
|
+
cp(File.join(SWX_RUBY_ROOT, 'lib', 'swxruby', 'services', 'test_data_types.rb'), "#{RAILS_ROOT}/app/services/test_data_types.rb")
|
39
|
+
end
|
40
|
+
|
41
|
+
# Copy HelloWorld class to app/services
|
42
|
+
unless File.exist?("#{RAILS_ROOT}/app/services/hello_world.rb")
|
43
|
+
puts '*** Copying HelloWorld service class to app/services ***'
|
44
|
+
cp(File.join(SWX_RUBY_ROOT, 'lib', 'swxruby', 'services', 'hello_world.rb'), "#{RAILS_ROOT}/app/services/hello_world.rb")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Add route for SWX gateway to routes.rb
|
49
|
+
puts '*** Adding route for SWX gateway to routes.rb ***'
|
50
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
51
|
+
gsub_file "#{RAILS_ROOT}/config/routes.rb", /(#{Regexp.escape(sentinel)})/mi do |match|
|
52
|
+
"#{match}\n map.swx '/swx', :controller => 'swx', :action => 'gateway'\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
# Check for installation of JSON gem
|
56
|
+
print '*** Checking if JSON gem is installed'
|
57
|
+
require 'rubygems'
|
58
|
+
require 'json'
|
59
|
+
puts ': JSON gem detected ***'
|
60
|
+
|
61
|
+
puts @rails_usage
|
62
|
+
rescue LoadError
|
63
|
+
puts @rails_usage
|
64
|
+
|
65
|
+
puts '!!!!! You do not have the JSON gem installed. SWX Ruby will not function without it.'
|
66
|
+
puts '!!!!! Please "gem install json" to get the JSON gem, then SWX Ruby should be ready to roll.'
|
67
|
+
rescue Exception => e
|
68
|
+
puts 'ERROR INSTALLING SWX Ruby: ' + e.message
|
69
|
+
end
|