ruby-station 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/public/ramaze.png ADDED
Binary file
Binary file
@@ -0,0 +1,66 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{ruby-station}
5
+ s.version = "0.0.4"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Yutaka HARA"]
9
+ s.date = %q{2009-08-15}
10
+ s.default_executable = %q{ruby-station}
11
+ s.description = %q{Create, Distribute, and Install Ruby applications easily}
12
+ s.email = %q{yutaka.hara/at/gmail.com}
13
+ s.executables = ["ruby-station"]
14
+ s.files = [
15
+ ".gitignore",
16
+ "Rakefile",
17
+ "VERSION",
18
+ "bin/ruby-station",
19
+ "config.rb",
20
+ "controller/applications.rb",
21
+ "controller/init.rb",
22
+ "controller/main.rb",
23
+ "layout/default.xhtml",
24
+ "model/application.rb",
25
+ "model/init.rb",
26
+ "public/css/ramaze_error.css",
27
+ "public/dispatch.fcgi",
28
+ "public/favicon.ico",
29
+ "public/js/jquery.js",
30
+ "public/ramaze.png",
31
+ "public/spinner.gif",
32
+ "ruby-station.gemspec",
33
+ "runtime/Rakefile",
34
+ "runtime/VERSION",
35
+ "runtime/lib/ruby-station.rb",
36
+ "runtime/lib/ruby-station/helper.rb",
37
+ "runtime/lib/ruby-station/helper/rails.rb",
38
+ "runtime/ruby-station-runtime-0.0.3.gem",
39
+ "runtime/ruby-station-runtime-0.0.4.gem",
40
+ "sample.config.yaml",
41
+ "spec/main.rb",
42
+ "util/gem-manager.rb",
43
+ "view/applications/do_install.xhtml",
44
+ "view/applications/install.xhtml",
45
+ "view/applications/uninstall.xhtml",
46
+ "view/index.xhtml"
47
+ ]
48
+ s.homepage = %q{http://github.com/yhara/ruby-station}
49
+ s.rdoc_options = ["--charset=UTF-8"]
50
+ s.require_paths = ["lib"]
51
+ s.rubygems_version = %q{1.3.5}
52
+ s.summary = %q{Create, Distribute, and Install Ruby applications easily}
53
+ s.test_files = [
54
+ "spec/main.rb"
55
+ ]
56
+
57
+ if s.respond_to? :specification_version then
58
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
59
+ s.specification_version = 3
60
+
61
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
62
+ else
63
+ end
64
+ else
65
+ end
66
+ end
data/runtime/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require 'rake/gempackagetask'
2
+
3
+ version = File.read('VERSION').chomp
4
+
5
+ spec = Gem::Specification.new do |s|
6
+ s.name = 'ruby-station-runtime'
7
+ s.version = version
8
+ s.has_rdoc = false
9
+ # s.extra_rdoc_files = %w(README.rdoc)
10
+ # s.rdoc_options = %w(--main README.rdoc)
11
+ s.summary = "Runtime library for RubyStation"
12
+ s.author = 'Yutaka HARA'
13
+ s.email = 'yutaka.hara/at/gmail.com'
14
+ # s.homepage = 'http://my-site.net'
15
+ s.files = %w(Rakefile) + Dir.glob("{lib}/**/*")
16
+ end
17
+
18
+ Rake::GemPackageTask.new(spec) do |pkg|
19
+ pkg.gem_spec = spec
20
+ end
21
+
22
+ desc 'Generate the gemspec'
23
+ task :gemspec do
24
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
25
+ File.open(file, 'w') {|f| f << spec.to_ruby }
26
+ puts "Created gemspec: #{file}"
27
+ end
data/runtime/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.4
@@ -0,0 +1,64 @@
1
+ require 'fileutils'
2
+ module RubyStation
3
+ module Helper
4
+
5
+ # This module helps invoking Rails apps.
6
+ # During execution of the application, Rails writes data to
7
+ # many directories (db/, log/, tmp/).
8
+ # So this helper copies all the files into data_dir and
9
+ # invoke the app within the directory.
10
+ #
11
+ # Be sure to run 'rake db:migrate RAILS_ENV=produciton'
12
+ # before you create the gem of your app.
13
+ #
14
+ # @example
15
+ # RubyStation::Helper::Rails.run
16
+ #
17
+ # @api external
18
+
19
+ module Rails
20
+
21
+ # Copy files (if needed) and start Rails server.
22
+ #
23
+ # @api external
24
+ def self.run
25
+ caller_path = caller[0][/^(.*):/, 1]
26
+ self.install(File.dirname(caller_path))
27
+
28
+ Dir.chdir(RubyStation.data_dir)
29
+ self.start_server
30
+ end
31
+
32
+ # Ensure your app is copied to data_dir.
33
+ # It does nothing if already copied.
34
+ #
35
+ # @api internal
36
+ def self.install(app_dir)
37
+ # Note: "." is needed, otherwise copied as data_dir/appname/*
38
+ from = File.join(app_dir, ".")
39
+ to = RubyStation.data_dir
40
+
41
+ unless installed?(from, to)
42
+ FileUtils.cp_r(from, to)
43
+ end
44
+ end
45
+
46
+ # Checks if the files are copied
47
+ #
48
+ # @api internal
49
+ def self.installed?(from, to)
50
+ # Note: Too simple?
51
+ File.exist?(File.join(to, "main.rb"))
52
+ end
53
+
54
+ # Start Rails with 'script/server'.
55
+ #
56
+ # @api internal
57
+ def self.start_server
58
+ Dir.chdir(RubyStation.data_dir)
59
+ # TODO: Support Windows
60
+ exec "./script/server -p #{RubyStation.port} -e production"
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,5 @@
1
+ module RubyStation
2
+ module Helper
3
+ autoload :Rails, "ruby-station/helper/rails.rb"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ require 'optparse'
2
+
3
+ module RubyStation
4
+ @port = nil
5
+ @data_dir = nil
6
+
7
+ def self.parse_argv
8
+ OptionParser.new{|o|
9
+ o.on("--port N"){|n| @port = n}
10
+ o.on("--data-dir PATH"){|d| @data_dir = d}
11
+ }.parse!(ARGV)
12
+
13
+ unless @port
14
+ @port = 40000 + rand(10000)
15
+ warn "--port is not specified; assuming it is #{@port}"
16
+ end
17
+ unless @data_dir
18
+ @data_dir = File.expand_path("./")
19
+ warn "--data-dir is not specified; assuming it is #{@data_dir}"
20
+ end
21
+ end
22
+
23
+ def self.port; @port; end
24
+ def self.data_dir; @data_dir; end
25
+ def self.data_path(filename)
26
+ File.expand_path(filename, @data_dir)
27
+ end
28
+
29
+ autoload :Helper, "ruby-station/helper"
30
+ end
@@ -0,0 +1,7 @@
1
+ :ruby_command: "ruby"
2
+ :gem_command: "gem"
3
+ :gem_dir: "./gem_home"
4
+ :gem_bin_dir: "./gem_bin"
5
+ :gem_install_option: "--no-rdoc --no-ri"
6
+ :data_dir: "./data"
7
+ :server_port: 2534
data/spec/main.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'ramaze'
2
+ require 'ramaze/spec/helper'
3
+
4
+ require __DIR__('../start')
5
+
6
+ describe MainController do
7
+ behaves_like 'http', 'xpath'
8
+ ramaze :view_root => __DIR__('../view'),
9
+ :public_root => __DIR__('../public')
10
+
11
+ it 'should show start page' do
12
+ got = get('/')
13
+ got.status.should == 200
14
+ puts got.body
15
+ got.at('//title').text.strip.should ==
16
+ MainController.new.index
17
+ end
18
+
19
+ it 'should show /notemplate' do
20
+ got = get('/notemplate')
21
+ got.status.should == 200
22
+ got.at('//div').text.strip.should ==
23
+ MainController.new.notemplate
24
+ end
25
+ end
@@ -0,0 +1,78 @@
1
+ module GemManager
2
+ def self.installed?(gemname, version)
3
+ gem_path = File.join(Conf.gem_dir, "gems", "#{gemname}-#{version}")
4
+ exists = File.exist?(gem_path)
5
+ Ramaze::Log.info "checking existance of #{gem_path}.. #{exists}"
6
+
7
+ exists
8
+ end
9
+
10
+ def self.install_file(path)
11
+ begin
12
+ # make symlink
13
+ newpath = "/tmp/#{File.basename(path, ".gem")}.gem"
14
+ File.symlink(path, newpath)
15
+
16
+ # install
17
+ cmd = [
18
+ Conf.gem_command, "install", newpath,
19
+ "-i", Conf.gem_dir,
20
+ "-n", Conf.gem_bin_dir,
21
+ Conf.gem_install_option
22
+ ].join(" ")
23
+ Ramaze::Log.info cmd
24
+
25
+ # execute
26
+ result = `#{cmd}`
27
+
28
+ # make data dir
29
+ spec = YAML.load(`gem spec #{path}`)
30
+ data_dir = File.join(Conf.data_dir, "#{spec.name}-#{spec.version}")
31
+ unless File.directory?(data_dir)
32
+ Dir.mkdir(data_dir)
33
+ Ramaze::Log.info "made data dir for the gem: #{data_dir}"
34
+ end
35
+
36
+ [result, spec.name, spec.version.to_s]
37
+ ensure
38
+ File.unlink(newpath)
39
+ end
40
+ end
41
+
42
+ def self.install_gem(name)
43
+ # install
44
+ cmd = [
45
+ Conf.gem_command, "install", name,
46
+ "-i", Conf.gem_dir,
47
+ "-n", Conf.gem_bin_dir,
48
+ Conf.gem_install_option
49
+ ].join(" ")
50
+ Ramaze::Log.info cmd
51
+
52
+ # execute
53
+ result = `#{cmd}`
54
+
55
+ # make data dir
56
+ raise unless result =~ /installed #{name}-(.*)/
57
+ version = $1
58
+ data_dir = File.join(Conf.data_dir, "#{name}-#{version}")
59
+ unless File.directory?(data_dir)
60
+ Dir.mkdir(data_dir)
61
+ Ramaze::Log.info "made data dir for the gem: #{data_dir}"
62
+ end
63
+
64
+ [result, name, version]
65
+ end
66
+
67
+ def self.uninstall(name, version)
68
+ cmd = [
69
+ Conf.gem_command, "uninstall", name,
70
+ "-v", version,
71
+ "-i", Conf.gem_dir,
72
+ "-n", Conf.gem_bin_dir
73
+ ].join(" ")
74
+ Ramaze::Log.info cmd
75
+
76
+ `#{cmd}`
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ <div>
2
+ #{h @result}
3
+ </div>
@@ -0,0 +1,21 @@
1
+ <div id="install">
2
+ <h2>Installing application</h2>
3
+
4
+ <?r if @name ?>
5
+ <p>Installing gem '#{@name}'...</p>
6
+ <?r else ?>
7
+ <p>Installing gem '#{@filename}'... (#{@size} bytes)</p>
8
+ <?r end ?>
9
+
10
+ <pre id="result">
11
+ <img src='/spinner.gif'>
12
+ </pre>
13
+
14
+ <a href='/'>back</a>
15
+ </div>
16
+
17
+ <script type="text/javascript">
18
+ $(document).ready(function(){
19
+ $("#result").load("#{r(:do_install)}");
20
+ });
21
+ </script>
@@ -0,0 +1,17 @@
1
+ <div id="uninstall">
2
+ <h2>アプリケーションの削除</h2>
3
+
4
+ <p>uninstalling #{@app.full_name} ..</p>
5
+
6
+ <pre id="result">
7
+ <img src='/spinner.gif'>
8
+ </pre>
9
+
10
+ <a href='/'>back</a>
11
+ </div>
12
+
13
+ <script type="text/javascript">
14
+ $(document).ready(function(){
15
+ $("#result").load("#{r(:do_uninstall, @app.id)}");
16
+ });
17
+ </script>
data/view/index.xhtml ADDED
@@ -0,0 +1,79 @@
1
+
2
+ <div id="list">
3
+ <h2>Listing Applications</h2>
4
+ <?r if @applications.nil? or @applications.empty? ?>
5
+
6
+ <?r else ?>
7
+ <table>
8
+ <tr>
9
+ <th>Name</th>
10
+ <th>Version</th>
11
+ <th>State</th>
12
+ <th>Operation</th>
13
+ </tr>
14
+ <?r @applications.each do |app| ?>
15
+ <tr>
16
+ <?r if app.pid ?>
17
+ <td>
18
+ <a href='http://localhost:#{h app.port}' target='_blank'>#{h app.name}</a>
19
+ </td>
20
+ <td>
21
+ #{h app.version}
22
+ </td>
23
+ <td>
24
+ ON / #{Applications.a("OFF", :stop, app.id)}
25
+ </td>
26
+ <?r else ?>
27
+ <td>
28
+ #{h app.name}
29
+ </td>
30
+ <td>
31
+ #{h app.version}
32
+ </td>
33
+ <td>
34
+ <a href='#{Applications.r(:start, app.id)}' target='_blank' onclick='setTimeout(function(){window.location = window.location;}, 1000)'>
35
+ ON</a> / OFF
36
+ </td>
37
+ <?r end ?>
38
+ <td>
39
+ #{Applications.a("-", :uninstall, app.id)}
40
+ </td>
41
+ </tr>
42
+ <?r end ?>
43
+ </table>
44
+ <?r end ?>
45
+ </div>
46
+ <div id="new">
47
+ <h2>Installing Applications</h2>
48
+ <input type="radio" id="by_name_button" checked>
49
+ <label for="by_name_button">by name</label>
50
+ <input type="radio" id="by_file_button">
51
+ <label for="by_file_button">by file</label>
52
+
53
+ <div id="by_name">
54
+ <form action="#{Applications.r(:install)}" method="POST" enctype="multipart/form-data">
55
+ <input type="text" name="name" size="30">
56
+ <input type="submit" value="install">
57
+ </form>
58
+ </div>
59
+
60
+ <div id="by_file" style="display: none;">
61
+ <form action="#{Applications.r(:install)}" method="POST" enctype="multipart/form-data">
62
+ <input type="file" name="gem" size="50">
63
+ <input type="submit" value="install">
64
+ </form>
65
+ </div>
66
+ </div>
67
+
68
+ <script type="text/javascript">
69
+ $(function(){
70
+ $("#by_name_button").change(function(){
71
+ $("#by_name").show();
72
+ $("#by_file").hide();
73
+ });
74
+ $("#by_file_button").change(function(){
75
+ $("#by_name").hide();
76
+ $("#by_file").show();
77
+ });
78
+ });
79
+ </script>
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-station
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Yutaka HARA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-15 00:00:00 +09:00
13
+ default_executable: ruby-station
14
+ dependencies: []
15
+
16
+ description: Create, Distribute, and Install Ruby applications easily
17
+ email: yutaka.hara/at/gmail.com
18
+ executables:
19
+ - ruby-station
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - .gitignore
26
+ - Rakefile
27
+ - VERSION
28
+ - bin/ruby-station
29
+ - config.rb
30
+ - controller/applications.rb
31
+ - controller/init.rb
32
+ - controller/main.rb
33
+ - layout/default.xhtml
34
+ - model/application.rb
35
+ - model/init.rb
36
+ - public/css/ramaze_error.css
37
+ - public/dispatch.fcgi
38
+ - public/favicon.ico
39
+ - public/js/jquery.js
40
+ - public/ramaze.png
41
+ - public/spinner.gif
42
+ - ruby-station.gemspec
43
+ - runtime/Rakefile
44
+ - runtime/VERSION
45
+ - runtime/lib/ruby-station.rb
46
+ - runtime/lib/ruby-station/helper.rb
47
+ - runtime/lib/ruby-station/helper/rails.rb
48
+ - runtime/ruby-station-runtime-0.0.3.gem
49
+ - runtime/ruby-station-runtime-0.0.4.gem
50
+ - sample.config.yaml
51
+ - spec/main.rb
52
+ - util/gem-manager.rb
53
+ - view/applications/do_install.xhtml
54
+ - view/applications/install.xhtml
55
+ - view/applications/uninstall.xhtml
56
+ - view/index.xhtml
57
+ has_rdoc: true
58
+ homepage: http://github.com/yhara/ruby-station
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.5
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Create, Distribute, and Install Ruby applications easily
85
+ test_files:
86
+ - spec/main.rb