corrupt 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/README +22 -0
  2. data/Rakefile +43 -0
  3. data/app/controllers/app_controller.rb +3 -0
  4. data/app/controllers/exceptions.rb +10 -0
  5. data/app/controllers/main.rb +13 -0
  6. data/app/models/page.rb +11 -0
  7. data/app/views/exceptions/404.haml +4 -0
  8. data/app/views/layouts/application.haml +30 -0
  9. data/app/views/main/index.haml +4 -0
  10. data/bin/corrupt +10 -0
  11. data/config.ru +23 -0
  12. data/config/app_config.yml.example +14 -0
  13. data/config/routes.rb +4 -0
  14. data/lib/corrupt.rb +71 -0
  15. data/lib/corrupt/app.rb +11 -0
  16. data/lib/corrupt/client.rb +47 -0
  17. data/lib/corrupt/client/helpers.rb +21 -0
  18. data/lib/corrupt/config.rb +22 -0
  19. data/lib/corrupt/framework/controller.rb +40 -0
  20. data/lib/corrupt/generators.rb +8 -0
  21. data/lib/corrupt/generators/app.rb +98 -0
  22. data/lib/corrupt/router.rb +36 -0
  23. data/lib/corrupt/system.rb +57 -0
  24. data/lib/corrupt/template.rb +34 -0
  25. data/public/favicon.ico +0 -0
  26. data/public/images/ruby-powered.png +0 -0
  27. data/public/index.haml +3 -0
  28. data/public/javascripts/application.js +1 -0
  29. data/public/stylesheets/application.css +103 -0
  30. data/spec/app/app_spec_helper.rb +1 -0
  31. data/spec/app/controllers/app_controller_spec.rb +12 -0
  32. data/spec/app/controllers/main_spec.rb +12 -0
  33. data/spec/app/models/page_spec.rb +14 -0
  34. data/spec/lib/corrupt/app_spec.rb +16 -0
  35. data/spec/lib/corrupt/config_spec.rb +7 -0
  36. data/spec/lib/corrupt/generators/app_spec.rb +15 -0
  37. data/spec/lib/corrupt/router_spec.rb +12 -0
  38. data/spec/lib/corrupt/system_spec.rb +8 -0
  39. data/spec/lib/corrupt/template_spec.rb +4 -0
  40. data/spec/lib/corrupt_spec.rb +19 -0
  41. data/spec/lib/lib_spec_helper.rb +1 -0
  42. data/spec/rcov.opts +1 -0
  43. data/spec/spec.opts +4 -0
  44. data/spec/spec_helper.rb +30 -0
  45. data/tasks/app.rake +28 -0
  46. data/tasks/gem.rake +28 -0
  47. data/tasks/notes.rake +11 -0
  48. data/tasks/spec.rake +25 -0
  49. data/tasks/util.rake +6 -0
  50. metadata +103 -0
