rack-raker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,16 @@
1
+ = Rack::Raker
2
+
3
+ A simple Rack middleware (or app) to run Rake tasks.
4
+
5
+ = Usage
6
+
7
+ == Middleware
8
+
9
+ require 'rack/raker'
10
+ use Rack::Raker, '/path/to/Rakefile'
11
+ run Rack::Lobster.new
12
+
13
+ == App
14
+
15
+ require 'rack/raker'
16
+ run Rack::Raker.new('/path/to/Rakefile')
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ task :default => :test
5
+
6
+ Rake::TestTask.new('test') do |t|
7
+ t.pattern = 'test/**/*_test.rb'
8
+ t.warning = true
9
+ t.verbose = true
10
+ end
data/config.ru ADDED
@@ -0,0 +1,13 @@
1
+ require 'rack'
2
+ require 'lib/rack/raker'
3
+
4
+ use Rack::Reloader, 5
5
+
6
+ rakefile = ::File.join(::File.dirname(__FILE__), 'Rakefile')
7
+
8
+ use Rack::Raker, rakefile
9
+ # To test Raker::Middleware
10
+ require 'rack/lobster'
11
+ run Rack::Lobster.new
12
+
13
+ # run Rack::Raker.new(rakefile)
@@ -0,0 +1,7 @@
1
+ <h3><code>$ rake -T</code></h3>
2
+
3
+ <ul>
4
+ <% @tasks.each do |task| %>
5
+ <li><a href="/rake/<%= task %>"><%= task %></a></li>
6
+ <% end %>
7
+ </ul>
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Rack::Raker</title>
5
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
6
+ </head>
7
+
8
+ <body>
9
+ <h1>Rack::Raker</h1>
10
+ <%= yield %>
11
+ </body>
12
+ </html>
@@ -0,0 +1,7 @@
1
+ <h3><code>$ <a href="/rake">rake -T</a></code></h3>
2
+
3
+ <h3><code>$ rake <%= @task %></code></h3>
4
+
5
+ <pre>
6
+ <%= @output %>
7
+ </pre>
@@ -0,0 +1,35 @@
1
+ require 'sinatra/base'
2
+
3
+ module Rack
4
+ module Raker
5
+ class App < Sinatra::Base
6
+
7
+ set :root, ::File.dirname(__FILE__) + '/app'
8
+
9
+ def initialize(*args)
10
+ @args = args
11
+ @rakefile = args.first
12
+ @manager = TaskManager.new(@rakefile)
13
+ end
14
+
15
+ # TODO: Show task descriptions (or make an actual UI).
16
+ get '/rake/?' do
17
+ @tasks = @manager.tasks
18
+ erb :index
19
+ end
20
+
21
+ get '/rake/:task' do |task|
22
+ @task = task
23
+ @output = @manager.run(task)
24
+ # TODO: Maybe show a helpful failure message.
25
+ redirect '/' unless @output
26
+ erb :show
27
+ end
28
+
29
+ not_found do
30
+ redirect '/rake'
31
+ end
32
+
33
+ end # App
34
+ end # Raker
35
+ end # Rack
@@ -0,0 +1,20 @@
1
+ module Rack
2
+ module Raker
3
+ class Middleware
4
+
5
+ def initialize(*args)
6
+ @args = args
7
+ @app = args.shift
8
+ @rakefile = args.first
9
+ end
10
+
11
+ def call(env)
12
+ request = Request.new(env)
13
+ @status, @headers, @body = @app.call(env)
14
+ return [@status, @headers, @body] unless request.path =~ /^\/rake/
15
+ Raker::App.new(@rakefile).call(env)
16
+ end
17
+
18
+ end # Middleware
19
+ end # Raker
20
+ end # Rack
@@ -0,0 +1,29 @@
1
+ module Rack
2
+ module Raker
3
+ class TaskManager
4
+
5
+ attr_accessor :tasks
6
+
7
+ def initialize(rakefile)
8
+ @rakefile = rakefile
9
+ end
10
+
11
+ # Return an array of Rake tasks.
12
+ def tasks
13
+ output = %x[ rake -f #{@rakefile} -s -T ]
14
+ @tasks ||= output.split("\n").map do |task|
15
+ task.match(/^rake\s([\w:]+)/)[1]
16
+ end
17
+ end
18
+
19
+ # Run the specified Rake +task+ and returns the (string) output, or false upon failure.
20
+ # TODO: Maybe move the +rake_opts+ elsewhere.
21
+ def run(task, rake_opts = ['-s'])
22
+ output = %x[ rake -f #{@rakefile} #{rake_opts.join(' ')} #{task} 2>/dev/null ]
23
+ output = false if output.empty?
24
+ output
25
+ end
26
+
27
+ end # TaskManager
28
+ end # Raker
29
+ end # Rack
data/lib/rack/raker.rb ADDED
@@ -0,0 +1,22 @@
1
+ module Rack
2
+ module Raker
3
+
4
+ VERSION = '0.0.1'
5
+
6
+ autoload :App, 'rack/raker/app'
7
+ autoload :Middleware, 'rack/raker/middleware'
8
+ autoload :TaskManager, 'rack/raker/task_manager'
9
+
10
+ # TODO: Add optional URL map.
11
+ def self.new(*args)
12
+ if args.first.class == String
13
+ # run
14
+ Raker::App.new(*args)
15
+ else
16
+ # use
17
+ Raker::Middleware.new(*args)
18
+ end
19
+ end
20
+
21
+ end # Raker
22
+ end # Rack
@@ -0,0 +1,41 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+
5
+ s.name = 'rack-raker'
6
+ s.version = '0.0.1'
7
+ s.date = '2009-11-02'
8
+ s.homepage = 'http://oshuma.github.com/rack-raker'
9
+
10
+ s.authors = ['Dale Campbell']
11
+ s.email = 'oshuma@gmail.com'
12
+
13
+ s.description = 'Rack Rake middleware/app.'
14
+ s.summary = 'Rack Rake middleware/app.'
15
+
16
+ s.add_dependency 'rack', '>= 0.4'
17
+ s.require_paths = %w[lib]
18
+
19
+ s.files = %w[
20
+ README
21
+ Rakefile
22
+ config.ru
23
+ rack-raker.gemspec
24
+ lib/rack/raker.rb
25
+ lib/rack/raker/app.rb
26
+ lib/rack/raker/app/views/index.erb
27
+ lib/rack/raker/app/views/layout.erb
28
+ lib/rack/raker/app/views/show.erb
29
+ lib/rack/raker/middleware.rb
30
+ lib/rack/raker/task_manager.rb
31
+ test/Rakefile
32
+ test/test_helper.rb
33
+ test/task_manager_test.rb
34
+ ]
35
+
36
+ s.test_files = s.files.select { |path| path =~ /^test\/.*_test.rb/ }
37
+
38
+ s.has_rdoc = true
39
+ s.extra_rdoc_files = %w[ README ]
40
+ s.rdoc_options = ['--line-numbers', '--inline-source', '--title', 'Rack::Raker', '--main', 'Rack::Raker']
41
+ end
data/test/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ # A test Rakefile.
2
+ namespace :raker do
3
+ desc 'Namespaced awesome task'
4
+ task :awesome do
5
+ puts 'This task is awesome.'
6
+ end
7
+
8
+ desc 'Do some utility stuff'
9
+ task :util do
10
+ puts 'Doing utility stuff...'
11
+ end
12
+ end
13
+
14
+ desc 'Some other task'
15
+ task :some_task do
16
+ puts 'Some other task.'
17
+ end
@@ -0,0 +1,17 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe TaskManager do
4
+ before(:each) do
5
+ @tasks = ['raker:awesome', 'raker:util', 'some_task']
6
+ @rakefile = File.join(File.dirname(__FILE__), 'Rakefile')
7
+ @manager = TaskManager.new(@rakefile)
8
+ end
9
+
10
+ it 'should return an array of tasks' do
11
+ @manager.tasks.should.equal @tasks
12
+ end
13
+
14
+ it 'should run the given task' do
15
+ @manager.run(@tasks.first).should.not.be false
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'test/spec'
3
+ require File.expand_path("#{File.dirname(__FILE__)}/../lib/rack/raker")
4
+
5
+ include Rack::Raker
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-raker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dale Campbell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-02 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0.4"
24
+ version:
25
+ description: Rack Rake middleware/app.
26
+ email: oshuma@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ files:
34
+ - README
35
+ - Rakefile
36
+ - config.ru
37
+ - rack-raker.gemspec
38
+ - lib/rack/raker.rb
39
+ - lib/rack/raker/app.rb
40
+ - lib/rack/raker/app/views/index.erb
41
+ - lib/rack/raker/app/views/layout.erb
42
+ - lib/rack/raker/app/views/show.erb
43
+ - lib/rack/raker/middleware.rb
44
+ - lib/rack/raker/task_manager.rb
45
+ - test/Rakefile
46
+ - test/test_helper.rb
47
+ - test/task_manager_test.rb
48
+ has_rdoc: true
49
+ homepage: http://oshuma.github.com/rack-raker
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --line-numbers
55
+ - --inline-source
56
+ - --title
57
+ - Rack::Raker
58
+ - --main
59
+ - Rack::Raker
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.3.5
78
+ signing_key:
79
+ specification_version: 2
80
+ summary: Rack Rake middleware/app.
81
+ test_files:
82
+ - test/task_manager_test.rb