merb 0.0.9 → 0.1.0

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/README CHANGED
@@ -1,3 +1,4 @@
1
+ <pre>
1
2
  Copyright (c) 2006 Ezra Zygmuntowicz
2
3
 
3
4
  Merb. Mongrel+Erb
@@ -246,3 +247,4 @@ merb_app:
246
247
  public
247
248
  plugins
248
249
  schema
250
+ </pre>
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ include FileUtils
15
15
 
16
16
 
17
17
  NAME = "merb"
18
- VERS = "0.0.9"
18
+ VERS = "0.1.0"
19
19
  CLEAN.include ['**/.*.sw?', '*.gem', '.config']
20
20
  RDOC_OPTS = ['--quiet', '--title', "Merb Documentation",
21
21
  "--opname", "index.html",
Binary file
@@ -0,0 +1,82 @@
1
+ require 'rake'
2
+ require 'rake/rdoctask'
3
+ require 'rake/testtask'
4
+ require 'code_statistics'
5
+ require 'fileutils'
6
+ require 'rubygems'
7
+ require 'merb'
8
+ require MERB_FRAMEWORK_ROOT+'/merb_tasks'
9
+ MERB_ROOT = File.dirname(__FILE__)
10
+ include FileUtils
11
+
12
+
13
+ #desc "Packages up Merb."
14
+ #task :default => [:package]
15
+
16
+ desc "load merb_init.rb"
17
+ task :merb_init do
18
+ require 'merb'
19
+ require File.dirname(__FILE__)+'/dist/conf/merb_init.rb'
20
+ end
21
+
22
+ desc "Load db schema"
23
+ task :load_schema => [:merb_init] do
24
+ require File.dirname(__FILE__)+'/dist/schema/schema.rb'
25
+ end
26
+
27
+ task :uninstall => [:clean] do
28
+ sh %{sudo gem uninstall #{NAME}}
29
+ end
30
+
31
+ desc 'Run unit tests'
32
+ Rake::TestTask.new('test_unit') do |t|
33
+ t.libs << 'test'
34
+ t.pattern = 'test/unit/*_test.rb'
35
+ t.verbose = true
36
+ end
37
+
38
+ desc 'Run functional tests'
39
+ Rake::TestTask.new('test_functional') do |t|
40
+ t.libs << 'test'
41
+ t.pattern = 'test/functional/*_test.rb'
42
+ t.verbose = true
43
+ end
44
+
45
+ desc 'Run all tests'
46
+ Rake::TestTask.new('test') do |t|
47
+ t.libs << 'test'
48
+ t.pattern = 'test/**/*_test.rb'
49
+ t.verbose = true
50
+ end
51
+
52
+ desc 'Run all tests, specs and finish with rcov'
53
+ task :aok do
54
+ sh %{rake rcov}
55
+ sh %{rake spec}
56
+ end
57
+
58
+ ##############################################################################
59
+ # Statistics
60
+ ##############################################################################
61
+
62
+ STATS_DIRECTORIES = [
63
+ %w(Code lib/),
64
+ %w(Unit\ tests test/unit),
65
+ %w(Functional\ tests test/functional)
66
+ ].collect { |name, dir| [ name, "./#{dir}" ] }.select { |name, dir| File.directory?(dir) }
67
+
68
+ desc "Report code statistics (KLOCs, etc) from the application"
69
+ task :stats do
70
+ #require 'extra/stats'
71
+ verbose = true
72
+ CodeStatistics.new(*STATS_DIRECTORIES).to_s
73
+ end
74
+
75
+ ##############################################################################
76
+ # SVN
77
+ ##############################################################################
78
+
79
+ desc "Add new files to subversion"
80
+ task :svn_add do
81
+ system "svn status | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs svn add"
82
+ end
@@ -0,0 +1,3 @@
1
+ # all your other controllers should inherit from this one to share code.ß
2
+ class Application < Merb::Controller
3
+ end
@@ -0,0 +1,5 @@
1
+ module Merb
2
+ module GlobalHelper
3
+ # helpers deinfed here available to all views.
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <title>Fresh Merb App</title>
5
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
6
+ </head>
7
+ <body>
8
+ <div id='content'>
9
+ <%= catch_content :layout %>
10
+ </div>
11
+ </body>
12
+ </html>
@@ -0,0 +1,53 @@
1
+ ---
2
+ # hostname or IP to bind to.
3
+ :host: 127.0.0.1
4
+
5
+ # port merb runs on or starting port for merb cluster.
6
+ :port: "4000"
7
+
8
+ # in development mode your controler classes get reloaded every request
9
+ # and templates are parsed each time and not cached
10
+ # in production mode templates are cached, as well as all your classes
11
+ :environment: development
12
+
13
+ # uncomment for memory sessions. This only works when
14
+ # you are running 1 merb at a time. ANd sessions do not persist
15
+ # between restarts.
16
+ # :memory_session: true
17
+
18
+ # This turns on the ActiveRecord sessions with rails parasite
19
+ # mode if active_support gem is installed. Skeleton app comes with a
20
+ # migration to create the sessions table. Or you can point merb to
21
+ # the same sessions table that your rails app uses to share sessions
22
+ # between merb and rails.
23
+ :sql_session: true
24
+
25
+ # uncomment to use the merb upload progress
26
+ #:config: dist/conf/upload.conf
27
+
28
+ # uncomment to cache templates in dev mode.
29
+ # templates are cached automatically in production mode.
30
+ #:cache_templates: true
31
+
32
+ # uncomment and set this is you want to run a drb
33
+ # server for upload progress or other drb services.
34
+ #:drb_server_port: 32323
35
+
36
+ # If you want to protect some or all of your app with
37
+ # HTTP basic auth then uncomment the folowing and fill
38
+ # in your credentials you want it to use. Then you need
39
+ # to set a before filter in a controller:
40
+ # before :basic_authentication
41
+ #:basic_auth:
42
+ # :username: ezra
43
+ # :password: test
44
+ # :domain: localhost
45
+
46
+ # uncomment this if you want merb to daemonize when you start it
47
+ # you can also just use merb -d for the same effect. Don't uncomment
48
+ # this if you use the cluster option
49
+ #:daemonize: true
50
+
51
+ # uncomment this to set the number of members in your merb cluster
52
+ # don't set this and :daemonize: at the same time.
53
+ #:cluster: 3
@@ -0,0 +1,21 @@
1
+ puts "merb init called"
2
+ require 'active_record'
3
+ ActiveRecord::Base.verification_timeout = 14400
4
+ ActiveRecord::Base.logger = MERB_LOGGER
5
+ Dir[DIST_ROOT+"/app/helpers/*.rb"].each { |m| require m }
6
+ require DIST_ROOT+"/app/controllers/application.rb"
7
+ Dir[DIST_ROOT+"/app/controllers/*.rb"].each { |m| require m }
8
+ Dir[DIST_ROOT+"/app/models/*.rb"].each { |m| require m }
9
+ Dir[DIST_ROOT+"/lib/**/*.rb"].each { |m| require m }
10
+ Dir[DIST_ROOT+"/plugins/*/init.rb"].each { |m| require m }
11
+
12
+ # set your db info here
13
+ ActiveRecord::Base.establish_connection(
14
+ :adapter => 'mysql',
15
+ :username => 'root',
16
+ :password => 'xxxxx',
17
+ :database => 'merb'
18
+ )
19
+
20
+ # add your own ruby code here for app specific stuff. This file gets loaded
21
+ # after the framework is loaded.
@@ -0,0 +1,19 @@
1
+ # Merb::RouteMatcher is the request routing mapper for the merb framework.
2
+ # You can define placeholder parts of the url with the :smbol notation.
3
+ # so r.add '/foo/:bar/baz/:id', :class => 'Bar', :method => 'foo'
4
+ # will match against a request to /foo/123/baz/456. It will then
5
+ # use the class Bar as your merb controller and call the foo method on it.
6
+ # the foo method will recieve a hash with {:bar => '123', :id => '456'}
7
+ # as the content. So the :placeholders sections of your routes become
8
+ # a hash of arguments to your controller methods.
9
+ # The default route is installed
10
+
11
+
12
+ puts "Compiling routes.."
13
+ Merb::RouteMatcher.prepare do |r|
14
+ # default route, usually you don't want to change this
15
+ r.add '/:controller/:action/:id'
16
+
17
+ # change this for your home page to be avaiable at /
18
+ r.add '/', :controller => 'default', :action =>'index'
19
+ end
@@ -0,0 +1,5 @@
1
+ # upload progress conf
2
+ ---
3
+ #:drb: true # uncomment for drb UploadProgress if you run a merb cluster
4
+ :path_info: /files/upload
5
+ :frequency: 2
@@ -0,0 +1,15 @@
1
+ class AddSessionsTable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :sessions, :force => true do |t|
4
+ t.column :id, :integer, :null => false
5
+ t.column :session_id, :string, :limit => 32
6
+ t.column :created_at, :datetime
7
+ t.column :data, :text
8
+ add_index "sessions", ["session_id"], :name => "session_id_index"
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :sessions
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'merb'
4
+
5
+ TMPL = <<EOF
6
+ class <%= class_name.snake_case.camel_case %> < ActiveRecord::Migration
7
+ def self.up
8
+ end
9
+
10
+ def self.down
11
+ end
12
+ end
13
+ EOF
14
+
15
+ class_name = ARGV[0]
16
+ highest_migration = Dir[Dir.pwd+'/dist/schema/migrations/*'].map{|f| File.basename(f) =~ /^(\d+)/; $1}.max
17
+ filename = format("%03d_%s", (highest_migration.to_i+1), class_name.snake_case)
18
+
19
+ File.open(Dir.pwd+"/dist/schema/migrations/#{filename}.rb", 'w+') do |file|
20
+ file.write Erubis::Eruby.new(TMPL).result(binding)
21
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+
4
+ pids=[]
5
+
6
+ port_or_star = ARGV[0] || '*'
7
+
8
+ Dir[File.dirname(__FILE__)+"/../log/merb.#{port_or_star}.pid"].each do |f|
9
+ pid = IO.read(f).chomp.to_i
10
+ puts "killing PID: #{pid}"
11
+ Process.kill(9, pid)
12
+ FileUtils.rm f
13
+ end
@@ -6,13 +6,13 @@ require 'logger'
6
6
 
7
7
  begin
8
8
  require 'fjson'
9
- puts "using fjson"
10
9
  rescue LoadError
11
10
  require 'json'
12
11
  end
13
12
 
13
+
14
14
  module Merb
15
- VERSION='0.0.9' unless defined?VERSION
15
+ VERSION='0.1.0' unless defined?VERSION
16
16
  class Server
17
17
  class << self
18
18
  def config
@@ -93,6 +93,7 @@ class Merb::Controller
93
93
  end
94
94
  require "merb/session/merb_ar_session"
95
95
  include ::Merb::SessionMixin
96
+ Thread.new{ loop{ sleep(60*60); ActiveRecord::Base.verify_active_connections! } }.priority = -10
96
97
  end
97
98
 
98
99
  if Merb::Server.basic_auth
@@ -1,4 +1,5 @@
1
1
  class Module
2
+
2
3
  def alias_method_chain(target, feature)
3
4
  # Strip out punctuation on predicates or bang methods since
4
5
  # e.g. target?_without_feature is not a valid method name.
@@ -7,4 +8,19 @@ class Module
7
8
  alias_method "#{aliased_target}_without_#{feature}#{punctuation}", target
8
9
  alias_method target, "#{aliased_target}_with_#{feature}#{punctuation}"
9
10
  end
11
+
12
+ def attr_initialize(*attrs)
13
+ define_method(:initialize) do |*passed|
14
+ raise ArgumentError, "Wrong number of arguments" \
15
+ unless attrs.size == passed.size
16
+
17
+ attrs.each_with_index do |att, i|
18
+ instance_variable_set("@#{att}", passed[i])
19
+ end
20
+
21
+ after_initialize if respond_to? :after_initialize
22
+ end
23
+ end
24
+
25
+
10
26
  end
@@ -1,3 +1,4 @@
1
+ require 'rubygems'
1
2
  require 'optparse'
2
3
  require 'ostruct'
3
4
  require 'fileutils'
@@ -103,8 +104,8 @@ module Merb
103
104
 
104
105
  def initialize_merb
105
106
  require 'merb'
106
- require @@merb_opts[:merb_root]+'/dist/conf/router.rb'
107
- require @@merb_opts[:merb_root]+'/dist/conf/merb_init.rb'
107
+ require @@merb_opts[:merb_root] / 'dist/conf/router.rb'
108
+ require @@merb_opts[:merb_root] / 'dist/conf/merb_init.rb'
108
109
  end
109
110
 
110
111
  def run
@@ -131,7 +132,10 @@ module Merb
131
132
  $LOAD_PATH.unshift( File.join(@@merb_opts[:dist_root] , '/app/controllers') )
132
133
  $LOAD_PATH.unshift( File.join(@@merb_opts[:dist_root] , '/app/models') )
133
134
  $LOAD_PATH.unshift( File.join(@@merb_opts[:dist_root] , '/lib') )
134
-
135
+ if File.exist? File.join(@@merb_opts[:dist_root] , '/framework')
136
+ $LOAD_PATH.unshift( File.join(@@merb_opts[:dist_root] , '/framework') )
137
+ end
138
+
135
139
  if @@merb_opts[:generate]
136
140
  require 'merb/generators/merb_app/merb_app'
137
141
  ::Merb::AppGenerator.run @@merb_opts[:generate]
@@ -1,4 +1,25 @@
1
- require 'mongrel'
1
+ module Mongrel
2
+ module Const
3
+ POST = 'POST'.freeze unless const_defined?(:POST)
4
+ QUERY_STRING = 'QUERY_STRING'.freeze unless const_defined?(:QUERY_STRING)
5
+ UPLOAD_ID = 'upload_id'.freeze
6
+ end
7
+
8
+ HttpHandler.class_eval do
9
+ def request_aborted(params)
10
+ end
11
+ end
12
+
13
+ HttpRequest.class_eval do
14
+ def initialize_with_abort(params, socket, dispatchers)
15
+ initialize_without_abort(params, socket, dispatchers)
16
+ dispatchers.each {|d| d.request_aborted(params) if @body.nil? && d }
17
+ end
18
+
19
+ alias_method :initialize_without_abort, :initialize
20
+ alias_method :initialize, :initialize_with_abort
21
+ end
22
+ end
2
23
 
3
24
 
4
25
  class MerbUploadHandler < Mongrel::HttpHandler
@@ -29,6 +50,14 @@ class MerbUploadHandler < Mongrel::HttpHandler
29
50
  def process(request, response)
30
51
  upload_notify(:finish, request.params)
31
52
  end
53
+
54
+ def request_aborted(params)
55
+ return unless params[Mongrel::Const::PATH_INFO] == @path_info &&
56
+ params[Mongrel::Const::REQUEST_METHOD] == Mongrel::Const::POST &&
57
+ upload_id = Mongrel::HttpRequest.query_parse(params[Mongrel::Const::QUERY_STRING])[Mongrel::Const::UPLOAD_ID]
58
+ Mongrel::Uploads.finish(upload_id)
59
+ puts "request aborted!"
60
+ end
32
61
 
33
62
  private
34
63
  def upload_notify(action, params, *args)
@@ -1,4 +1,4 @@
1
- taMERB_ROOT = Dir.pwd
1
+ MERB_ROOT = Dir.pwd
2
2
 
3
3
  desc "Setup the Merb Environment by requiring merb and loading your merb_init.rb"
4
4
  task :merb_env do
@@ -0,0 +1,15 @@
1
+ namespace :merb do
2
+ desc "freeze the merb framework into dist/merb for portability"
3
+ task :freeze do
4
+ FileUtils.rm_rf MERB_ROOT / 'dist/framework'
5
+ FileUtils.cp_r MERB_FRAMEWORK_ROOT, (MERB_ROOT / 'dist/framework')
6
+ tmpl = "#!/usr/local/bin/ruby\nrequire File.expand_path(File.dirname(__FILE__)+'/../dist/framework/merb/merb_server')\nMerb::Server.run\n"
7
+ File.open(MERB_ROOT / 'script/merb', 'wb') {|f|
8
+ f.write tmpl
9
+ f.chmod(0744)
10
+ }
11
+
12
+ puts "Freezing Merb Framework into dist/framework"
13
+ puts "Use script/merb to start instead of plain merb"
14
+ end
15
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0.9
3
3
  specification_version: 1
4
4
  name: merb
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.9
7
- date: 2007-01-14 00:00:00 -08:00
6
+ version: 0.1.0
7
+ date: 2007-01-18 00:00:00 -08:00
8
8
  summary: Merb == Mongrel + Erb. Pocket rocket web framework.
9
9
  require_paths:
10
10
  - lib
@@ -82,8 +82,42 @@ files:
82
82
  - lib/merb/vendor/paginator/paginator.rb
83
83
  - lib/merb/vendor/paginator/README.txt
84
84
  - lib/tasks/db.rake
85
+ - lib/tasks/merb.rake
85
86
  - examples/README_EXAMPLES
87
+ - examples/skeleton
86
88
  - examples/skeleton.tar
89
+ - examples/skeleton/dist
90
+ - examples/skeleton/log
91
+ - examples/skeleton/Rakefile
92
+ - examples/skeleton/script
93
+ - examples/skeleton/test
94
+ - examples/skeleton/dist/app
95
+ - examples/skeleton/dist/conf
96
+ - examples/skeleton/dist/lib
97
+ - examples/skeleton/dist/plugins
98
+ - examples/skeleton/dist/public
99
+ - examples/skeleton/dist/schema
100
+ - examples/skeleton/dist/app/controllers
101
+ - examples/skeleton/dist/app/helpers
102
+ - examples/skeleton/dist/app/models
103
+ - examples/skeleton/dist/app/views
104
+ - examples/skeleton/dist/app/controllers/application.rb
105
+ - examples/skeleton/dist/app/helpers/global_helper.rb
106
+ - examples/skeleton/dist/app/views/layout
107
+ - examples/skeleton/dist/app/views/layout/application.herb
108
+ - examples/skeleton/dist/conf/merb.yml
109
+ - examples/skeleton/dist/conf/merb_init.rb
110
+ - examples/skeleton/dist/conf/router.rb
111
+ - examples/skeleton/dist/conf/upload.conf
112
+ - examples/skeleton/dist/public/images
113
+ - examples/skeleton/dist/public/javascripts
114
+ - examples/skeleton/dist/public/stylesheets
115
+ - examples/skeleton/dist/schema/migrations
116
+ - examples/skeleton/dist/schema/migrations/001_add_sessions_table.rb
117
+ - examples/skeleton/script/new_migration
118
+ - examples/skeleton/script/stop_merb
119
+ - examples/skeleton/test/specs
120
+ - examples/skeleton/test/unit
87
121
  test_files: []
88
122
 
89
123
  rdoc_options: