parasite 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/Manifest.txt +8 -0
- data/README.txt +117 -0
- data/Rakefile +20 -0
- data/bin/parasite +49 -0
- data/lib/parasite.rb +3 -0
- data/templates/server.rake +127 -0
- data/test/test_parasite.rb +0 -0
- metadata +61 -0
data/History.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Release 0-2-0
|
2
|
+
-- added parasite executable, links into rails environment
|
3
|
+
-- updated generator to be compatible with changes in Rails
|
4
|
+
-- updated generator to be compatible with changes in Camping
|
5
|
+
-- cleaned up some behind the scenes stuff
|
6
|
+
-- add a website to the build
|
7
|
+
|
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
** Parasite
|
2
|
+
|
3
|
+
Camping app developers no longer have any reason to envy their Ruby on Rails friends: Parasite brings generators, environments, and other Rails-y goodness to the world of Camping app development.
|
4
|
+
|
5
|
+
Parasite is currently at version 0.2. The Parasite package is composed of two gems: parasite and the camping_generator. The first provides a way to hook into the Rails development environment, while the second provides a generator for creating Camping apps quickly and painlessly.
|
6
|
+
|
7
|
+
*** Installation
|
8
|
+
|
9
|
+
To install parasite and the camping_generator fire up a terminal and:
|
10
|
+
|
11
|
+
$ sudo gem install parasite
|
12
|
+
parasite will require the camping_generator, along with Rails and Camping. More details on installing those packages can be found at their project pages.
|
13
|
+
|
14
|
+
If you are installing Camping for the first time, I would encourage you to install the camping-omnibus gem:
|
15
|
+
|
16
|
+
$ sudo gem install camping-omnibus --source http://code.whytheluckystiff.net
|
17
|
+
If you wish to install the camping_generator without the parasite gem, you can install it directly with:
|
18
|
+
|
19
|
+
$ sudo gem install camping_generator
|
20
|
+
Usage
|
21
|
+
|
22
|
+
**** Parasite
|
23
|
+
The parasite package consists of an executable and a set of Rake templates to facilitate the building of Camping apps. Using the executable, you can latch on to a “host” Rails project. Just run the executable in an existing Rails environment.
|
24
|
+
|
25
|
+
$ rails example_project
|
26
|
+
create
|
27
|
+
create app/controllers
|
28
|
+
...
|
29
|
+
$ cd example_project/
|
30
|
+
$ ls
|
31
|
+
README components doc public tmp
|
32
|
+
Rakefile config lib script vendor
|
33
|
+
app db log test
|
34
|
+
$ parasite
|
35
|
+
/path/to/parasite/parasite-0.2.0/bin/../templates/
|
36
|
+
|
37
|
+
/path/to/parasiteparasite-0.2.0/bin/../templates/server.rake
|
38
|
+
|
39
|
+
Installed parasite to ./vendor/plugins/parasite
|
40
|
+
$ ls -R vendor/plugins/parasite/
|
41
|
+
tasks
|
42
|
+
|
43
|
+
vendor/plugins/parasite//tasks:
|
44
|
+
server.rake
|
45
|
+
$
|
46
|
+
To see a description of the installed rake tasks,
|
47
|
+
|
48
|
+
$ rake -T
|
49
|
+
rake camping:server # Run the camping server with specified files or all .rb files in the apps directory
|
50
|
+
...
|
51
|
+
Now you’re ready to start creating camping apps, using the camping_generator.
|
52
|
+
|
53
|
+
**** Camping Generator
|
54
|
+
The camping_generator adds a generator for creating templated Camping apps. If you’re not familiar with the structure of single file Camping apps, see The Camping Short, Short Example. To see the usage,
|
55
|
+
|
56
|
+
$ script/generate camping
|
57
|
+
Usage: script/generate camping CampingName [options]
|
58
|
+
|
59
|
+
Options:
|
60
|
+
--scaffold Generate controllers and views
|
61
|
+
--session Add session support
|
62
|
+
--stylesheet Include a dynamic style sheet
|
63
|
+
|
64
|
+
Rails Info:
|
65
|
+
-v, --version Show the Rails version number and quit.
|
66
|
+
-h, --help Show this help message and quit.
|
67
|
+
|
68
|
+
General Options:
|
69
|
+
-p, --pretend Run but do not make any changes.
|
70
|
+
-f, --force Overwrite files that already exist.
|
71
|
+
-s, --skip Skip files that already exist.
|
72
|
+
-q, --quiet Suppress normal output.
|
73
|
+
-t, --backtrace Debugging: show backtrace on errors.
|
74
|
+
-c, --svn Modify files with subversion. (Note: svn must be in path)
|
75
|
+
|
76
|
+
Description:
|
77
|
+
The camping generator creates a new camping app in a single file in the /app
|
78
|
+
directory.
|
79
|
+
|
80
|
+
Example:
|
81
|
+
./script/generate camping --scaffold Blog Post User
|
82
|
+
|
83
|
+
This will create a Blog app with models (Posts and Users), views,
|
84
|
+
controllers, and the appropriate pre-amble and post-amble.
|
85
|
+
|
86
|
+
For example, let’s create the canonical jukebox app using the generator:
|
87
|
+
|
88
|
+
$ script/generate camping Jukebox Artist Record Track --scaffold --stylesheet
|
89
|
+
exists app/
|
90
|
+
create app/jukebox.rb
|
91
|
+
$ cat app/jukebox.rb
|
92
|
+
#!/usr/bin/env ruby
|
93
|
+
|
94
|
+
require 'camping'
|
95
|
+
Camping.goes :Jukebox
|
96
|
+
|
97
|
+
module Jukebox
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
module Jukebox::Models
|
102
|
+
class Artist < Base; end
|
103
|
+
class Record < Base; end
|
104
|
+
class Track < Base; end
|
105
|
+
...
|
106
|
+
Closer investigation of the jukebox app is left as an exercise to the reader.
|
107
|
+
|
108
|
+
*** Support
|
109
|
+
|
110
|
+
The best place for getting support is on #camping on irc.freenode.net. Just ask for mfredrickson. Also, you can file bugs and patches on Parasite project page on RubyForge.
|
111
|
+
|
112
|
+
*** Links
|
113
|
+
|
114
|
+
http://rubyforge.org/projects/parasite
|
115
|
+
http://rubyonrails.com/
|
116
|
+
http://code.whytheluckystiff.net/camping
|
117
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'echoe'
|
5
|
+
require '../version.rb'
|
6
|
+
|
7
|
+
# Copy in history and readmes
|
8
|
+
File.cp '../History.txt', './History.txt'
|
9
|
+
File.cp '../README.txt', './README.txt'
|
10
|
+
|
11
|
+
Echoe.new('parasite', Parasite::Common::MAJOR_VERSION + '.0') do |p|
|
12
|
+
p.rubyforge_name = 'parasite'
|
13
|
+
p.summary = 'Turn a Rails environment into a Camping factory'
|
14
|
+
p.description = p.paragraphs_of('README.txt', 2..3).join("\n\n")
|
15
|
+
p.url = Parasite::Common::URL
|
16
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
17
|
+
p.extra_deps = [['camping_generator', '0.2.0']]
|
18
|
+
end
|
19
|
+
|
20
|
+
# vim: syntax=Ruby
|
data/bin/parasite
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
templates = File.dirname(__FILE__) + '/../templates/'
|
7
|
+
|
8
|
+
puts templates + "\n\n"
|
9
|
+
|
10
|
+
OPTIONS = {
|
11
|
+
:rails_root => '.'
|
12
|
+
}
|
13
|
+
parser = OptionParser.new do |opts|
|
14
|
+
opts.banner = <<BANNER
|
15
|
+
Turn your Rails environment into a Camping factory.
|
16
|
+
Installs rake tasks and overrides generators to make
|
17
|
+
creating Camping apps faster and easier.
|
18
|
+
|
19
|
+
Usage: #{File.basename($0)} [--apply-to <rails app path>]
|
20
|
+
|
21
|
+
Options are:
|
22
|
+
BANNER
|
23
|
+
opts.separator ""
|
24
|
+
opts.on("-a", "--apply-to=PATH", String,
|
25
|
+
"Root path of your rails application",
|
26
|
+
"Default: .") { |OPTIONS[:rails_root]| }
|
27
|
+
opts.parse!(ARGV)
|
28
|
+
end
|
29
|
+
|
30
|
+
plugins = File.join(OPTIONS[:rails_root], 'vendor', 'plugins')
|
31
|
+
parasite_path = File.join(plugins, 'parasite')
|
32
|
+
tasks_path = File.join(parasite_path, 'tasks')
|
33
|
+
task_templates = Dir[File.join(templates, '*.rake')]
|
34
|
+
|
35
|
+
FileUtils.rm_rf parasite_path
|
36
|
+
Dir.mkdir parasite_path
|
37
|
+
|
38
|
+
Dir.mkdir tasks_path
|
39
|
+
Dir.chdir tasks_path do
|
40
|
+
task_templates.each do |template_name|
|
41
|
+
puts template_name + "\n\n"
|
42
|
+
task_name = File.basename(template_name).sub(/\Atasks_/,'')
|
43
|
+
template = File.open(template_name,'r') {|f| f.readlines.join}
|
44
|
+
File.open(task_name, 'w') {|file| file << template }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
puts "Installed parasite to #{parasite_path}"
|
49
|
+
|
data/lib/parasite.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
namespace :camping do
|
3
|
+
desc "Run the camping server with specified files or all .rb files in the apps directory"
|
4
|
+
task :server do
|
5
|
+
require 'rubygems'
|
6
|
+
require 'camping'
|
7
|
+
require 'camping/reloader'
|
8
|
+
require 'webrick/httpserver'
|
9
|
+
require 'camping/webrick'
|
10
|
+
|
11
|
+
# Get the database and log from the current rails environment
|
12
|
+
require(File.join(RAILS_ROOT, 'config', 'environment'))
|
13
|
+
database = (YAML.load(open(File.join('config', 'database.yml')))[RAILS_ENV])
|
14
|
+
log = File.join(RAILS_ROOT, 'log', RAILS_ENV + '.log')
|
15
|
+
|
16
|
+
# TODO take these from environment variables or something else useful
|
17
|
+
webhost = '0.0.0.0'
|
18
|
+
webport = '3301'
|
19
|
+
|
20
|
+
ARGV.shift # drop the 'camping' command from the list
|
21
|
+
|
22
|
+
# if the user specified a file(s) use it, otherwise grab everything in /app
|
23
|
+
ARGV << File.join(RAILS_ROOT, 'app') if ARGV.empty?
|
24
|
+
|
25
|
+
# from the camping command line tool:
|
26
|
+
# Load apps
|
27
|
+
PATHS = ARGV.dup
|
28
|
+
apps = PATHS.inject([]) do |apps, script|
|
29
|
+
if File.directory? script
|
30
|
+
apps.push(*Dir[File.join(script, '*.rb')])
|
31
|
+
else
|
32
|
+
apps << script
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Camping::Reloader.database = database
|
37
|
+
Camping::Reloader.log = log
|
38
|
+
apps.map! { |script| Camping::Reloader.new(script) }
|
39
|
+
abort("** No apps successfully loaded") unless apps.detect { |app| app.klass }
|
40
|
+
|
41
|
+
def apps.find_new_scripts
|
42
|
+
each { |app| app.reload_app }
|
43
|
+
PATHS.each do |path|
|
44
|
+
Dir[File.join(path, '*.rb')].each do |script|
|
45
|
+
smount = File.basename(script, '.rb')
|
46
|
+
next if detect { |x| x.mount == smount }
|
47
|
+
|
48
|
+
puts "** Discovered new #{script}"
|
49
|
+
app = Camping::Reloader.new(script)
|
50
|
+
next unless app
|
51
|
+
|
52
|
+
yield app
|
53
|
+
self << app
|
54
|
+
end
|
55
|
+
end
|
56
|
+
self.sort! { |x, y| x.mount <=> y.mount }
|
57
|
+
end
|
58
|
+
|
59
|
+
def apps.index_page
|
60
|
+
welcome = "You are Camping"
|
61
|
+
apps = self
|
62
|
+
b = Markaby::Builder.new({}, {})
|
63
|
+
b = b.instance_eval do
|
64
|
+
html do
|
65
|
+
head do
|
66
|
+
title welcome
|
67
|
+
style <<-END, :type => 'text/css'
|
68
|
+
body {
|
69
|
+
font-family: verdana, arial, sans-serif;
|
70
|
+
padding: 10px 40px;
|
71
|
+
margin: 0;
|
72
|
+
}
|
73
|
+
h1, h2, h3, h4, h5, h6 {
|
74
|
+
font-family: utopia, georgia, serif;
|
75
|
+
}
|
76
|
+
END
|
77
|
+
end
|
78
|
+
body do
|
79
|
+
h1 welcome
|
80
|
+
p %{Good day. These are the Camping apps you mounted.}
|
81
|
+
ul do
|
82
|
+
apps.each do |app|
|
83
|
+
next unless app.klass
|
84
|
+
li do
|
85
|
+
h3(:style => "display: inline") { a app.klass.name, :href => "/#{app.mount}" }
|
86
|
+
small { text " / " ; a "View Source", :href => "/code/#{app.mount}" }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
b.to_s
|
94
|
+
end
|
95
|
+
|
96
|
+
# Mount the root
|
97
|
+
s = WEBrick::HTTPServer.new(:BindAddress => webhost, :Port => webport)
|
98
|
+
if apps.length > 1
|
99
|
+
apps.each do |app|
|
100
|
+
s.mount "/#{app.mount}", WEBrick::CampingHandler, app
|
101
|
+
s.mount_proc("/code/#{app.mount}") do |req, resp|
|
102
|
+
resp['Content-Type'] = 'text/plain'
|
103
|
+
resp.body = app.view_source
|
104
|
+
end
|
105
|
+
end
|
106
|
+
s.mount_proc("/") do |req, resp|
|
107
|
+
apps.find_new_scripts do |app|
|
108
|
+
s.mount "/#{app.mount}", WEBrick::CampingHandler, app
|
109
|
+
s.mount_proc("/code/#{app.mount}") do |req, resp|
|
110
|
+
resp['Content-Type'] = 'text/plain'
|
111
|
+
resp.body = app.view_source
|
112
|
+
end
|
113
|
+
end
|
114
|
+
resp.body = apps.index_page
|
115
|
+
end
|
116
|
+
else
|
117
|
+
s.mount "/", WEBrick::CampingHandler, apps.first
|
118
|
+
end
|
119
|
+
|
120
|
+
# Server up
|
121
|
+
trap(:INT) do
|
122
|
+
s.shutdown
|
123
|
+
end
|
124
|
+
s.start
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.1
|
3
|
+
specification_version: 1
|
4
|
+
name: parasite
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2007-03-11 00:00:00 -06:00
|
8
|
+
summary: Turn a Rails environment into a Camping factory
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: ""
|
12
|
+
homepage: http://parasite.rubyforge.org
|
13
|
+
rubyforge_project: parasite
|
14
|
+
description: "Parasite is currently at version 0.2. The Parasite package is composed of two gems: parasite and the camping_generator. The first provides a way to hook into the Rails development environment, while the second provides a generator for creating Camping apps quickly and painlessly. *** Installation"
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- ""
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- bin/parasite
|
37
|
+
- lib/parasite.rb
|
38
|
+
- test/test_parasite.rb
|
39
|
+
- templates/server.rake
|
40
|
+
test_files:
|
41
|
+
- test/test_parasite.rb
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
executables:
|
47
|
+
- parasite
|
48
|
+
extensions: []
|
49
|
+
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
dependencies:
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: camping_generator
|
55
|
+
version_requirement:
|
56
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.2.0
|
61
|
+
version:
|