wandbox 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +192 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/wandbox +7 -0
- data/lib/wandbox.rb +22 -0
- data/lib/wandbox/cli.rb +15 -0
- data/lib/wandbox/cli/cli.rb +27 -0
- data/lib/wandbox/cli/compiler.rb +19 -0
- data/lib/wandbox/cli/compiler_list.rb +24 -0
- data/lib/wandbox/cli/run.rb +61 -0
- data/lib/wandbox/compiler.rb +70 -0
- data/lib/wandbox/converter.rb +62 -0
- data/lib/wandbox/list.rb +39 -0
- data/lib/wandbox/version.rb +3 -0
- data/lib/wandbox/web.rb +42 -0
- data/wandbox.gemspec +27 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e518c86bb13c805d640cc3a4d950db78efe38b47
|
4
|
+
data.tar.gz: cc964f90a52475b52d690490f9b36176fc1583c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fc0fd9dd6bd5ce3f8741d8aa44f365130b1d33c7512b0ce82b0dc4b58c5286a4009feb4cb264502643bdb3f1ca7e064f5c95cc9167ff0ce0b396364971149adf
|
7
|
+
data.tar.gz: 424226aa5b1557b1d1c82328ea01b3ec924f0eac70959166ce18dea4a7424c2ae492bffcfbec6d5b16bc061b9542c3663c27ebabdf67decd3291a589f5f986fd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
# Wandbox
|
2
|
+
|
3
|
+
Run Wandbox(http://melpon.org/wandbox/) in CLI.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'wandbox'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install wandbox
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```shell
|
24
|
+
$ cat test.rb
|
25
|
+
5.times.each { |n|
|
26
|
+
puts n
|
27
|
+
}
|
28
|
+
$ wandbox run test.rb
|
29
|
+
0
|
30
|
+
1
|
31
|
+
2
|
32
|
+
3
|
33
|
+
4
|
34
|
+
```
|
35
|
+
|
36
|
+
#### Using Boost in C++
|
37
|
+
|
38
|
+
Using `--options` option.
|
39
|
+
|
40
|
+
```shell
|
41
|
+
$ cat test.cpp
|
42
|
+
#include <boost/config.hpp>
|
43
|
+
#include <iostream>
|
44
|
+
|
45
|
+
int
|
46
|
+
main(){
|
47
|
+
std::cout << BOOST_COMPILER << std::endl;
|
48
|
+
return 0;
|
49
|
+
}
|
50
|
+
$ wandbox run test.cpp --options="boost-1.58"
|
51
|
+
GNU C++ version 6.0.0 20150711 (experimental)
|
52
|
+
```
|
53
|
+
|
54
|
+
#### Using Clang Compiler
|
55
|
+
|
56
|
+
Using `--compiler` option.
|
57
|
+
|
58
|
+
```shell
|
59
|
+
$ cat test.cpp
|
60
|
+
#include <iostream>
|
61
|
+
|
62
|
+
int
|
63
|
+
main(){
|
64
|
+
std::cout << __VERSION__ << std::endl;
|
65
|
+
return 0;
|
66
|
+
}
|
67
|
+
$ wandbox run test.cpp --compiler=clang-head
|
68
|
+
4.2.1 Compatible Clang 3.7.0 (trunk 241983)
|
69
|
+
```
|
70
|
+
|
71
|
+
#### Run multiple source files.
|
72
|
+
|
73
|
+
```shell
|
74
|
+
$ cat prog.rb
|
75
|
+
require_relative "./test"
|
76
|
+
|
77
|
+
puts X.method
|
78
|
+
$ cat test.rb
|
79
|
+
module X
|
80
|
+
def self.method
|
81
|
+
"X.method"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
$ wandbox run prog.rb test.rb
|
85
|
+
X.method
|
86
|
+
```
|
87
|
+
|
88
|
+
#### Save source code in Wandbox
|
89
|
+
|
90
|
+
Using `--save` option.
|
91
|
+
|
92
|
+
```shell
|
93
|
+
$ wandbox run prog.rb --save
|
94
|
+
http://melpon.org/wandbox/permlink/rCVQCfbdmsqGXaO7
|
95
|
+
hello world
|
96
|
+
```
|
97
|
+
|
98
|
+
#### Output compiler list
|
99
|
+
|
100
|
+
Using `compiler-list` in sub command.
|
101
|
+
|
102
|
+
```shell
|
103
|
+
$ wandbox compiler-list
|
104
|
+
Compiler list:
|
105
|
+
gcc-head
|
106
|
+
gcc-5.1.0
|
107
|
+
gcc-4.9.2
|
108
|
+
gcc-4.9.1
|
109
|
+
gcc-4.9.0
|
110
|
+
gcc-4.8.2
|
111
|
+
gcc-4.8.1
|
112
|
+
gcc-4.7.3
|
113
|
+
gcc-4.6.4
|
114
|
+
gcc-4.5.4
|
115
|
+
gcc-4.4.7
|
116
|
+
gcc-4.3.6
|
117
|
+
clang-head
|
118
|
+
clang-3.6
|
119
|
+
clang-3.5
|
120
|
+
clang-3.4
|
121
|
+
clang-3.3
|
122
|
+
clang-3.2
|
123
|
+
clang-3.1
|
124
|
+
clang-3.0
|
125
|
+
...
|
126
|
+
```
|
127
|
+
|
128
|
+
#### Output compiler options
|
129
|
+
|
130
|
+
```shell
|
131
|
+
$ wandbox compiler gcc-head --options="warning,c++11"
|
132
|
+
[Compiler]:
|
133
|
+
gcc HEAD
|
134
|
+
|
135
|
+
[Language]:
|
136
|
+
C++
|
137
|
+
|
138
|
+
[Version]:
|
139
|
+
6.0.0 20150718 (experimental)
|
140
|
+
|
141
|
+
[Compiler command]:
|
142
|
+
$ g++ prog.cc -Wall -Wextra -std=c++11
|
143
|
+
|
144
|
+
[Option list]:
|
145
|
+
boost-1.47 : -I/usr/local/boost-1.47.0/include
|
146
|
+
boost-1.48 : -I/usr/local/boost-1.48.0/include
|
147
|
+
boost-1.49 : -I/usr/local/boost-1.49.0/include
|
148
|
+
boost-1.50 : -I/usr/local/boost-1.50.0/include
|
149
|
+
boost-1.51 : -I/usr/local/boost-1.51.0/include
|
150
|
+
boost-1.52 : -I/usr/local/boost-1.52.0/include
|
151
|
+
boost-1.53 : -I/usr/local/boost-1.53.0/include
|
152
|
+
boost-1.54 : -I/usr/local/boost-1.54.0/include
|
153
|
+
boost-1.55 : -I/usr/local/boost-1.55.0/include
|
154
|
+
boost-1.56 : -I/usr/local/boost-1.56.0/include
|
155
|
+
boost-1.57 : -I/usr/local/boost-1.57.0/include
|
156
|
+
boost-1.58 : -I/usr/local/boost-1.58.0/include
|
157
|
+
c++11 : -std=c++11
|
158
|
+
c++14 : -std=c++14
|
159
|
+
c++1z : -std=c++1z
|
160
|
+
c++98 : -std=c++98
|
161
|
+
cpp-pedantic : -pedantic
|
162
|
+
cpp-pedantic-errors : -pedantic-errors
|
163
|
+
cpp-verbose : -v
|
164
|
+
gnu++11 : -std=gnu++11
|
165
|
+
gnu++14 : -std=gnu++14
|
166
|
+
gnu++1z : -std=gnu++1z
|
167
|
+
gnu++98 : -std=gnu++98
|
168
|
+
optimize : -O2 -march=native
|
169
|
+
sprout : -I/usr/local/sprout
|
170
|
+
warning : -Wall -Wextra
|
171
|
+
```
|
172
|
+
|
173
|
+
|
174
|
+
## Development
|
175
|
+
|
176
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec wandbox` to use the code located in this directory, ignoring other installed copies of this gem.
|
177
|
+
|
178
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
179
|
+
|
180
|
+
## Contributing
|
181
|
+
|
182
|
+
1. Fork it ( https://github.com/osyo-manga/gem-wandbox/fork )
|
183
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
184
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
185
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
186
|
+
5. Create a new Pull Request
|
187
|
+
|
188
|
+
## Release note
|
189
|
+
|
190
|
+
* 0.1.0
|
191
|
+
* Release!!
|
192
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "wandbox"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/wandbox
ADDED
data/lib/wandbox.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
require "wandbox/version"
|
3
|
+
require "wandbox/list"
|
4
|
+
require "wandbox/web"
|
5
|
+
require "wandbox/converter"
|
6
|
+
require "wandbox/compiler"
|
7
|
+
|
8
|
+
module Wandbox
|
9
|
+
def list
|
10
|
+
List.new Web.list
|
11
|
+
end
|
12
|
+
module_function :list
|
13
|
+
|
14
|
+
def run compiler, code, **opt
|
15
|
+
Web.compile opt.merge({compiler: compiler, code: code})
|
16
|
+
end
|
17
|
+
module_function :run
|
18
|
+
|
19
|
+
def run_by_file filename, **opt
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/wandbox/cli.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
require "thor"
|
3
|
+
require "wandbox"
|
4
|
+
require "wandbox/version"
|
5
|
+
require "wandbox/cli/compiler_list"
|
6
|
+
require "wandbox/cli/compiler"
|
7
|
+
require "wandbox/cli/run"
|
8
|
+
|
9
|
+
module Wandbox module CLI
|
10
|
+
class CLI < Thor
|
11
|
+
register CompilerList, "compilerlist", "compiler-list [OPTIONS]...", "Output compiler list."
|
12
|
+
tasks["compilerlist"].options = CompilerList.class_options
|
13
|
+
map "compiler-list" => "compilerlist"
|
14
|
+
|
15
|
+
register Compiler, "compiler", "compiler [COMPILER] [OPTIONS]...", "Output compiler setting."
|
16
|
+
tasks["compiler"].options = Compiler.class_options
|
17
|
+
|
18
|
+
register Run, "run_", "run [OPTIONS]... [FILES]...", "Run for [FILES] by Wandbox."
|
19
|
+
tasks["run_"].options = Run.class_options
|
20
|
+
map "run" => "run_"
|
21
|
+
|
22
|
+
desc "version", "Output version"
|
23
|
+
def version
|
24
|
+
puts Wandbox::VERSION
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
require "thor"
|
3
|
+
require "wandbox"
|
4
|
+
|
5
|
+
|
6
|
+
module Wandbox module CLI
|
7
|
+
class Compiler < Thor::Group
|
8
|
+
argument :compiler, type: :string, desc: "Compiler name."
|
9
|
+
class_option :options, type: :string, desc: "Using options. e.g.) --options=warning,c++11"
|
10
|
+
|
11
|
+
def execute
|
12
|
+
name = compiler
|
13
|
+
compiler = Wandbox::Compiler.from_compiler_name name
|
14
|
+
return puts "Not found '#{name}'." unless compiler
|
15
|
+
opts = options["options"] || ""
|
16
|
+
puts compiler.to_stdio opts.split ","
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
require "thor"
|
3
|
+
require "wandbox"
|
4
|
+
# require "iolite"
|
5
|
+
|
6
|
+
module Wandbox module CLI
|
7
|
+
class CompilerList < Thor::Group
|
8
|
+
class_option :lang, type: :string, desc: "Output [LANGUAGE] compilers."
|
9
|
+
|
10
|
+
def execute
|
11
|
+
list = Wandbox.list
|
12
|
+
if options[:lang]
|
13
|
+
list = list.select_by_language options[:lang]
|
14
|
+
end
|
15
|
+
if list.empty?
|
16
|
+
return puts "Not found compiler list."
|
17
|
+
end
|
18
|
+
puts "Compiler list:"
|
19
|
+
list.each {|it|
|
20
|
+
puts " #{it["name"]}"
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
require "thor"
|
3
|
+
require "wandbox"
|
4
|
+
|
5
|
+
module Wandbox module CLI
|
6
|
+
class Run < Thor::Group
|
7
|
+
|
8
|
+
argument :filenames, type: :array
|
9
|
+
|
10
|
+
class_option :lang, type: :string, desc: "Programming language. e.g.) --lang=C++"
|
11
|
+
class_option :compiler, type: :string, desc: "Run compiler. e.g.) --compiler=clang-head"
|
12
|
+
class_option :stdin, type: :string, desc: "Stdin value."
|
13
|
+
class_option :options, type: :string, desc: "Wandbox options. e.g.) --options=warning,c++11"
|
14
|
+
class_option :save, type: :boolean, desc: "Output wandbox permanent link."
|
15
|
+
class_option :"post-parameter", type: :hash, desc: "POST parameter."
|
16
|
+
class_option :debug, type: :boolean, desc: ""
|
17
|
+
|
18
|
+
def execute
|
19
|
+
filenames.each{ |filename|
|
20
|
+
return puts "File '#{filename}' not found." unless File.exist? filename
|
21
|
+
}
|
22
|
+
filename, *filenames_ = filenames
|
23
|
+
|
24
|
+
lang = options[:lang] || Wandbox.file2lang(filename)
|
25
|
+
compiler = options[:compiler] || Wandbox.lang2compiler(lang)["name"]
|
26
|
+
if compiler.nil?
|
27
|
+
return puts "No supported language."
|
28
|
+
end
|
29
|
+
|
30
|
+
# puts compiler["display-compile-command"].sub(/prog\..+/, filename)
|
31
|
+
# puts "Running by #{compiler}..."
|
32
|
+
|
33
|
+
code = File.open(filename).read
|
34
|
+
param = {}
|
35
|
+
param[:codes] = filenames_.map { |filename|
|
36
|
+
{ "file" => filename, "code" => File.open(filename).read }
|
37
|
+
}
|
38
|
+
param[:stdin] = options[:stdin] || ""
|
39
|
+
param[:save] = options[:save] || false
|
40
|
+
param[:options] = options[:options]
|
41
|
+
|
42
|
+
# String to Symbol from key
|
43
|
+
param.merge! Hash[options[:"post-parameter"].map{|k,v| [k.to_sym, v] }] if options[:"post-parameter"]
|
44
|
+
|
45
|
+
puts param if options[:debug]
|
46
|
+
result = Wandbox.run compiler, code, param
|
47
|
+
|
48
|
+
progfile = "prog#{File.extname filename}"
|
49
|
+
|
50
|
+
if param[:save]
|
51
|
+
puts result["url"]
|
52
|
+
end
|
53
|
+
puts result if options[:debug]
|
54
|
+
puts "#{result["compiler_message"]}#{result["program_message"]}"
|
55
|
+
status = result["status"].to_i
|
56
|
+
if status != 0
|
57
|
+
exit status
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "wandbox"
|
2
|
+
require "iolite"
|
3
|
+
require "json"
|
4
|
+
require_relative "./list"
|
5
|
+
|
6
|
+
module Wandbox
|
7
|
+
class Compiler < Hash
|
8
|
+
include Iolite::Placeholders
|
9
|
+
include Iolite::Adaptor::ToLazy
|
10
|
+
|
11
|
+
def initialize data
|
12
|
+
data.each { |key, value| self[key] = value }
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.from_compiler_name name
|
16
|
+
compiler = Wandbox.list.find_compiler name
|
17
|
+
return nil unless compiler
|
18
|
+
Compiler.new compiler
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.from_json json
|
22
|
+
Compiler.new JSON.parse json
|
23
|
+
end
|
24
|
+
|
25
|
+
def options
|
26
|
+
options = self["switches"].select &arg1["type"] == "single"
|
27
|
+
options + self["switches"].select(&arg1["type"] == "select").map(&arg1["options"]).flatten
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_option_by_name name
|
31
|
+
options.find &arg1["name"] == name
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_stdio enable_options=[]
|
35
|
+
opts = options
|
36
|
+
opts.reject! &arg1["display-flags"].empty?
|
37
|
+
opts.sort_by! &arg1["name"]
|
38
|
+
width = (opts.max_by(&arg1["name"].length) || { "name" => "" })["name"].length
|
39
|
+
|
40
|
+
enable_options_s = enable_options.map(&to_l.find_option_by_name(arg1)).compact.map(&arg1["display-flags"]).join " "
|
41
|
+
<<"EOS"
|
42
|
+
[Compiler]:
|
43
|
+
#{self["display-name"]}
|
44
|
+
|
45
|
+
[Language]:
|
46
|
+
#{self["language"]}
|
47
|
+
|
48
|
+
[Version]:
|
49
|
+
#{self["version"]}
|
50
|
+
|
51
|
+
[Compiler command]:
|
52
|
+
$ #{self["display-compile-command"]}#{ " " + enable_options_s unless enable_options_s.empty?}
|
53
|
+
#{
|
54
|
+
unless opts.empty?
|
55
|
+
<<"EOS"
|
56
|
+
|
57
|
+
[Option list]:
|
58
|
+
#{"Option name".ljust width + 1} : Added extra option
|
59
|
+
#{
|
60
|
+
opts.map { |it|
|
61
|
+
" #{it["name"].ljust width + 1} : #{it["display-flags"]}"
|
62
|
+
}.join "\n"
|
63
|
+
}
|
64
|
+
EOS
|
65
|
+
end
|
66
|
+
}
|
67
|
+
EOS
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
require "wandbox/list"
|
3
|
+
require "wandbox"
|
4
|
+
|
5
|
+
|
6
|
+
module Wandbox
|
7
|
+
FILE_EXTENTIONS = {
|
8
|
+
".cpp" => "C++",
|
9
|
+
".c" => "C",
|
10
|
+
".d" => "D",
|
11
|
+
".rill" => "Rill",
|
12
|
+
".hs" => "Haskell",
|
13
|
+
".lhs" => "Haskell",
|
14
|
+
".cs" => "C#",
|
15
|
+
".pl" => "Perl",
|
16
|
+
".py" => "Python",
|
17
|
+
".rb" => "Ruby",
|
18
|
+
".php" => "PHP",
|
19
|
+
".erl" => "Erlang",
|
20
|
+
".exs" => "Elixir",
|
21
|
+
".js" => "JavaScript",
|
22
|
+
".coffee" => "CoffeeScript",
|
23
|
+
".sql" => "SQL",
|
24
|
+
".scala" => "Scala",
|
25
|
+
".lua" => "Lua",
|
26
|
+
".rs" => "Rust",
|
27
|
+
".vim" => "Vim script",
|
28
|
+
".bash" => "Bash script",
|
29
|
+
".lazy" => "Lazy K",
|
30
|
+
".lisp" => "Lisp",
|
31
|
+
".pas" => "Pascal",
|
32
|
+
".java" => "Java",
|
33
|
+
".groovy" => "Groovy",
|
34
|
+
}
|
35
|
+
|
36
|
+
def ext2lang ext
|
37
|
+
ext = ext.downcase
|
38
|
+
FILE_EXTENTIONS[ext]
|
39
|
+
end
|
40
|
+
module_function :ext2lang
|
41
|
+
|
42
|
+
def file2lang filename
|
43
|
+
ext2lang File.extname filename
|
44
|
+
end
|
45
|
+
module_function :file2lang
|
46
|
+
|
47
|
+
def lang2compilers lang
|
48
|
+
Wandbox.list.select_by_language(lang)
|
49
|
+
end
|
50
|
+
module_function :lang2compilers
|
51
|
+
|
52
|
+
def lang2compiler lang
|
53
|
+
lang2compilers(lang).first
|
54
|
+
end
|
55
|
+
module_function :lang2compiler
|
56
|
+
|
57
|
+
def file2compiler filename
|
58
|
+
lang = file2lang filename
|
59
|
+
lang2compiler lang if lang
|
60
|
+
end
|
61
|
+
module_function :file2compiler
|
62
|
+
end
|
data/lib/wandbox/list.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
require "iolite"
|
3
|
+
require_relative "./compiler"
|
4
|
+
|
5
|
+
module Wandbox
|
6
|
+
class List
|
7
|
+
include Enumerable
|
8
|
+
include Iolite::Placeholders
|
9
|
+
|
10
|
+
def initialize list
|
11
|
+
@list = list
|
12
|
+
end
|
13
|
+
|
14
|
+
def each &block
|
15
|
+
@list.each &block
|
16
|
+
end
|
17
|
+
|
18
|
+
def languages
|
19
|
+
map(&arg1["language"]).uniq
|
20
|
+
end
|
21
|
+
|
22
|
+
def select_by_language lang
|
23
|
+
lang = lang.downcase
|
24
|
+
select &arg1["language"].downcase == lang
|
25
|
+
end
|
26
|
+
|
27
|
+
def find_compiler compiler
|
28
|
+
find &arg1["name"] == compiler
|
29
|
+
end
|
30
|
+
|
31
|
+
def empty?
|
32
|
+
@list.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_ary
|
36
|
+
@list
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/wandbox/web.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
require "net/http"
|
3
|
+
require "uri"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
|
7
|
+
module Wandbox module Web
|
8
|
+
def list
|
9
|
+
res = Net::HTTP.get_response URI.parse('http://melpon.org/wandbox/api/list.json')
|
10
|
+
if res.code != "200"
|
11
|
+
return []
|
12
|
+
end
|
13
|
+
JSON.parse(res.body)
|
14
|
+
end
|
15
|
+
module_function :list
|
16
|
+
|
17
|
+
def compile compiler: "", code: "", codes: [], options: "", stdin: "", compiler_option_raw: "", runtime_option_raw: "", save: false
|
18
|
+
body = {
|
19
|
+
"code" => code,
|
20
|
+
"compiler" => compiler,
|
21
|
+
"codes" => codes,
|
22
|
+
"options" => options,
|
23
|
+
"stdin" => stdin,
|
24
|
+
"compiler-option-raw" => compiler_option_raw,
|
25
|
+
"runtime-option-raw" => runtime_option_raw,
|
26
|
+
"save" => save,
|
27
|
+
}
|
28
|
+
# p body
|
29
|
+
uri = URI.parse("http://melpon.org/wandbox/api/compile.json")
|
30
|
+
|
31
|
+
request = Net::HTTP::Post.new(uri.request_uri, initheader = { "Content-type" => "application/json" },)
|
32
|
+
request.body = body.to_json
|
33
|
+
|
34
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
35
|
+
|
36
|
+
http.start do |http|
|
37
|
+
response = http.request(request)
|
38
|
+
JSON.parse(response.body)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
module_function :compile
|
42
|
+
end end
|
data/wandbox.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wandbox/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wandbox"
|
8
|
+
spec.version = Wandbox::VERSION
|
9
|
+
spec.authors = ["manga_osyo"]
|
10
|
+
spec.email = ["manga.osyo@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Wandbox(http://melpon.org/wandbox/) in CLI.}
|
13
|
+
spec.description = %q{Wandbox(http://melpon.org/wandbox/) in CLI.}
|
14
|
+
spec.homepage = "https://github.com/osyo-manga/gem-wandbox"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "thor", "0.19.1"
|
23
|
+
spec.add_dependency "iolite", "0.0.3"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wandbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- manga_osyo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.19.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.19.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: iolite
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Wandbox(http://melpon.org/wandbox/) in CLI.
|
70
|
+
email:
|
71
|
+
- manga.osyo@gmail.com
|
72
|
+
executables:
|
73
|
+
- wandbox
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- exe/wandbox
|
86
|
+
- lib/wandbox.rb
|
87
|
+
- lib/wandbox/cli.rb
|
88
|
+
- lib/wandbox/cli/cli.rb
|
89
|
+
- lib/wandbox/cli/compiler.rb
|
90
|
+
- lib/wandbox/cli/compiler_list.rb
|
91
|
+
- lib/wandbox/cli/run.rb
|
92
|
+
- lib/wandbox/compiler.rb
|
93
|
+
- lib/wandbox/converter.rb
|
94
|
+
- lib/wandbox/list.rb
|
95
|
+
- lib/wandbox/version.rb
|
96
|
+
- lib/wandbox/web.rb
|
97
|
+
- wandbox.gemspec
|
98
|
+
homepage: https://github.com/osyo-manga/gem-wandbox
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.4.5
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Wandbox(http://melpon.org/wandbox/) in CLI.
|
122
|
+
test_files: []
|