impact 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +1 -0
- data/bin/impact +5 -0
- data/impact.gemspec +26 -0
- data/lib/impact.rb +8 -0
- data/lib/impact/cli.rb +22 -0
- data/lib/impact/server.rb +77 -0
- data/lib/impact/version.rb +5 -0
- data/spec/impact/server_spec.rb +38 -0
- data/spec/spec_helper.rb +23 -0
- metadata +118 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Piotr Murach
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Impact
|
2
|
+
[![Build Status](https://secure.travis-ci.org/peter-murach/impact.png?branch=master)][travis]
|
3
|
+
|
4
|
+
Ruby backend for Impact.js framework.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'impact'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install impact
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Change your game config paths to:
|
23
|
+
|
24
|
+
```javascript
|
25
|
+
'api': {
|
26
|
+
'save': 'lib/weltmeister/api/save',
|
27
|
+
'browse': 'lib/weltmeister/api/browse',
|
28
|
+
'glob': 'lib/weltmeister/api/glob'
|
29
|
+
}
|
30
|
+
```
|
31
|
+
|
32
|
+
And start up the server by running in the project directory:
|
33
|
+
|
34
|
+
```shell
|
35
|
+
impact
|
36
|
+
```
|
37
|
+
|
38
|
+
To see available server settings do:
|
39
|
+
|
40
|
+
```shell
|
41
|
+
impact -h
|
42
|
+
```
|
43
|
+
|
44
|
+
Visit the `localhost:4567` to see the game and `localhost:4567/weltmeister` to see level editor.
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/impact
ADDED
data/impact.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'impact/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "impact"
|
8
|
+
gem.version = Impact::VERSION
|
9
|
+
gem.authors = ["Piotr Murach"]
|
10
|
+
gem.email = [""]
|
11
|
+
gem.description = %q{Ruby backend for Impact.js framework}
|
12
|
+
gem.summary = %q{Ruby backend for Impact.js framework}
|
13
|
+
gem.homepage = "http://github.com/peter-murach/impact"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'sinatra'
|
21
|
+
gem.add_dependency 'json'
|
22
|
+
|
23
|
+
gem.add_development_dependency 'rspec'
|
24
|
+
gem.add_development_dependency 'rake'
|
25
|
+
gem.add_development_dependency 'yard'
|
26
|
+
end
|
data/lib/impact.rb
ADDED
data/lib/impact/cli.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Impact
|
4
|
+
class Server < Sinatra::Base
|
5
|
+
|
6
|
+
if ARGV.any?
|
7
|
+
require 'optparse'
|
8
|
+
|
9
|
+
OptionParser.new { |op|
|
10
|
+
op.on('-p port', 'set the port (default is 4567)') { |val| set :port, val.to_i }
|
11
|
+
op.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| set :bind, val }
|
12
|
+
op.on('-e env', 'set the environment (default is development)') { |val| set :environment, val.to_sym }
|
13
|
+
op.on('-s server', 'specify rack server/handler (default is thin)') { |val| set :server, val }
|
14
|
+
op.on('-r root', 'specify root directory (default is current)') { |val| set :root, val }
|
15
|
+
op.on('-x', 'turn on the mutex lock (default is off)') { set :lock, true }
|
16
|
+
}.parse!(ARGV.dup)
|
17
|
+
end
|
18
|
+
|
19
|
+
at_exit { Impact::Server.run! if $!.nil? }
|
20
|
+
|
21
|
+
end # Server
|
22
|
+
end # Impact
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'sinatra/base'
|
4
|
+
require 'pathname'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module Impact
|
8
|
+
class Server < Sinatra::Base
|
9
|
+
|
10
|
+
set :public_folder, File.join(Dir.pwd, '/')
|
11
|
+
|
12
|
+
set :static, true
|
13
|
+
|
14
|
+
set :root, File.join('./')
|
15
|
+
|
16
|
+
get '/' do
|
17
|
+
File.read('index.html')
|
18
|
+
end
|
19
|
+
|
20
|
+
get '/weltmeister' do
|
21
|
+
File.read('weltmeister.html')
|
22
|
+
end
|
23
|
+
|
24
|
+
get '/lib/weltmeister/api/glob' do
|
25
|
+
response = Dir.glob(params[:glob])
|
26
|
+
|
27
|
+
content_type :json
|
28
|
+
response.to_json
|
29
|
+
end
|
30
|
+
|
31
|
+
get '/lib/weltmeister/api/browse' do
|
32
|
+
response = { :dirs => [], :files => [], :parent => false }
|
33
|
+
dir = File.join(settings.root, params[:dir])
|
34
|
+
|
35
|
+
ext = "*." + case params[:type]
|
36
|
+
when 'images' then "{" + %w[png gif jpg jpeg bmp].join(', ') + "}"
|
37
|
+
when 'script' then "js"
|
38
|
+
else "*"
|
39
|
+
end
|
40
|
+
|
41
|
+
response[:parent] = Pathname.new(dir).parent if dir
|
42
|
+
|
43
|
+
dir += '/' unless dir.to_s[-1] == '/'
|
44
|
+
|
45
|
+
response[:files] = Dir.glob(File.join(dir, ext)).reject { |file| File.directory?(file) }
|
46
|
+
|
47
|
+
response[:dirs] = Dir.glob(File.join(dir, '*')).select { |file| File.directory?(file)}
|
48
|
+
|
49
|
+
content_type :json
|
50
|
+
response.to_json
|
51
|
+
end
|
52
|
+
|
53
|
+
post '/lib/weltmeister/api/save' do
|
54
|
+
response = { :error => 0 }
|
55
|
+
|
56
|
+
if params[:path] && params[:data]
|
57
|
+
dir = File.join(settings.root, params[:path])
|
58
|
+
|
59
|
+
if File.extname(dir) == ".js"
|
60
|
+
begin
|
61
|
+
File.open(dir, 'w') { |file| file.write(params[:data]) }
|
62
|
+
rescue => e
|
63
|
+
response.merge! :error => 2, :msg => "Couldn't write to file: #{e.message}"
|
64
|
+
end
|
65
|
+
else
|
66
|
+
response.merge! :error => 3, :msg => "File must have a .js suffix"
|
67
|
+
end
|
68
|
+
else
|
69
|
+
response.merge! :error => 1, :msg => "No Data or Path specified"
|
70
|
+
end
|
71
|
+
|
72
|
+
content_type :json
|
73
|
+
response.to_json
|
74
|
+
end
|
75
|
+
|
76
|
+
end # Server
|
77
|
+
end # Impact
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Impact::Server' do
|
4
|
+
|
5
|
+
context 'glob api' do
|
6
|
+
it 'finds files' do
|
7
|
+
response = ["lib/game/levels/*.js"]
|
8
|
+
Dir.should_receive(:glob).with(response).and_return response
|
9
|
+
get '/lib/weltmeister/api/glob?glob[]=lib%2Fgame%2Flevels%2F*.js'
|
10
|
+
last_response.body.should == response.to_json
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'browse api' do
|
15
|
+
let(:pwd) { './'}
|
16
|
+
let(:files) { ['./lib/game/levels/player.js'] }
|
17
|
+
let(:dirs) { ['./lib/tools', './lib/media', './lib/game'] }
|
18
|
+
|
19
|
+
before { File.stub(:join).and_return pwd }
|
20
|
+
|
21
|
+
it 'searches through directories' do
|
22
|
+
response = {
|
23
|
+
:parent => false,
|
24
|
+
:dirs => [],
|
25
|
+
:files => dirs
|
26
|
+
}
|
27
|
+
Pathname.stub_chain(:new, :parent).and_return false
|
28
|
+
Dir.stub(:glob).and_return dirs
|
29
|
+
get 'lib/weltmeister/api/browse?dir=&type=scripts'
|
30
|
+
last_response.body["files"].should == response.to_json["files"]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'save api' do
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'impact'
|
4
|
+
require 'rspec'
|
5
|
+
require 'rack/test'
|
6
|
+
|
7
|
+
module TestHelpers
|
8
|
+
def app
|
9
|
+
Impact::Server.class_eval {
|
10
|
+
set :environment, :test
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
17
|
+
config.run_all_when_everything_filtered = true
|
18
|
+
config.filter_run :focus
|
19
|
+
config.order = 'random'
|
20
|
+
|
21
|
+
config.include Rack::Test::Methods
|
22
|
+
config.include TestHelpers
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: impact
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Piotr Murach
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: &2156810840 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2156810840
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: json
|
27
|
+
requirement: &2156810300 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2156810300
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &2156809840 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2156809840
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &2156809340 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2156809340
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: yard
|
60
|
+
requirement: &2156808600 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2156808600
|
69
|
+
description: Ruby backend for Impact.js framework
|
70
|
+
email:
|
71
|
+
- ''
|
72
|
+
executables:
|
73
|
+
- impact
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/impact
|
84
|
+
- impact.gemspec
|
85
|
+
- lib/impact.rb
|
86
|
+
- lib/impact/cli.rb
|
87
|
+
- lib/impact/server.rb
|
88
|
+
- lib/impact/version.rb
|
89
|
+
- spec/impact/server_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: http://github.com/peter-murach/impact
|
92
|
+
licenses: []
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 1.8.10
|
112
|
+
signing_key:
|
113
|
+
specification_version: 3
|
114
|
+
summary: Ruby backend for Impact.js framework
|
115
|
+
test_files:
|
116
|
+
- spec/impact/server_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
has_rdoc:
|