mack 0.7.0.1 → 0.7.1
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/CHANGELOG +34 -0
- data/README +6 -13
- data/bin/env_handler.rb +10 -0
- data/bin/gem_load_path.rb +25 -0
- data/bin/mack +1 -0
- data/bin/mackery +22 -0
- data/bin/mackery-console +16 -0
- data/bin/mackery-server +41 -0
- data/lib/mack.rb +7 -1
- data/lib/mack/controller/controller.rb +5 -4
- data/lib/mack/controller/request.rb +19 -1
- data/lib/mack/errors/errors.rb +8 -8
- data/lib/mack/generators/controller_generator/controller_generator.rb +1 -1
- data/lib/mack/generators/mack_application_generator/templates/app/views/layouts/application.html.erb.template +1 -2
- data/lib/mack/generators/mack_application_generator/templates/config/app_config/default.yml.template +2 -0
- data/lib/mack/generators/mack_application_generator/templates/config/database.yml.template +6 -6
- data/lib/mack/generators/passenger_generator/passenger_generator.rb +2 -0
- data/lib/mack/generators/passenger_generator/templates/config.ru.template +5 -0
- data/lib/mack/generators/passenger_generator/templates/tmp/README.template +2 -0
- data/lib/mack/initialization/application.rb +39 -36
- data/lib/mack/initialization/boot_loader.rb +174 -0
- data/lib/mack/initialization/configuration.rb +83 -95
- data/lib/mack/initialization/console.rb +11 -0
- data/lib/mack/initialization/environment.rb +16 -0
- data/lib/mack/initialization/helpers.rb +26 -24
- data/lib/mack/initialization/logging.rb +81 -81
- data/lib/mack/initialization/plugins.rb +14 -11
- data/lib/mack/initialization/server/simple_server.rb +3 -3
- data/lib/mack/rendering/type/base.rb +1 -1
- data/lib/mack/rendering/type/layout.rb +1 -1
- data/lib/mack/rendering/type/partial.rb +1 -1
- data/lib/mack/rendering/type/public.rb +1 -1
- data/lib/mack/rendering/type/template.rb +1 -1
- data/lib/mack/runner.rb +2 -2
- data/lib/mack/runner_helpers/session.rb +3 -3
- data/lib/mack/sessions/cookie_session_store.rb +44 -0
- data/lib/mack/{controller → sessions}/session.rb +0 -0
- data/lib/mack/sessions/session_store_base.rb +62 -0
- data/lib/mack/sessions/test_session_store.rb +38 -0
- data/lib/mack/tasks/mack_server_tasks.rake +8 -21
- data/lib/mack/tasks/mack_tasks.rake +33 -6
- data/lib/mack/tasks/rake_rules.rake +8 -0
- data/lib/mack/tasks/test_tasks.rake +39 -15
- data/lib/mack/testing/helpers.rb +6 -39
- data/lib/mack/utils/content_length_handler.rb +45 -0
- data/lib/mack/utils/forgery_detector.rb +152 -0
- data/lib/mack/utils/gem_manager.rb +22 -1
- data/lib/mack/utils/paths.rb +154 -0
- data/lib/mack/utils/server.rb +8 -6
- data/lib/mack/version.rb +1 -1
- data/lib/mack/view_helpers/asset_helpers.rb +50 -0
- data/lib/mack/view_helpers/form_helpers.rb +52 -6
- data/lib/mack/view_helpers/link_helpers.rb +6 -3
- data/lib/mack_app.rb +12 -14
- data/lib/mack_core.rb +35 -14
- data/lib/mack_tasks.rb +35 -20
- metadata +23 -27
- data/lib/mack/tasks/cachetastic_tasks.rake +0 -58
@@ -1,113 +1,113 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
module Mack
|
1
|
+
boot_load(:logging, :configuration) do
|
2
|
+
require 'log4r'
|
3
|
+
require File.join(File.dirname(__FILE__), "..", "utils", "ansi", "ansi_color")
|
4
|
+
module Mack
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def self.logger=(log)
|
12
|
-
$mack_default_logger = log
|
13
|
-
end
|
6
|
+
def self.logger
|
7
|
+
$mack_default_logger
|
8
|
+
end
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
begin
|
18
|
-
FileUtils.mkdir_p(log_directory)
|
19
|
-
rescue Exception => e
|
10
|
+
def self.logger=(log)
|
11
|
+
$mack_default_logger = log
|
20
12
|
end
|
13
|
+
|
14
|
+
def self.reset_logger!
|
15
|
+
log_directory = app_config.log_root || Mack::Paths.log
|
16
|
+
begin
|
17
|
+
FileUtils.mkdir_p(log_directory)
|
18
|
+
rescue Exception => e
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
21
|
+
Mack.logger = Log4r::Logger.new('')
|
22
|
+
Mack.logger.level = Module.instance_eval("Log4r::#{(app_config.log_level || :info).to_s.upcase}")
|
24
23
|
|
25
|
-
|
24
|
+
format = Log4r::PatternFormatter.new(:pattern => "%l:\t[%d]\t%M")
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
if Mack.env == "development"
|
27
|
+
# console:
|
28
|
+
Mack.logger.add(Log4r::StdoutOutputter.new('console', :formatter => format))
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
# file:
|
32
|
+
Mack.logger.add(Log4r::FileOutputter.new('fileOutputter', :filename => File.join(log_directory, "#{Mack.env}.log"), :trunc => false, :formatter => format))
|
33
|
+
end
|
35
34
|
|
36
|
-
end
|
35
|
+
end
|
37
36
|
|
38
|
-
unless Mack.logger
|
39
|
-
|
40
|
-
|
37
|
+
unless Mack.logger
|
38
|
+
module Log4r # :nodoc:
|
39
|
+
class IOOutputter # :nodoc:
|
41
40
|
|
42
|
-
|
43
|
-
|
41
|
+
# let's not do this more than once. :)
|
42
|
+
unless Log4r::IOOutputter.private_instance_methods.include?("old_write")
|
44
43
|
|
45
|
-
|
44
|
+
alias_method :old_write, :write
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
else
|
52
|
-
level = data.match(/^\w+/).to_s
|
53
|
-
color = app_config.log.send("#{level.downcase}_color")
|
54
|
-
if color
|
55
|
-
old_write(Mack::Utils::Ansi::Color.wrap(color, data))
|
46
|
+
def write(data)
|
47
|
+
case data
|
48
|
+
when /^(DEBUG:|INFO:|WARN:|ERROR:|FATAL:)\s\[.*\]\s(SELECT|INSERT|UPDATE|DELETE|CREATE|DROP)/
|
49
|
+
old_write(Mack::Utils::Ansi::Color.wrap(app_config.log.db_color, data))
|
56
50
|
else
|
57
|
-
|
51
|
+
level = data.match(/^\w+/).to_s
|
52
|
+
color = app_config.log.send("#{level.downcase}_color")
|
53
|
+
if color
|
54
|
+
old_write(Mack::Utils::Ansi::Color.wrap(color, data))
|
55
|
+
else
|
56
|
+
old_write(data)
|
57
|
+
end
|
58
58
|
end
|
59
59
|
end
|
60
|
-
end
|
61
60
|
|
62
|
-
|
61
|
+
end
|
63
62
|
|
64
|
-
|
65
|
-
|
63
|
+
end # IOOutputter
|
64
|
+
end # Log4r
|
66
65
|
|
67
|
-
|
68
|
-
end
|
66
|
+
Mack.reset_logger!
|
67
|
+
end
|
69
68
|
|
70
|
-
module Mack
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
69
|
+
module Mack
|
70
|
+
module Logging # :nodoc:
|
71
|
+
# Used to house a list of filters for parameter logging. The initial list
|
72
|
+
# includes password and password_confirmation
|
73
|
+
class Filter
|
74
|
+
include Singleton
|
76
75
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
def initialize
|
81
|
-
@list = [:password, :password_confirmation]
|
82
|
-
end
|
76
|
+
# The list of parameters you want filtered for logging.
|
77
|
+
attr_reader :list
|
83
78
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
@list.flatten!
|
88
|
-
end
|
79
|
+
def initialize
|
80
|
+
@list = [:password, :password_confirmation]
|
81
|
+
end
|
89
82
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
83
|
+
# Adds 'n' number of parameter names to the list
|
84
|
+
def add(*args)
|
85
|
+
@list << args
|
86
|
+
@list.flatten!
|
87
|
+
end
|
94
88
|
|
95
|
-
|
96
|
-
|
89
|
+
# Removes 'n' number of parameter names from the list
|
97
90
|
def remove(*args)
|
98
|
-
|
91
|
+
@list.delete_values(*args)
|
99
92
|
end
|
93
|
+
|
94
|
+
class << self
|
100
95
|
|
101
|
-
|
102
|
-
|
103
|
-
|
96
|
+
def remove(*args)
|
97
|
+
Mack::Logging::Filter.instance.remove(*args)
|
98
|
+
end
|
104
99
|
|
105
|
-
|
106
|
-
|
107
|
-
|
100
|
+
def add(*args)
|
101
|
+
Mack::Logging::Filter.instance.add(*args)
|
102
|
+
end
|
108
103
|
|
109
|
-
|
104
|
+
def list
|
105
|
+
Mack::Logging::Filter.instance.list
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
110
109
|
|
110
|
+
end
|
111
111
|
end
|
112
112
|
end
|
113
113
|
end
|
@@ -1,13 +1,16 @@
|
|
1
|
-
plugins
|
2
|
-
|
3
|
-
plugins
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
boot_load(:plugins, :initializers) do
|
2
|
+
Mack.logger.debug "Initializing plugins..." unless app_config.log.disable_initialization_logging
|
3
|
+
plugins = [] # a list of all plugins
|
4
|
+
Dir.glob(Mack::Paths.plugins("*")).each do |d|
|
5
|
+
plugins << d
|
6
|
+
$: << File.join(d, "lib") # add the lib for this plugin to the global load path
|
7
|
+
end
|
8
|
+
plugins.sort.each do |plug|
|
9
|
+
begin
|
10
|
+
require File.join(plug, "init.rb") # load the init.rb for each plugin.
|
11
|
+
rescue Exception => e
|
12
|
+
puts e.message
|
13
|
+
end
|
14
|
+
$:.delete(File.join(plug, "lib")) # remove the plugins lib directory from the global load path.
|
11
15
|
end
|
12
|
-
$:.delete(File.join(plug, "lib")) # remove the plugins lib directory from the global load path.
|
13
16
|
end
|
@@ -8,9 +8,9 @@ module Mack
|
|
8
8
|
class << self
|
9
9
|
|
10
10
|
def run(options)
|
11
|
-
r = "Rack::Handler::#{options
|
12
|
-
puts "Starting app using: #{r} in #{options
|
13
|
-
eval(r).run(Mack::Utils::Server.build_app, :Port => options
|
11
|
+
r = "Rack::Handler::#{options[:handler].camelcase}"
|
12
|
+
puts "Starting app using: #{r} in #{options[:environment]} mode on port: #{options[:port]}"
|
13
|
+
eval(r).run(Mack::Utils::Server.build_app, :Port => options[:port])
|
14
14
|
end
|
15
15
|
|
16
16
|
end
|
@@ -49,7 +49,7 @@ module Mack
|
|
49
49
|
# Returns the directory path for the current controller.
|
50
50
|
def controller_view_path
|
51
51
|
ivar_cache do
|
52
|
-
|
52
|
+
Mack::Paths.views(self.controller.controller_name)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -12,7 +12,7 @@ module Mack
|
|
12
12
|
# Example:
|
13
13
|
# app/views/layouts/application.html.erb
|
14
14
|
def render
|
15
|
-
l_file =
|
15
|
+
l_file = Mack::Paths.layouts("#{self.options[:layout]}.#{self.options[:format]}")
|
16
16
|
begin
|
17
17
|
render_file(l_file, :layout)
|
18
18
|
rescue Mack::Errors::ResourceNotFound => e
|
@@ -24,7 +24,7 @@ module Mack
|
|
24
24
|
else
|
25
25
|
# it's elsewhere
|
26
26
|
parts[parts.size - 1] = "_" << parts.last
|
27
|
-
partial =
|
27
|
+
partial = Mack::Paths.views(parts)
|
28
28
|
end
|
29
29
|
partial = "#{partial}.#{self.options[:format]}"
|
30
30
|
render_file(partial, :partial)
|
@@ -13,7 +13,7 @@ module Mack
|
|
13
13
|
if File.extname(p_file).blank?
|
14
14
|
p_file = "#{p_file}.#{self.options[:format]}"
|
15
15
|
end
|
16
|
-
find_file(Mack.
|
16
|
+
find_file(Mack::Paths.public(p_file)) do |f|
|
17
17
|
return File.open(f).read
|
18
18
|
end
|
19
19
|
raise Mack::Errors::ResourceNotFound.new(p_file)
|
@@ -13,7 +13,7 @@ module Mack
|
|
13
13
|
# Example:
|
14
14
|
# <%= render(:template, "users/show") %> # => app/views/users/show.html.erb
|
15
15
|
def render
|
16
|
-
t_file =
|
16
|
+
t_file = Mack::Paths.views("#{self.render_value}.#{self.options[:format]}")
|
17
17
|
render_file(t_file, :template)
|
18
18
|
end
|
19
19
|
|
data/lib/mack/runner.rb
CHANGED
@@ -100,8 +100,8 @@ module Mack
|
|
100
100
|
if File.extname(env["PATH_INFO"]).blank?
|
101
101
|
env["PATH_INFO"] << ".html"
|
102
102
|
end
|
103
|
-
if File.exists?(
|
104
|
-
return Rack::File.new(
|
103
|
+
if File.exists?(Mack::Paths.public(env["PATH_INFO"]))
|
104
|
+
return Rack::File.new(Mack::Paths.public).call(env)
|
105
105
|
else
|
106
106
|
raise exception
|
107
107
|
end
|
@@ -11,7 +11,7 @@ module Mack
|
|
11
11
|
unless self.sess_id
|
12
12
|
self.sess_id = create_new_session(request, response, cookies)
|
13
13
|
else
|
14
|
-
sess =
|
14
|
+
sess = Mack::SessionStore.get(self.sess_id, request, response, cookies)
|
15
15
|
if sess
|
16
16
|
request.session = sess
|
17
17
|
else
|
@@ -26,7 +26,7 @@ module Mack
|
|
26
26
|
unless response.redirection?
|
27
27
|
request.session.delete(:tell)
|
28
28
|
end
|
29
|
-
|
29
|
+
Mack::SessionStore.set(request.session.id, request, response, cookies) if app_config.mack.use_sessions
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
@@ -39,7 +39,7 @@ module Mack
|
|
39
39
|
cookies[app_config.mack.session_id] = {:value => id, :expires => nil}
|
40
40
|
sess = Mack::Session.new(id)
|
41
41
|
request.session = sess
|
42
|
-
|
42
|
+
Mack::SessionStore.set(request.session.id, request, response, cookies)
|
43
43
|
id
|
44
44
|
end
|
45
45
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "session_store_base")
|
2
|
+
module Mack
|
3
|
+
module SessionStore
|
4
|
+
# Stores session information in the user's cookie.
|
5
|
+
# The session information is encrypted using the mack-encryption library.
|
6
|
+
# This is the default session store for Mack applications.
|
7
|
+
# To set the expiry time for this session store use the following app_config setting:
|
8
|
+
# cookie_session_store::expiry_time: <%= 4.hours %>
|
9
|
+
# It is recommend that you set the app_config setting 'default_secret_key' to
|
10
|
+
# something, otherwise it will generate a random one each time you start your application,
|
11
|
+
# which could make decrypting cookies a bit of a pain. :)
|
12
|
+
class Cookie < Mack::SessionStore::Base
|
13
|
+
|
14
|
+
class << self
|
15
|
+
|
16
|
+
# Returns a decrypted session from the cookie or nil.
|
17
|
+
def get(id, request, response, cookies)
|
18
|
+
c = cookies[id]
|
19
|
+
return nil if c.nil?
|
20
|
+
begin
|
21
|
+
sess = YAML.load(c.decrypt)
|
22
|
+
return sess
|
23
|
+
rescue Exception => e
|
24
|
+
# The cookie was bad, delete it and start a new session.
|
25
|
+
c.delete(id)
|
26
|
+
return nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Encrypts the session and places it into the cookie.
|
31
|
+
def set(id, request, response, cookies)
|
32
|
+
cookies[id] = {:value => YAML.dump(request.session).encrypt, :expires => (Time.now + app_config.cookie_session_store.expiry_time)}
|
33
|
+
end
|
34
|
+
|
35
|
+
# Deletes the cookie.
|
36
|
+
def expire(id, request, response, cookies)
|
37
|
+
cookies.delete(id)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
File without changes
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Mack
|
2
|
+
module SessionStore
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def store # :nodoc:
|
7
|
+
ivar_cache do
|
8
|
+
"Mack::SessionStore::#{app_config.mack.session_store.camelcase}".constantize
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Calls the get method on the specified session store.
|
13
|
+
def get(*args)
|
14
|
+
self.store.get(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Calls the set method on the specified session store.
|
18
|
+
def set(*args)
|
19
|
+
self.store.set(*args)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Calls the expire method on the specified session store.
|
23
|
+
def expire(*args)
|
24
|
+
self.store.expire(*args)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Calls the expire_all method on the specified session store.
|
28
|
+
def expire_all(*args)
|
29
|
+
self.store.expire_all(*args)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
class Base
|
35
|
+
|
36
|
+
class << self
|
37
|
+
|
38
|
+
# Needs to be defined by the subclass. Raises NoMethodError.
|
39
|
+
def get(id, request, response, cookies)
|
40
|
+
raise NoMethodError.new("get")
|
41
|
+
end
|
42
|
+
|
43
|
+
# Needs to be defined by the subclass. Raises NoMethodError.
|
44
|
+
def set(id, request, response, cookies)
|
45
|
+
raise NoMethodError.new("set")
|
46
|
+
end
|
47
|
+
|
48
|
+
# Needs to be defined by the subclass. Raises NoMethodError.
|
49
|
+
def expire(id, request, response, cookies)
|
50
|
+
raise NoMethodError.new("expire")
|
51
|
+
end
|
52
|
+
|
53
|
+
# Needs to be defined by the subclass. Raises NoMethodError.
|
54
|
+
def expire_all(request, response, cookies)
|
55
|
+
raise NoMethodError.new("expire_all")
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end # Base
|
61
|
+
end # SessionStore
|
62
|
+
end # Mack
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "session_store_base")
|
2
|
+
module Mack
|
3
|
+
module SessionStore
|
4
|
+
# A simple Hash based session store for testing.
|
5
|
+
class Test < Mack::SessionStore::Base
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def get(id, *args) # :nodoc:
|
10
|
+
store[id]
|
11
|
+
end
|
12
|
+
|
13
|
+
def set(id, request, *args) # :nodoc:
|
14
|
+
store[id] = request.session
|
15
|
+
end
|
16
|
+
|
17
|
+
def direct_set(id, session) # :nodoc:
|
18
|
+
store[id] = session
|
19
|
+
end
|
20
|
+
|
21
|
+
def expire(id, *args) # :nodoc:
|
22
|
+
store.delete(id)
|
23
|
+
end
|
24
|
+
|
25
|
+
def expire_all # :nodoc:
|
26
|
+
@store = {}
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def store
|
31
|
+
@store ||= {}
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end # Test
|
37
|
+
end # SessionStore
|
38
|
+
end # Mack
|