mack 0.6.0.1 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +45 -0
- data/bin/mack +8 -3
- data/lib/mack.rb +2 -57
- data/lib/mack/controller/all_helpers.rb +14 -0
- data/lib/{controller → mack/controller}/controller.rb +7 -1
- data/lib/{controller → mack/controller}/cookie_jar.rb +0 -0
- data/lib/{controller → mack/controller}/filter.rb +0 -0
- data/lib/{controller → mack/controller}/request.rb +0 -0
- data/lib/{controller → mack/controller}/response.rb +0 -0
- data/lib/{controller → mack/controller}/session.rb +0 -0
- data/lib/{controller → mack/controller}/uploaded_file.rb +0 -0
- data/lib/{core_extensions → mack/core_extensions}/kernel.rb +0 -0
- data/lib/{core_extensions → mack/core_extensions}/string.rb +0 -0
- data/lib/{distributed → mack/distributed}/errors/errors.rb +0 -0
- data/lib/{distributed → mack/distributed}/routing/urls.rb +10 -1
- data/lib/{distributed → mack/distributed}/utils/rinda.rb +0 -0
- data/lib/{errors → mack/errors}/errors.rb +4 -0
- data/lib/{generators → mack/generators}/mack_application_generator/mack_application_generator.rb +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/manifest.yml +0 -0
- data/lib/mack/generators/mack_application_generator/templates/Rakefile.template +6 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/app/controllers/default_controller.rb.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/app/helpers/controllers/default_controller_helper.rb.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/app/helpers/views/application_helper.rb.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/app/views/default/index.html.erb.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/app/views/layouts/application.html.erb.template +0 -0
- data/lib/mack/generators/mack_application_generator/templates/config/app_config/default.yml.template +11 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/config/app_config/development.yml.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/config/app_config/production.yml.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/config/app_config/test.yml.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/config/database.yml.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/config/initializers/gems.rb.template +3 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/config/initializers/mime_types.rb.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/config/routes.rb.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/public/favicon.ico.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/public/stylesheets/scaffold.css.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/test/functional/default_controller_spec.rb.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/test/functional/default_controller_test.rb.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/test/spec.opts.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/test/spec_helper.rb.template +0 -0
- data/lib/{generators → mack/generators}/mack_application_generator/templates/test/test_helper.rb.template +0 -0
- data/lib/{generators → mack/generators}/plugin_generator/plugin_generator.rb +0 -0
- data/lib/{generators → mack/generators}/plugin_generator/templates/vendor/plugins/%=@plugin_name%/init.rb.template +0 -0
- data/lib/{generators → mack/generators}/plugin_generator/templates/vendor/plugins/%=@plugin_name%/lib/%=@plugin_name%.rb.template +0 -0
- data/lib/{generators → mack/generators}/plugin_generator/templates/vendor/plugins/%=@plugin_name%/lib/tasks/%=@plugin_name%_tasks.rake.template +0 -0
- data/lib/{initialization → mack/initialization}/application.rb +6 -6
- data/lib/{initialization → mack/initialization}/configuration.rb +7 -2
- data/lib/{initialization → mack/initialization}/console.rb +1 -1
- data/lib/{initialization → mack/initialization}/helpers.rb +1 -1
- data/lib/{initialization → mack/initialization}/logging.rb +25 -0
- data/lib/mack/initialization/orm_support.rb +20 -0
- data/lib/{initialization → mack/initialization}/plugins.rb +0 -0
- data/lib/{initialization → mack/initialization}/server/simple_server.rb +0 -0
- data/lib/{rendering → mack/rendering}/engine/base.rb +0 -0
- data/lib/{rendering → mack/rendering}/engine/builder.rb +0 -0
- data/lib/{rendering → mack/rendering}/engine/erubis.rb +0 -0
- data/lib/{rendering → mack/rendering}/engine/registry.rb +0 -0
- data/lib/{rendering → mack/rendering}/type/action.rb +0 -0
- data/lib/{rendering → mack/rendering}/type/base.rb +0 -0
- data/lib/{rendering → mack/rendering}/type/file_base.rb +0 -0
- data/lib/{rendering → mack/rendering}/type/inline.rb +0 -0
- data/lib/{rendering → mack/rendering}/type/layout.rb +0 -0
- data/lib/{rendering → mack/rendering}/type/partial.rb +0 -0
- data/lib/{rendering → mack/rendering}/type/public.rb +0 -0
- data/lib/{rendering → mack/rendering}/type/template.rb +0 -0
- data/lib/{rendering → mack/rendering}/type/text.rb +0 -0
- data/lib/{rendering → mack/rendering}/type/url.rb +0 -0
- data/lib/{rendering → mack/rendering}/type/xml.rb +0 -0
- data/lib/{rendering → mack/rendering}/view_template.rb +0 -0
- data/lib/{routing → mack/routing}/route_map.rb +1 -7
- data/lib/{routing → mack/routing}/urls.rb +0 -0
- data/lib/mack/runner.rb +121 -0
- data/lib/mack/runner_helpers/base.rb +13 -0
- data/lib/mack/runner_helpers/registry.rb +13 -0
- data/lib/mack/runner_helpers/request_logger.rb +32 -0
- data/lib/mack/runner_helpers/session.rb +41 -0
- data/lib/{tasks → mack/tasks}/cachetastic_tasks.rake +0 -11
- data/lib/{tasks → mack/tasks}/gem_tasks.rake +3 -17
- data/lib/{tasks → mack/tasks}/generator_tasks.rake +1 -1
- data/lib/{tasks → mack/tasks}/log_tasks.rake +0 -0
- data/lib/{tasks → mack/tasks}/mack_dump_tasks.rake +0 -0
- data/lib/{tasks → mack/tasks}/mack_ring_server_tasks.rake +0 -0
- data/lib/{tasks → mack/tasks}/mack_server_tasks.rake +0 -0
- data/lib/{tasks → mack/tasks}/mack_tasks.rake +1 -2
- data/lib/{tasks → mack/tasks}/mack_update_tasks.rake +0 -0
- data/lib/{tasks → mack/tasks}/rake_helpers.rb +0 -0
- data/lib/{tasks → mack/tasks}/rake_rules.rake +1 -5
- data/lib/{tasks → mack/tasks}/test_tasks.rake +18 -8
- data/lib/mack/tasks/tmp_tasks.rake +8 -0
- data/lib/{testing → mack/testing}/helpers.rb +1 -1
- data/lib/{testing → mack/testing}/response.rb +0 -0
- data/lib/{testing → mack/testing}/rspec.rb +3 -2
- data/lib/{testing → mack/testing}/test_assertions.rb +0 -0
- data/lib/{testing → mack/testing}/test_case.rb +0 -0
- data/lib/mack/utils/ansi/ansi_color.rb +22 -0
- data/lib/{utils → mack/utils}/crypt/default_worker.rb +0 -0
- data/lib/{utils → mack/utils}/crypt/keeper.rb +0 -0
- data/lib/{utils → mack/utils}/gem_manager.rb +10 -5
- data/lib/{utils → mack/utils}/mime_types.rb +0 -0
- data/lib/{utils → mack/utils}/mime_types.yml +2 -1
- data/lib/{utils → mack/utils}/server.rb +11 -5
- data/lib/mack/view_helpers/all_helpers.rb +16 -0
- data/lib/{view_helpers → mack/view_helpers}/html_helpers.rb +1 -1
- data/lib/{view_helpers → mack/view_helpers}/string_helpers.rb +1 -1
- data/lib/mack_app.rb +19 -0
- data/lib/mack_core.rb +52 -0
- data/lib/mack_tasks.rb +16 -1
- metadata +118 -98
- data/lib/generators/mack_application_generator/templates/Rakefile.template +0 -10
- data/lib/generators/mack_application_generator/templates/config/app_config/default.yml.template +0 -6
- data/lib/initialization/orm_support.rb +0 -10
- data/lib/runner.rb +0 -172
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
|
5
|
-
gem 'mack', '<%= @options["version"] %>'
|
6
|
-
require 'mack_tasks'
|
7
|
-
|
8
|
-
<% if @options["testing_framework"] != "rspec" -%>
|
9
|
-
alias_task :default, "test:<%= @options["testing_framework"] %>"
|
10
|
-
<% end -%>
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# If the application explicitly says it doesn't want to use any orm,
|
2
|
-
# then we're not going to initialize any default orm.
|
3
|
-
# Note: this is initialization process only. By the default, application
|
4
|
-
# generated by mack still have data_mapper as default.
|
5
|
-
orm = app_config.orm
|
6
|
-
unless orm.nil?
|
7
|
-
Mack.logger.info "Initializing #{orm} orm..."
|
8
|
-
require "mack-#{orm}"
|
9
|
-
require "mack-#{orm}_tasks"
|
10
|
-
end
|
data/lib/runner.rb
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'routing', 'urls')
|
2
|
-
module Mack
|
3
|
-
# This is the heart and soul of the Mack framework! This class interfaces with the Rack framework.
|
4
|
-
# It handles all the dispatching back and forth between the Rack framework and a Mack application.
|
5
|
-
class Runner
|
6
|
-
include Mack::Routes::Urls
|
7
|
-
|
8
|
-
attr_reader :response # :nodoc:
|
9
|
-
attr_reader :request # :nodoc:
|
10
|
-
attr_reader :cookies # :nodoc:
|
11
|
-
# This method needs to be defined as part of the Rack framework. As is noted for the Mack::Runner
|
12
|
-
# class, this is where the center of the Mack framework lies.
|
13
|
-
def call(env)
|
14
|
-
# pp env
|
15
|
-
begin
|
16
|
-
setup(env) do
|
17
|
-
begin
|
18
|
-
route = Mack::Routes::RouteMap.instance.get_route_from_request(self.request)
|
19
|
-
if route[:redirect_to]
|
20
|
-
# because the route is specified to be a redirect, let's do that:
|
21
|
-
redirect_to(route)
|
22
|
-
else
|
23
|
-
self.request.all_params[:original_controller] = route[:controller]
|
24
|
-
self.request.all_params[:original_action] = route[:action]
|
25
|
-
run_controller(route)
|
26
|
-
end
|
27
|
-
# rescue Mack::Errors::ResourceNotFound, Mack::Errors::UndefinedRoute => e
|
28
|
-
# return try_to_find_resource(env, e)
|
29
|
-
rescue Exception => e
|
30
|
-
route = Mack::Routes::RouteMap.instance.get_route_from_error(e.class)
|
31
|
-
unless route.nil?
|
32
|
-
run_controller(route, e)
|
33
|
-
else
|
34
|
-
if e.class == Mack::Errors::ResourceNotFound || e.class == Mack::Errors::UndefinedRoute
|
35
|
-
return try_to_find_resource(env, e)
|
36
|
-
else
|
37
|
-
raise e
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end # setup
|
42
|
-
rescue Exception => e
|
43
|
-
Mack.logger.error(e)
|
44
|
-
raise e
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
#--
|
49
|
-
# This method gets called after the session has been established. Override this method
|
50
|
-
# to add custom code around requests.
|
51
|
-
# def custom_dispatch_wrapper
|
52
|
-
# yield
|
53
|
-
# end
|
54
|
-
#++
|
55
|
-
|
56
|
-
#private
|
57
|
-
def run_controller(route, e = nil)
|
58
|
-
# let's handle a normal request:
|
59
|
-
begin
|
60
|
-
cont = "#{route[:controller].to_s.camelcase}Controller".constantize
|
61
|
-
rescue NameError => e
|
62
|
-
raise Mack::Errors::ResourceNotFound.new(self.request.path_info)
|
63
|
-
end
|
64
|
-
self.request.all_params[:controller] = route[:controller]
|
65
|
-
self.request.all_params[:action] = route[:action]
|
66
|
-
self.request.instance_variable_set("@params_controller", nil)
|
67
|
-
self.request.instance_variable_set("@params_action", nil)
|
68
|
-
|
69
|
-
c = cont.new(self.request, self.response, self.cookies)
|
70
|
-
c.caught_exception = e unless e.nil?
|
71
|
-
|
72
|
-
self.response.controller = c
|
73
|
-
self.response.write(c.run)
|
74
|
-
end
|
75
|
-
|
76
|
-
def log_request
|
77
|
-
s_time = Time.now
|
78
|
-
x = yield
|
79
|
-
e_time = Time.now
|
80
|
-
p_time = e_time - s_time
|
81
|
-
if app_config.log.detailed_requests
|
82
|
-
msg = "\n\t[#{@request.request_method.upcase}] '#{@request.path_info}'\n"
|
83
|
-
msg << "\tSession ID: #{@request.session.id}\n"
|
84
|
-
msg << "\tParameters: #{@request.all_params}\n"
|
85
|
-
msg << "\tCompleted in #{p_time} (#{(1 / p_time).round} reqs/sec) | #{@response.status} [#{@request.full_host}]"
|
86
|
-
else
|
87
|
-
msg = "[#{@request.request_method.upcase}] '#{@request.path_info}' (#{p_time})"
|
88
|
-
end
|
89
|
-
Mack.logger.info(msg)
|
90
|
-
x
|
91
|
-
end
|
92
|
-
|
93
|
-
# Setup the request, response, cookies, session, etc...
|
94
|
-
# yield up, and then clean things up afterwards.
|
95
|
-
def setup(env)
|
96
|
-
exception = nil
|
97
|
-
log_request do
|
98
|
-
@request = Mack::Request.new(env)
|
99
|
-
@response = Mack::Response.new
|
100
|
-
@cookies = Mack::CookieJar.new(self.request, self.response)
|
101
|
-
session do
|
102
|
-
begin
|
103
|
-
# custom_dispatch_wrapper do
|
104
|
-
yield
|
105
|
-
# end
|
106
|
-
rescue Exception => e
|
107
|
-
exception = e
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
raise exception if exception
|
112
|
-
self.response.finish
|
113
|
-
end
|
114
|
-
|
115
|
-
def session
|
116
|
-
sess_id = self.cookies[app_config.mack.session_id]
|
117
|
-
unless sess_id
|
118
|
-
sess_id = create_new_session
|
119
|
-
else
|
120
|
-
sess = Cachetastic::Caches::MackSessionCache.get(sess_id)
|
121
|
-
if sess
|
122
|
-
self.request.session = sess
|
123
|
-
else
|
124
|
-
# we couldn't find it in the store, so we need to create it:
|
125
|
-
sess_id = create_new_session
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
yield
|
130
|
-
|
131
|
-
Cachetastic::Caches::MackSessionCache.set(sess_id, self.request.session)
|
132
|
-
end
|
133
|
-
|
134
|
-
def create_new_session
|
135
|
-
id = String.randomize(40).downcase
|
136
|
-
self.cookies[app_config.mack.session_id] = {:value => id, :expires => nil}
|
137
|
-
sess = Mack::Session.new(id)
|
138
|
-
self.request.session = sess
|
139
|
-
Cachetastic::Caches::MackSessionCache.set(id, sess)
|
140
|
-
id
|
141
|
-
end
|
142
|
-
|
143
|
-
def try_to_find_resource(env, exception)
|
144
|
-
env = env.dup
|
145
|
-
# we can't find a route for this, so let's try and see if it's in the public directory:
|
146
|
-
if File.extname(env["PATH_INFO"]).blank?
|
147
|
-
env["PATH_INFO"] << ".html"
|
148
|
-
end
|
149
|
-
if File.exists?(File.join(Mack.root, "public", env["PATH_INFO"]))
|
150
|
-
return Rack::File.new(File.join(Mack.root, "public")).call(env)
|
151
|
-
else
|
152
|
-
raise exception
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
# This will redirect the request to the specified url. A default status of
|
157
|
-
# 302, Moved Temporarily, is set if no status is specified. A simple HTML
|
158
|
-
# page is rendered in case the redirect does not occur.
|
159
|
-
def redirect_to(route)
|
160
|
-
status = route[:status] || 302
|
161
|
-
url = route[:redirect_to]
|
162
|
-
options = self.request.all_params
|
163
|
-
options.merge!(route)
|
164
|
-
options - [:controller, :action, :redirect_to, :method, :status, :format]
|
165
|
-
url = url_for_pattern(url, options)
|
166
|
-
self.response.status = status
|
167
|
-
self.response[:location] = url
|
168
|
-
self.response.write(redirect_html(self.request.path_info, url, status))
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|
172
|
-
end
|