data/README ADDED
@@ -0,0 +1,22 @@
1
+ = Corrupt
2
+
3
+ Bare-bones Rack based MVC framework.
4
+
5
+ So many buzz-words, it could kill a baby seal.
6
+
7
+ == Getting Started
8
+
9
+ This will generate a new application:
10
+
11
+ $ corrupt -n /path/to/kickass_app
12
+ $ cd /path/to/kickass_app
13
+
14
+ Then just copy and edit the example app_config.yml:
15
+
16
+ $ cp config/app_config.yml.example config/app_config.yml
17
+ $ $EDITOR config/app_config.yml
18
+
19
+ Now start the server (through Rack):
20
+
21
+ $ rake run:rackup
22
+
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ task :default => 'spec'
2
+
3
+ task :environment do
4
+ ENV['CORRUPT_ENV'] ||= 'development'
5
+ begin
6
+ require 'corrupt'
7
+ rescue LoadError
8
+ # TODO: This might get moved to /vendor or some shit.
9
+ require File.dirname(__FILE__) + '/lib/corrupt'
10
+ end
11
+ Corrupt.boot!
12
+ end
13
+
14
+ FileList['tasks/**/*.rake'].each { |task| load task }
15
+
16
+ desc 'Open a console with the library loaded'
17
+ task :console do
18
+ lib_dir = File.join(File.dirname(__FILE__), 'lib')
19
+ sh "irb -I #{lib_dir} -r 'corrupt'"
20
+ end
21
+
22
+ desc 'List the configured routes'
23
+ task :routes => [ :environment ] do
24
+ width = 30
25
+ puts "| Routes for '#{Corrupt.env}' environment |"
26
+ Corrupt::Router.routes.each do |route|
27
+ print "#{route[0]}".ljust(width)
28
+ print "#{route[1].inspect}".rjust(width)
29
+ puts
30
+ end
31
+ end
32
+
33
+ namespace :db do
34
+ desc 'Migrate the database (destructive)'
35
+ task :migrate => [:environment] do
36
+ DataMapper.auto_migrate!
37
+ end
38
+
39
+ desc 'Migrate the database (non-destructive)'
40
+ task :uprade => [:environment] do
41
+ DataMapper.auto_upgrade!
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ # Base controller from which the others inherit.
2
+ class AppController < Corrupt::Controller::Base
3
+ end # AppController
@@ -0,0 +1,10 @@
1
+ # Handles HTTP error status codes.
2
+ class Exceptions < AppController
3
+
4
+ # HTTP 404
5
+ def four_oh_four
6
+ template('exceptions/404.haml')
7
+ return_response(404)
8
+ end
9
+
10
+ end # Exceptions
@@ -0,0 +1,13 @@
1
+ # Handles the home page and various others.
2
+ class Main < AppController
3
+
4
+ # GET /
5
+ def index
6
+ template('main/index.haml')
7
+ return_response do |content|
8
+ # This sets 'title' in the template.
9
+ content.title = 'Main Index'
10
+ end
11
+ end
12
+
13
+ end # Main
@@ -0,0 +1,11 @@
1
+ # This is an application model and will get loaded into the
2
+ # global namespace. Corrupt uses DataMapper by default,
3
+ # however, a model can be any Ruby class.
4
+ class Page
5
+ attr_accessor :title, :content
6
+
7
+ def initialize(title)
8
+ @title = title
9
+ @content = ''
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ %h2 404
2
+
3
+ %p This controller is located here: <code>/app/controllers/exceptions.rb</code>
4
+ %p This template is located here: <code>/app/views/exceptions/404.haml</code>
@@ -0,0 +1,30 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title= Corrupt.config['name']
5
+
6
+ %link{:type => 'text/css', :rel => 'stylesheet', :href => '/stylesheets/application.css'}
7
+
8
+ %body
9
+ #top-background
10
+
11
+ #header
12
+ %h1
13
+ %a{:href => '/'}= Corrupt.config['name']
14
+
15
+ #menu
16
+ %a{:href => '/'} main
17
+ %p
18
+ %a{:href => 'http://www.ruby-lang.org/', :title => 'Ruby Powered'}
19
+ %img{:src => '/images/ruby-powered.png', :alt => 'Ruby Powered'}
20
+
21
+ #content
22
+ = yield
23
+
24
+ #footer
25
+ Your
26
+ %a{:href => '#', :onclick => '; document.getElementById("details").style.display = "block"; return false;'}Application
27
+ Footer
28
+
29
+ %div{:style => 'display: none;', :id => 'details'}
30
+ The application template is located here: <code>/app/views/layouts/application.haml</code>
@@ -0,0 +1,4 @@
1
+ %h2= title
2
+
3
+ %p This controller is located here: <code>/app/controllers/main.rb</code>
4
+ %p This template is located here: <code>/app/views/main/index.haml</code>
data/bin/corrupt ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'rubygems'
6
+ require 'optparse'
7
+ require 'corrupt'
8
+ require 'corrupt/client'
9
+
10
+ Corrupt::Client.run
data/config.ru ADDED
@@ -0,0 +1,23 @@
1
+ require 'rack'
2
+
3
+ # Setup some Rack middleware.
4
+ static_paths = [
5
+ '/favicon.ico',
6
+ '/images',
7
+ '/javascripts',
8
+ '/stylesheets'
9
+ ]
10
+ use Rack::Static, :urls => static_paths, :root => 'public'
11
+
12
+ # Corrupt this motherfucker.
13
+ ENV['CORRUPT_ENV'] ||= 'production'
14
+
15
+ begin
16
+ require 'corrupt'
17
+ rescue LoadError
18
+ # TODO: This might get moved to /vendor or some shit.
19
+ require File.join(File.dirname(__FILE__), 'lib', 'corrupt')
20
+ end
21
+
22
+ Corrupt.boot!
23
+ run Corrupt::App
@@ -0,0 +1,14 @@
1
+ defaults: &defaults
2
+ name: CorruptApp
3
+ database: db/development.sqlite3
4
+
5
+ development:
6
+ <<: *defaults
7
+
8
+ test:
9
+ <<: *defaults
10
+ database: db/test.sqlite3
11
+
12
+ production:
13
+ <<: *defaults
14
+ database: db/production.sqlite3
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ # URL routes for the application.
2
+ Corrupt::Router.new do |route|
3
+ route.map '/', :controller => 'Main', :action => 'index'
4
+ end
data/lib/corrupt.rb ADDED
@@ -0,0 +1,71 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
2
+
3
+ # Dependencies.
4
+ begin
5
+ require 'dm-core'
6
+ require 'dm-timestamps'
7
+ require 'haml'
8
+ require 'logger'
9
+ require 'maruku'
10
+ require 'singleton'
11
+ require 'sqlite3'
12
+ require 'yaml'
13
+ rescue LoadError => error
14
+ $stderr.puts error
15
+ end
16
+
17
+ # Corrupt core libraries.
18
+ require 'corrupt/app'
19
+ require 'corrupt/config'
20
+ require 'corrupt/router'
21
+ require 'corrupt/system'
22
+ require 'corrupt/template'
23
+
24
+ # Corrupt generators.
25
+ require 'corrupt/generators'
26
+
27
+ # Corrupt framework libraries.
28
+ require 'corrupt/framework/controller'
29
+
30
+ module Corrupt
31
+ VERSION = '0.3.4'
32
+
33
+ # Setup the Corrupt environment.
34
+ def self.boot!
35
+ Corrupt::System.boot!
36
+ end
37
+
38
+ # Output a version string.
39
+ def self.to_version
40
+ "Corrupt v#{VERSION}"
41
+ end
42
+
43
+ private
44
+
45
+ def self.app_root
46
+ ENV['CORRUPT_APP'] || File.join(Dir.pwd, 'app')
47
+ end
48
+
49
+ def self.config
50
+ Corrupt::Config
51
+ end
52
+
53
+ def self.config_file
54
+ ENV['CORRUPT_CONFIG'] || Corrupt.app_root + '/../config/app_config.yml'
55
+ end
56
+
57
+ def self.env
58
+ ENV['CORRUPT_ENV'] || 'development'
59
+ end
60
+
61
+ def self.log
62
+ @log ||= Logger.new("#{Corrupt.app_root}/../log/#{Corrupt.env}.log")
63
+ @log.level = (Corrupt.env == 'production' ? Logger::WARN : Logger::DEBUG)
64
+ @log
65
+ end
66
+
67
+ def self.root
68
+ ENV['CORRUPT_ROOT'] || File.expand_path(File.dirname(__FILE__) + '/..')
69
+ end
70
+
71
+ end # Corrupt
@@ -0,0 +1,11 @@
1
+ module Corrupt
2
+
3
+ # This is the main Rack app, which is ran through
4
+ # run Corrupt::App
5
+ class App
6
+ def self.call(env)
7
+ Router.dispatch(env['PATH_INFO'])
8
+ end
9
+ end # App
10
+
11
+ end # Corrupt
@@ -0,0 +1,47 @@
1
+ module Corrupt
2
+ autoload :ClientHelpers, 'corrupt/client/helpers'
3
+
4
+ class Client
5
+ include ClientHelpers
6
+
7
+ def initialize(argv = ARGV)
8
+ @argv = argv
9
+ @options = {}
10
+ end
11
+
12
+ def self.run
13
+ new.run
14
+ end
15
+
16
+ def run
17
+ input = OptionParser.new do |opts|
18
+ opts.banner = "Usage: #{File.basename($0)} [options]"
19
+
20
+ opts.on("--debug", "Turn on debugging output.") do |debug|
21
+ $DEBUG = @options[:debug] = debug
22
+ end
23
+
24
+ opts.on("-n <path>", "--new", "Create a new Corrupt application.") do |path|
25
+ @options[:path] = path
26
+ end
27
+
28
+ opts.on("-v", "--version", "Print the version.") do |v|
29
+ output(Corrupt.to_version)
30
+ exit
31
+ end
32
+ end
33
+
34
+ begin
35
+ @argv << '--help' if @argv.empty?
36
+ input.parse!(@argv)
37
+ take_action!
38
+ rescue OptionParser::InvalidOption => error
39
+ error("#{error}\nTry passing '--help'")
40
+ rescue OptionParser::MissingArgument => error
41
+ error("#{error}\nTry passing '--help'")
42
+ end
43
+ end
44
+
45
+ end # Client
46
+
47
+ end # Corrupt
@@ -0,0 +1,21 @@
1
+ module Corrupt
2
+ module ClientHelpers
3
+
4
+ # Output an error message to +stream+ (defaults to $stderr).
5
+ def error(message, stream = $stderr)
6
+ stream.puts message
7
+ end
8
+
9
+ # Output +string+ to +opts[:stream]+ using +opts[:method]+.
10
+ def output(string, opts = {})
11
+ opts[:method] ||= 'puts'
12
+ opts[:stream] ||= $stdout
13
+ opts[:stream].send(opts[:method], string)
14
+ end
15
+
16
+ def take_action!
17
+ Corrupt::Generators::App.new(@options[:path]) if @options[:path]
18
+ end
19
+
20
+ end # ClientHelpers
21
+ end # Corrupt
@@ -0,0 +1,22 @@
1
+ module Corrupt
2
+
3
+ # Singleton class to store Corrupt configuration.
4
+ class Config
5
+ include Singleton
6
+
7
+ attr_accessor :options
8
+
9
+ # Access the configured +key+'s value.
10
+ def self.[](key)
11
+ raise 'Config not setup' unless @setup
12
+ instance.options[key]
13
+ end
14
+
15
+ # Setup Config with the YAML +file+.
16
+ def self.setup(file)
17
+ instance.options = YAML.load_file(file)[Corrupt.env]
18
+ @setup = true
19
+ end
20
+ end # Config
21
+
22
+ end # Corrupt
@@ -0,0 +1,40 @@
1
+ module Corrupt
2
+ module Controller
3
+
4
+ class Base
5
+ attr_writer :headers
6
+
7
+ # Return the content (string) to be rendered.
8
+ def content
9
+ @content
10
+ end
11
+
12
+ # Set the content to be rendered.
13
+ def content=(new_content)
14
+ @content = new_content
15
+ headers['Content-Length'] = content.size.to_s
16
+ end
17
+
18
+ # Return the headers for the response.
19
+ def headers
20
+ { 'Content-Length' => content.size.to_s,
21
+ 'Content-Type' => 'text/html' }
22
+ end
23
+
24
+ # Return the full Rack response in this format:
25
+ # [status, headers, content]
26
+ # An optional +status+ may be passed; defaults to 200.
27
+ def return_response(status = 200)
28
+ yield template if block_given?
29
+ self.content = template.render
30
+ [status, headers, content]
31
+ end
32
+
33
+ # Set the template to be rendered.
34
+ def template(file = nil)
35
+ @template ||= Corrupt::Template.new(file)
36
+ end
37
+ end # Base
38
+
39
+ end # Controller
40
+ end # Corrupt
@@ -0,0 +1,8 @@
1
+
2
+ module Corrupt
3
+
4
+ module Generators
5
+ autoload :App, 'corrupt/generators/app'
6
+ end # Generators
7
+
8
+ end # Corrupt
@@ -0,0 +1,98 @@
1
+ module Corrupt
2
+ module Generators
3
+ # autoload :Fileutils, 'fileutils'
4
+
5
+ class App
6
+
7
+ # A list of directories to create when making a new application.
8
+ DIRS = [
9
+ 'app',
10
+ 'app/controllers',
11
+ 'app/models',
12
+ 'app/views',
13
+ 'app/views/exceptions',
14
+ 'app/views/layouts',
15
+ 'app/views/main',
16
+ 'config',
17
+ 'db',
18
+ 'log',
19
+ 'public',
20
+ 'public/images',
21
+ 'public/javascripts',
22
+ 'public/stylesheets',
23
+ 'spec',
24
+ 'spec/app',
25
+ 'spec/app/controllers',
26
+ 'spec/app/models',
27
+ 'tasks',
28
+ 'tmp',
29
+ ]
30
+
31
+ # A list of files to copy for a new application.
32
+ FILES = [
33
+ 'config.ru',
34
+ 'Rakefile',
35
+ 'README',
36
+ 'app/controllers/app_controller.rb',
37
+ 'app/controllers/exceptions.rb',
38
+ 'app/controllers/main.rb',
39
+ 'app/models/page.rb',
40
+ 'app/views/exceptions/404.haml',
41
+ 'app/views/layouts/application.haml',
42
+ 'app/views/main/index.haml',
43
+ 'config/app_config.yml.example',
44
+ 'config/routes.rb',
45
+ 'public/images/ruby-powered.png',
46
+ 'public/javascripts/application.js',
47
+ 'public/stylesheets/application.css',
48
+ 'public/favicon.ico',
49
+ 'public/index.haml',
50
+ 'spec/app/controllers/app_controller_spec.rb',
51
+ 'spec/app/controllers/main_spec.rb',
52
+ 'spec/app/models/page_spec.rb',
53
+ 'spec/app/app_spec_helper.rb',
54
+ 'spec/rcov.opts',
55
+ 'spec/spec.opts',
56
+ 'spec/spec_helper.rb',
57
+ 'tasks/app.rake',
58
+ 'tasks/gem.rake',
59
+ 'tasks/notes.rake',
60
+ 'tasks/spec.rake',
61
+ 'tasks/util.rake',
62
+ ]
63
+
64
+ def initialize(path)
65
+ @path = File.expand_path(path)
66
+ setup_app!
67
+ end
68
+
69
+ private
70
+
71
+ def setup_app!
72
+ Dir.mkdir(@path) unless File.exists?(@path)
73
+ create_directories
74
+ copy_files
75
+ end
76
+
77
+ def create_directories
78
+ DIRS.each do |dir|
79
+ Dir.mkdir(File.join(@path, dir))
80
+ end
81
+ end
82
+
83
+ def copy_files
84
+ FILES.each do |file|
85
+ base_file = File.expand_path(File.join(Corrupt.root, file))
86
+ Dir.chdir(@path) do |app_root|
87
+ base_path = File.dirname(file)
88
+ destination = File.join(app_root, file)
89
+ copy_command = "cp #{base_file} #{destination}"
90
+ %x/#{copy_command}/
91
+ end
92
+ end
93
+ end
94
+
95
+ end # App
96
+
97
+ end # Generators
98
+ end # Corrupt
@@ -0,0 +1,36 @@
1
+ module Corrupt
2
+
3
+ # Handles URL dispatching for the application.
4
+ # Routes are stored in a class variable, accessible by Router.routes.
5
+ class Router
6
+ def initialize(&block)
7
+ @@routes = []
8
+ yield self if block_given?
9
+ end
10
+
11
+ # Maps incoming URLs to a controller and action.
12
+ # TODO: Maybe change the routes storage to a hash like:
13
+ # @@routes[path] # => options
14
+ def map(path, options)
15
+ @@routes << [path, options]
16
+ end
17
+
18
+ # Return the configured routes.
19
+ def self.routes
20
+ @@routes
21
+ end
22
+
23
+ # Dispatch a request to a controller and action.
24
+ def self.dispatch(path)
25
+ route = @@routes.select { |route| route[0] == path }.flatten
26
+ # FIXME: This could probably be handled a little better.
27
+ if route.empty?
28
+ Exceptions.new.four_oh_four
29
+ else
30
+ response = route[1] # 2nd element is the controller/action hash.
31
+ Corrupt::Controller.const_get(response[:controller]).new.send(response[:action])
32
+ end
33
+ end
34
+ end
35
+
36
+ end # Corrupt
@@ -0,0 +1,57 @@
1
+ module Corrupt
2
+
3
+ # This class is responsible for setting up the Corrupt environment.
4
+ class System
5
+ def initialize
6
+ load_app_config
7
+ end
8
+
9
+ # Class wrapper to the boot! instance method.
10
+ def self.boot!
11
+ new.boot!
12
+ end
13
+
14
+ # Setup the Corrupt environment.
15
+ def boot!
16
+ load_models
17
+ load_controllers
18
+ prepare_router
19
+ setup_database
20
+ end
21
+
22
+ private
23
+
24
+ def load_app_config
25
+ Corrupt::Config.setup(Corrupt.config_file)
26
+ end
27
+
28
+ def load_controllers
29
+ app_controller = "#{Corrupt.app_root}/controllers/app_controller.rb"
30
+ controllers = Dir["#{Corrupt.app_root}/controllers/*.rb"].sort
31
+ # Load AppController first...
32
+ require controllers.delete(app_controller)
33
+ # ...now the rest.
34
+ controllers.each do |controller|
35
+ require controller
36
+ end
37
+ end
38
+
39
+ def load_models
40
+ models = Dir["#{Corrupt.app_root}/models/*.rb"].sort
41
+ models.each do |model|
42
+ require model
43
+ end
44
+ end
45
+
46
+ def prepare_router
47
+ load File.join(Corrupt.root, 'config', 'routes.rb')
48
+ end
49
+
50
+ def setup_database
51
+ database = File.join(Corrupt.root, Corrupt::Config['database'])
52
+ DataMapper.setup(:default, "sqlite3:///#{database}")
53
+ end
54
+
55
+ end # System
56
+
57
+ end # Corrupt
@@ -0,0 +1,34 @@
1
+ module Corrupt
2
+
3
+ class Template
4
+ # TODO: Maybe parameterize the layout option?
5
+ def initialize(file)
6
+ # FIXME: This is rather ugly; maybe raise a 'view not found' exception?
7
+ if file
8
+ view_path = File.join(Corrupt.app_root, 'views')
9
+ @file = File.join(view_path, file)
10
+ else
11
+ @file = File.join(Corrupt.root, 'public', 'index.haml')
12
+ end
13
+ @layout = File.join(Corrupt.app_root, 'views', 'layouts', 'application.haml')
14
+ @variables = {}
15
+ end
16
+
17
+ def method_missing(name, *args)
18
+ # Trip the trailing '='
19
+ name = name.to_s.gsub!(/[=]$/, '')
20
+ @variables[name] = args
21
+ end
22
+
23
+ # Renders the file with any variables and returns an HTML string.
24
+ # Wraps the file inside of the layout.
25
+ def render
26
+ wrap = Haml::Engine.new(File.read(@layout))
27
+ wrap.render do
28
+ engine = Haml::Engine.new(File.read(@file))
29
+ engine.render(Object.new, @variables)
30
+ end
31
+ end
32
+ end # Template
33
+
34
+ end # Corrupt
File without changes
Binary file
data/public/index.haml ADDED
@@ -0,0 +1,3 @@
1
+ %h2 Index
2
+
3
+ %p Here lies /public/index.haml
@@ -0,0 +1 @@
1
+ // Application Javascript goes here.
@@ -0,0 +1,103 @@
1
+ /* Corrupt default styles. */
2
+
3
+ * {
4
+ color: #333;
5
+ }
6
+
7
+ body {
8
+ background-color: #eee;
9
+ font-family: 'Arial', 'MS Trebuchet', sans-serif;
10
+ }
11
+
12
+ #top-background {
13
+ position: fixed;
14
+ top: 0;
15
+ background-color: #eee;
16
+ height: 100px;
17
+ width: 100%;
18
+ z-index: 50;
19
+ }
20
+
21
+ #header {
22
+ position: fixed;
23
+ top: 0;
24
+ left: 135px;
25
+ z-index: 100;
26
+ }
27
+
28
+ h1 {
29
+ font-size: 4em;
30
+ letter-spacing: 0.1em;
31
+ margin: 0;
32
+ text-align: center;
33
+ }
34
+
35
+ h1 > a {
36
+ text-decoration: none;
37
+ }
38
+
39
+ h1 > a:hover {
40
+ border-bottom: 1px dashed #888;
41
+ }
42
+
43
+ h2 {
44
+ font-size: 2em;
45
+ text-align: center;
46
+ }
47
+
48
+ p {
49
+ line-height: 1.5em;
50
+ text-align: center;
51
+ }
52
+
53
+ p:first-letter {
54
+ border-bottom: 1px solid #888;
55
+ font-family: 'Times', serif;
56
+ font-size: 1.5em;
57
+ }
58
+
59
+ p > a {
60
+ border-bottom: 1px dashed #888;
61
+ font-weight: bold;
62
+ padding-bottom: 1px;
63
+ text-decoration: none;
64
+ }
65
+
66
+ p > a:hover {
67
+ border-bottom: 1px solid #888;
68
+ }
69
+
70
+ #menu {
71
+ position: fixed;
72
+ top: 0;
73
+ left: 0;
74
+ background-color: #ddd;
75
+ border-right: 1px solid #333;
76
+ font-size: 25px;
77
+ margin: 0.5em;
78
+ padding: 0.5em;
79
+ z-index: 100;
80
+
81
+ opacity: .80;
82
+ filter: alpha(opacity=80);
83
+ -moz-opacity: 0.80;
84
+ }
85
+
86
+ #menu a {
87
+ display: block;
88
+ text-decoration: none;
89
+ }
90
+
91
+ #menu a:hover {
92
+ border-bottom: 1px dashed #888;
93
+ }
94
+
95
+ #content {
96
+ margin-top: 100px;
97
+ }
98
+
99
+ #footer {
100
+ font-size: 0.75em;
101
+ margin: 0 auto;
102
+ text-align: center;
103
+ }
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../app_spec_helper')
2
+
3
+ describe AppController do
4
+ before(:each) do
5
+ @controller = AppController.new
6
+ end
7
+
8
+ it 'should return a default response' do
9
+ @response = @controller.return_response
10
+ @response.size.should == 3
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../app_spec_helper')
2
+
3
+ describe Main do
4
+ before(:each) do
5
+ @controller = Main.new
6
+ end
7
+
8
+ it 'should respond to the index action' do
9
+ @response = @controller.index
10
+ @response[0].should == 200
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../app_spec_helper')
2
+
3
+ describe Page do
4
+ it 'should have title and content accessors' do
5
+ title = 'Kickass Page'
6
+ content = "This is some bitchin' content."
7
+
8
+ page = Page.new(title)
9
+ page.content = content
10
+
11
+ page.title.should == title
12
+ page.content.should == content
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../lib_spec_helper')
2
+
3
+ describe App do
4
+ it 'should return a proper Rack response: [status, headers, content]' do
5
+ @response = get('/')
6
+ @response.size.should == 3
7
+ @response[0].should be_instance_of(Fixnum)
8
+ @response[1].should be_instance_of(Hash)
9
+ @response[2].should be_instance_of(String)
10
+ end
11
+
12
+ it 'should return a 404 status' do
13
+ @response = get('/not/a/real/path')
14
+ @response[0].should == 404
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../lib_spec_helper')
2
+
3
+ describe Config do
4
+ it 'should have a name' do
5
+ Corrupt::Config['name'].should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../lib_spec_helper')
2
+
3
+ require 'fileutils'
4
+
5
+ describe Generators::App do
6
+ before(:each) do
7
+ @path = '/tmp/test_corrupt_app'
8
+ FileUtils.rm_r(@path) if File.exists?(@path)
9
+ end
10
+
11
+ it 'should create the new directory' do
12
+ Generators::App.new(@path)
13
+ File.exists?(@path).should be_true
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../lib_spec_helper')
2
+
3
+ describe Router do
4
+ before(:each) do
5
+ @router = Router.new
6
+ end
7
+
8
+ it 'should store the configured routes' do
9
+ @router.map '/', :controller => 'Main', :action => 'index'
10
+ Router.routes.size.should == 1
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../lib_spec_helper')
2
+
3
+ describe System do
4
+ it 'should boot and load the config' do
5
+ System.boot!
6
+ Corrupt::Config.should_not be_nil
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../lib_spec_helper')
2
+
3
+ describe Template do
4
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/lib_spec_helper')
2
+
3
+ describe Corrupt do
4
+ it 'should have a version string' do
5
+ Corrupt.to_version.should_not be_nil
6
+ end
7
+
8
+ it 'should have an environment' do
9
+ Corrupt.env.should == 'test'
10
+ end
11
+
12
+ it 'should have a configuration accessor' do
13
+ Corrupt.config.should_not be_nil
14
+ end
15
+
16
+ it 'should have a logger' do
17
+ Corrupt.log.should_not be_nil
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
data/spec/rcov.opts ADDED
@@ -0,0 +1 @@
1
+ --exclude "spec/*,gems/*"
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ begin
5
+ require 'corrupt'
6
+ rescue LoadError
7
+ # TODO: Might move this to /vendor or some shit.
8
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/corrupt')
9
+ end
10
+
11
+ ENV['CORRUPT_ENV'] = 'test'
12
+ Corrupt.boot!
13
+
14
+ module RequestHelpers
15
+ # Send a GET request through the stack.
16
+ def get(path)
17
+ env = {'PATH_INFO' => path}
18
+ Corrupt::App.call(env)
19
+ end
20
+ end
21
+
22
+ Spec::Runner.configure do |config|
23
+ include Corrupt
24
+
25
+ config.include RequestHelpers
26
+
27
+ config.before(:all) do
28
+ DataMapper.auto_migrate!
29
+ end
30
+ end
data/tasks/app.rake ADDED
@@ -0,0 +1,28 @@
1
+ desc 'Start the server with rackup'
2
+ task :run => 'run:rackup'
3
+
4
+ namespace :run do
5
+ task :setup => [ :environment ] do
6
+ require 'rack'
7
+ @application = Corrupt::App
8
+ @options = { :Host => '127.0.0.1', :Port => 9292 }
9
+ end
10
+
11
+ desc 'Start the server with rackup'
12
+ task :rackup => [ :environment ] do
13
+ config = File.join(Corrupt.root, 'config.ru')
14
+ sh "rackup #{config}"
15
+ end
16
+
17
+ desc 'Start the server with Mongrel handler'
18
+ task :mongrel => [ :environment, :setup ] do
19
+ puts 'Starting with Mongrel handler...'
20
+ Rack::Handler::Mongrel.run @application, @options
21
+ end
22
+
23
+ desc 'Start the server with Thin handler'
24
+ task :thin => [ :environment, :setup ] do
25
+ puts 'Starting with Thin handler...'
26
+ Rack::Handler::Thin.run @application, @options
27
+ end
28
+ end
data/tasks/gem.rake ADDED
@@ -0,0 +1,28 @@
1
+ ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..'))
2
+ GEMSPEC = ROOT_DIR + '/corrupt.gemspec'
3
+
4
+ namespace :gem do
5
+ desc 'Build the gem'
6
+ task :build do
7
+ sh "gem build #{GEMSPEC}"
8
+ end
9
+
10
+ desc 'Clean the built gem'
11
+ task :clean do
12
+ sh "rm -f #{ROOT_DIR}/*.gem"
13
+ end
14
+
15
+ desc 'Clean, rebuild and install the gem'
16
+ task :install => [ :clean, :build ] do
17
+ gem = FileList["#{ROOT_DIR}/*.gem"].first
18
+ sudo = RUBY_PLATFORM !~ /win32/ ? "sudo" : ""
19
+ begin
20
+ sh "#{sudo} gem uninstall corrupt"
21
+ rescue
22
+ end
23
+ sh "#{sudo} gem install #{gem}"
24
+ end
25
+
26
+ desc 'Clean and rebuild the gem'
27
+ task :rebuild => [ :clean, :build ]
28
+ end
data/tasks/notes.rake ADDED
@@ -0,0 +1,11 @@
1
+ namespace :notes do
2
+ desc 'List all TODO notes'
3
+ task :fixme do
4
+ sh 'find ./ -type f -exec grep -Hn --color FIXME {} \;'
5
+ end
6
+
7
+ desc 'List all TODO notes'
8
+ task :todo do
9
+ sh 'find ./ -type f -exec grep -Hn --color TODO {} \;'
10
+ end
11
+ end
data/tasks/spec.rake ADDED
@@ -0,0 +1,25 @@
1
+ require 'spec/rake/spectask'
2
+
3
+ desc 'Run the specs'
4
+ Spec::Rake::SpecTask.new(:spec) do |t|
5
+ t.spec_opts = ['--options', 'spec/spec.opts']
6
+ t.spec_files = FileList['spec/**/*_spec.rb']
7
+ end
8
+
9
+ desc 'Run the specs with autotest'
10
+ task :autotest do
11
+ ENV['RSPEC'] = 'true'
12
+ sh "autotest"
13
+ end
14
+
15
+ namespace :spec do
16
+ desc 'Generate code coverage'
17
+ Spec::Rake::SpecTask.new(:rcov) do |t|
18
+ t.spec_opts = ['--options', 'spec/spec.opts']
19
+ t.spec_files = FileList['spec/**/*_spec.rb']
20
+ t.rcov = true
21
+ t.rcov_opts = lambda do
22
+ IO.readlines('spec/rcov.opts').map {|l| l.chomp.split ' '}.flatten
23
+ end
24
+ end
25
+ end
data/tasks/util.rake ADDED
@@ -0,0 +1,6 @@
1
+ namespace :util do
2
+ desc 'Setup the development environment'
3
+ task :setup_dev do
4
+ Rake::Task['db:migrate'].invoke
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: corrupt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.4
5
+ platform: ruby
6
+ authors:
7
+ - Dale Campbell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-17 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: No nonsense Rack-based framework.
17
+ email:
18
+ - dale@save-state.net
19
+ executables:
20
+ - corrupt
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - Rakefile
27
+ - README
28
+ - app/controllers/app_controller.rb
29
+ - app/controllers/exceptions.rb
30
+ - app/controllers/main.rb
31
+ - app/models/page.rb
32
+ - app/views/exceptions/404.haml
33
+ - app/views/layouts/application.haml
34
+ - app/views/main/index.haml
35
+ - config.ru
36
+ - config/app_config.yml.example
37
+ - config/routes.rb
38
+ - lib/corrupt/app.rb
39
+ - lib/corrupt/client/helpers.rb
40
+ - lib/corrupt/client.rb
41
+ - lib/corrupt/config.rb
42
+ - lib/corrupt/framework/controller.rb
43
+ - lib/corrupt/generators/app.rb
44
+ - lib/corrupt/generators.rb
45
+ - lib/corrupt/router.rb
46
+ - lib/corrupt/system.rb
47
+ - lib/corrupt/template.rb
48
+ - lib/corrupt.rb
49
+ - public/images/ruby-powered.png
50
+ - public/javascripts/application.js
51
+ - public/stylesheets/application.css
52
+ - public/favicon.ico
53
+ - public/index.haml
54
+ - spec/app/app_spec_helper.rb
55
+ - spec/app/controllers/app_controller_spec.rb
56
+ - spec/app/controllers/main_spec.rb
57
+ - spec/app/models/page_spec.rb
58
+ - spec/lib/corrupt/app_spec.rb
59
+ - spec/lib/corrupt/config_spec.rb
60
+ - spec/lib/corrupt/generators/app_spec.rb
61
+ - spec/lib/corrupt/router_spec.rb
62
+ - spec/lib/corrupt/system_spec.rb
63
+ - spec/lib/corrupt/template_spec.rb
64
+ - spec/lib/corrupt_spec.rb
65
+ - spec/lib/lib_spec_helper.rb
66
+ - spec/rcov.opts
67
+ - spec/spec.opts
68
+ - spec/spec_helper.rb
69
+ - tasks/app.rake
70
+ - tasks/gem.rake
71
+ - tasks/notes.rake
72
+ - tasks/spec.rake
73
+ - tasks/util.rake
74
+ has_rdoc: false
75
+ homepage: http://corrupt.save-state.net/
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options: []
80
+
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ requirements: []
96
+
97
+ rubyforge_project: corrupt
98
+ rubygems_version: 1.3.2
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Rack-based MVC framework.
102
+ test_files: []
103
+