mack 0.7.1.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +32 -0
- data/bin/gem_load_path.rb +1 -1
- data/bin/mackery +0 -1
- data/bin/mackery-server +5 -1
- data/lib/mack/assets/asset_helpers.rb +51 -0
- data/lib/mack/assets/assets_mgr.rb +165 -0
- data/lib/mack/controller/controller.rb +4 -4
- data/lib/mack/controller/cookie_jar.rb +1 -1
- data/lib/mack/controller/request.rb +13 -3
- data/lib/mack/controller/response.rb +12 -0
- data/lib/mack/core_extensions/kernel.rb +69 -0
- data/lib/mack/core_extensions/symbol.rb +4 -0
- data/lib/mack/errors/errors.rb +5 -1
- data/lib/mack/generators/controller_generator/manifest.yml +2 -2
- data/lib/mack/generators/controller_helper_generator/manifest.yml +2 -2
- data/lib/mack/generators/mack_application_generator/manifest.yml +10 -2
- data/lib/mack/generators/mack_application_generator/templates/config/{app_config/default.yml.template → configatron/default.rb.template} +10 -15
- data/lib/mack/generators/mack_application_generator/templates/config/{app_config/development.yml.template → configatron/development.rb.template} +1 -1
- data/lib/mack/generators/mack_application_generator/templates/config/{app_config/production.yml.template → configatron/production.rb.template} +0 -0
- data/lib/mack/generators/mack_application_generator/templates/config/{app_config/test.yml.template → configatron/test.rb.template} +1 -1
- data/lib/mack/generators/mack_application_generator/templates/public/404.html.template +15 -0
- data/lib/mack/generators/mack_application_generator/templates/public/500.html.template +15 -0
- data/lib/mack/generators/view_helper_generator/manifest.yml +2 -2
- data/lib/mack/initialization/application.rb +9 -5
- data/lib/mack/initialization/boot_loader.rb +2 -104
- data/lib/mack/initialization/configuration.rb +72 -69
- data/lib/mack/initialization/console.rb +1 -1
- data/lib/mack/initialization/helpers.rb +1 -6
- data/lib/mack/initialization/logging/basic_layout.rb +14 -0
- data/lib/mack/initialization/logging/color_layout.rb +23 -0
- data/lib/mack/initialization/logging/filter.rb +45 -0
- data/lib/mack/initialization/logging.rb +33 -89
- data/lib/mack/initialization/plugins.rb +1 -1
- data/lib/mack/rendering/engine/builder.rb +3 -0
- data/lib/mack/rendering/engine/erubis.rb +28 -16
- data/lib/mack/rendering/type/file_base.rb +1 -1
- data/lib/mack/rendering/type/url.rb +3 -3
- data/lib/mack/rendering/view_template.rb +4 -7
- data/lib/mack/routing/resource_proxy.rb +33 -0
- data/lib/mack/routing/route_map.rb +122 -288
- data/lib/mack/routing/route_object.rb +88 -0
- data/lib/mack/routing/routes.rb +169 -0
- data/lib/mack/routing/urls.rb +39 -5
- data/lib/mack/runner.rb +65 -32
- data/lib/mack/runner_helpers/request_logger.rb +3 -3
- data/lib/mack/runner_helpers/session.rb +4 -4
- data/lib/mack/sessions/cookie_session_store.rb +3 -3
- data/lib/mack/sessions/session.rb +1 -1
- data/lib/mack/sessions/session_store_base.rb +1 -1
- data/lib/mack/tasks/gem_tasks.rake +156 -1
- data/lib/mack/tasks/mack_dump_tasks.rake +1 -1
- data/lib/mack/tasks/mack_update_tasks.rake +85 -1
- data/lib/mack/tasks/rake_rules.rake +6 -0
- data/lib/mack/tasks/test_tasks.rake +4 -4
- data/lib/mack/testing/helpers.rb +13 -6
- data/lib/mack/testing/rspec.rb +27 -9
- data/lib/mack/testing/test_case.rb +1 -1
- data/lib/mack/utils/ansi/ansi_color.rb +4 -1
- data/lib/mack/utils/forgery_detector.rb +3 -3
- data/lib/mack/utils/http_status_codes.rb +19 -0
- data/lib/mack/utils/http_status_codes.yml +55 -0
- data/lib/mack/utils/paths.rb +32 -32
- data/lib/mack/utils/reloader.rb +60 -0
- data/lib/mack/utils/server.rb +3 -3
- data/lib/mack/version.rb +1 -1
- data/lib/mack/view_helpers/all_helpers.rb +7 -0
- data/lib/mack/view_helpers/date_time_helpers.rb +16 -10
- data/lib/mack/view_helpers/form_helpers.rb +1 -1
- data/lib/mack/view_helpers/html_helpers.rb +22 -1
- data/lib/mack/view_helpers/link_helpers.rb +51 -10
- data/lib/mack/view_helpers/string_helpers.rb +1 -1
- data/lib/mack.rb +0 -1
- data/lib/mack_core.rb +8 -8
- data/lib/mack_tasks.rb +1 -1
- metadata +27 -15
- data/lib/mack/view_helpers/asset_helpers.rb +0 -50
@@ -1,5 +1,5 @@
|
|
1
1
|
boot_load(:initializers) do
|
2
|
-
Mack.logger.debug "Initializing custom initializers..." unless
|
2
|
+
Mack.logger.debug "Initializing custom initializers..." unless configatron.mack.log.disable_initialization_logging
|
3
3
|
Dir.glob(Mack::Paths.initializers("**/*.rb")) do |d|
|
4
4
|
require d
|
5
5
|
end
|
@@ -7,7 +7,7 @@ end
|
|
7
7
|
|
8
8
|
boot_load(:lib, :plugins, :gems) do
|
9
9
|
# require 'lib' files:
|
10
|
-
Mack.logger.debug "Initializing lib classes..." unless
|
10
|
+
Mack.logger.debug "Initializing lib classes..." unless configatron.mack.log.disable_initialization_logging
|
11
11
|
Dir.glob(Mack::Paths.lib("**/*.rb")).each do |d|
|
12
12
|
require d
|
13
13
|
end
|
@@ -21,15 +21,14 @@ end
|
|
21
21
|
|
22
22
|
boot_load(:routes) do
|
23
23
|
# set up routes:
|
24
|
-
Mack.logger.debug "Initializing routes..." unless
|
24
|
+
Mack.logger.debug "Initializing routes..." unless configatron.mack.log.disable_initialization_logging
|
25
25
|
require Mack::Paths.config("routes")
|
26
26
|
end
|
27
27
|
|
28
28
|
boot_load(:app_files, :default_controller) do
|
29
29
|
# require 'app' files:
|
30
|
-
Mack.logger.debug "Initializing 'app' classes..." unless
|
30
|
+
Mack.logger.debug "Initializing 'app' classes..." unless configatron.mack.log.disable_initialization_logging
|
31
31
|
Dir.glob(Mack::Paths.app("**/*.rb")).each do |d|
|
32
|
-
# puts "d: #{d}"
|
33
32
|
begin
|
34
33
|
require d
|
35
34
|
rescue NameError => e
|
@@ -46,4 +45,9 @@ boot_load(:app_files, :default_controller) do
|
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
48
|
+
|
49
|
+
# Add default assets
|
50
|
+
assets_mgr.defaults do |a|
|
51
|
+
a.add_css "scaffold" if File.exists?Mack::Paths.stylesheets("scaffold.css")
|
52
|
+
end
|
49
53
|
end
|
@@ -26,8 +26,7 @@ module Mack
|
|
26
26
|
begin
|
27
27
|
Mack::BootLoader.instance.sequences[a.to_sym].run
|
28
28
|
rescue Exception => e
|
29
|
-
|
30
|
-
puts e.backtrace
|
29
|
+
raise e
|
31
30
|
end
|
32
31
|
end
|
33
32
|
end
|
@@ -70,105 +69,4 @@ module Mack
|
|
70
69
|
|
71
70
|
end
|
72
71
|
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# module Mack
|
76
|
-
# class BootLoader
|
77
|
-
# include Singleton
|
78
|
-
# include Extlib::Hook
|
79
|
-
#
|
80
|
-
# attr_accessor :steps
|
81
|
-
# attr_accessor :additional_procs
|
82
|
-
#
|
83
|
-
# def initialize
|
84
|
-
# self.steps = [:initializers, :gems, :plugins, :libs, :default_controller, :routes, :app, :additional]
|
85
|
-
# self.additional_procs = []
|
86
|
-
# end
|
87
|
-
#
|
88
|
-
# def start
|
89
|
-
# Mack.logger.debug "Starting boot loader sequence...."
|
90
|
-
# end
|
91
|
-
#
|
92
|
-
# def initializers
|
93
|
-
# # set up initializers:
|
94
|
-
# Mack.logger.debug "Initializing custom initializers..." unless app_config.log.disable_initialization_logging
|
95
|
-
# Dir.glob(Mack::Paths.initializers("**/*.rb")) do |d|
|
96
|
-
# require d
|
97
|
-
# end
|
98
|
-
# end
|
99
|
-
#
|
100
|
-
# def gems
|
101
|
-
# Mack.logger.debug "Initializing custom gems..." unless app_config.log.disable_initialization_logging
|
102
|
-
# Mack::Utils::GemManager.instance.do_requires
|
103
|
-
# end
|
104
|
-
#
|
105
|
-
# def plugins
|
106
|
-
# # require 'plugins':
|
107
|
-
# Mack.logger.debug "Initializing plugins..." unless app_config.log.disable_initialization_logging
|
108
|
-
# require File.join(File.dirname(__FILE__), "plugins.rb")
|
109
|
-
# end
|
110
|
-
#
|
111
|
-
# def libs
|
112
|
-
# # require 'lib' files:
|
113
|
-
# Mack.logger.debug "Initializing lib classes..." unless app_config.log.disable_initialization_logging
|
114
|
-
# Dir.glob(Mack::Paths.lib("**/*.rb")).each do |d|
|
115
|
-
# require d
|
116
|
-
# end
|
117
|
-
# end
|
118
|
-
#
|
119
|
-
# def default_controller
|
120
|
-
# # make sure that default_controller is available to other controllers
|
121
|
-
# path = Mack::Paths.controllers("default_controller.rb")
|
122
|
-
# require path if File.exists?(path)
|
123
|
-
# end
|
124
|
-
#
|
125
|
-
# def routes
|
126
|
-
# # set up routes:
|
127
|
-
# Mack.logger.debug "Initializing routes..." unless app_config.log.disable_initialization_logging
|
128
|
-
# require Mack::Paths.config("routes")
|
129
|
-
# end
|
130
|
-
#
|
131
|
-
# def app
|
132
|
-
# # require 'app' files:
|
133
|
-
# Mack.logger.debug "Initializing 'app' classes..." unless app_config.log.disable_initialization_logging
|
134
|
-
# Dir.glob(Mack::Paths.app("**/*.rb")).each do |d|
|
135
|
-
# # puts "d: #{d}"
|
136
|
-
# begin
|
137
|
-
# require d
|
138
|
-
# rescue NameError => e
|
139
|
-
# if e.message.match("uninitialized constant")
|
140
|
-
# mod = e.message.gsub("uninitialized constant ", "")
|
141
|
-
# x =%{
|
142
|
-
# module ::#{mod}
|
143
|
-
# end
|
144
|
-
# }
|
145
|
-
# eval(x)
|
146
|
-
# require d
|
147
|
-
# else
|
148
|
-
# raise e
|
149
|
-
# end
|
150
|
-
# end
|
151
|
-
# end
|
152
|
-
# end
|
153
|
-
#
|
154
|
-
# def additional
|
155
|
-
# self.additional_procs.each do |p|
|
156
|
-
# puts "p: #{p.inspect}"
|
157
|
-
# p.call
|
158
|
-
# end
|
159
|
-
# end
|
160
|
-
#
|
161
|
-
# def finish
|
162
|
-
# Mack.logger.debug "...Finished boot loader sequence."
|
163
|
-
# end
|
164
|
-
#
|
165
|
-
# def self.run
|
166
|
-
# Mack::BootLoader.instance.start
|
167
|
-
# Mack::BootLoader.instance.steps.each do |step|
|
168
|
-
# Mack::BootLoader.instance.send(step)
|
169
|
-
# end
|
170
|
-
# Mack::BootLoader.instance.finish
|
171
|
-
# end
|
172
|
-
#
|
173
|
-
# end
|
174
|
-
# end
|
72
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'mack-facets'
|
2
|
-
require '
|
2
|
+
require 'configatron'
|
3
3
|
require File.join(File.dirname(__FILE__), 'boot_loader')
|
4
|
+
require File.join(File.dirname(__FILE__), '..', 'core_extensions', 'kernel')
|
4
5
|
require File.join(File.dirname(__FILE__), '..', 'utils', 'paths')
|
5
6
|
boot_load(:configuration) do
|
6
7
|
module Mack
|
@@ -14,83 +15,85 @@ boot_load(:configuration) do
|
|
14
15
|
def self.env
|
15
16
|
ENV["MACK_ENV"] ||= "development"
|
16
17
|
end
|
18
|
+
|
19
|
+
# Returns true/false based on whether the specified environment
|
20
|
+
# is the current environment
|
21
|
+
def self.env?(env)
|
22
|
+
self.env == env.to_s
|
23
|
+
end
|
17
24
|
|
18
25
|
# All configuration for the Mack subsystem happens here. Each of the default environments,
|
19
26
|
# production, development, and test have their own default configuration options. These
|
20
27
|
# get merged with overall default options.
|
21
28
|
module Configuration # :nodoc:
|
29
|
+
unless const_defined?("LOADED")
|
30
|
+
configatron.mack.render_url_timeout = 5
|
31
|
+
configatron.mack.cache_classes = true
|
32
|
+
configatron.mack.reload_classes = 1
|
33
|
+
configatron.mack.deep_class_reload = false
|
34
|
+
configatron.mack.use_lint = true
|
35
|
+
configatron.mack.show_exceptions = true
|
36
|
+
configatron.mack.use_sessions = true
|
37
|
+
configatron.mack.session_id = '_mack_session_id'
|
38
|
+
configatron.mack.cookie_values = {:path => '/'}
|
39
|
+
configatron.mack.site_domain = 'http://localhost:3000'
|
40
|
+
configatron.mack.testing_framework = :rspec
|
41
|
+
configatron.mack.rspec_file_pattern = 'test/**/*_spec.rb'
|
42
|
+
configatron.mack.test_case_file_pattern = 'test/**/*_test.rb'
|
43
|
+
configatron.mack.session_store = :cookie
|
44
|
+
configatron.mack.disable_forgery_detector = false
|
45
|
+
configatron.mack.assets.max_distribution = 4
|
46
|
+
configatron.mack.assets.hosts = ''
|
47
|
+
configatron.mack.assets.stamp = Time.now.to_i
|
48
|
+
configatron.mack.cookie_session_store.expiry_time = 4.hours
|
49
|
+
|
50
|
+
configatron.mack.log.level = :info
|
51
|
+
configatron.mack.log.detailed_requests = true
|
52
|
+
configatron.mack.log.disable_initialization_logging = false
|
53
|
+
configatron.mack.log.root = Mack::Paths.log
|
54
|
+
configatron.mack.log.colors.db = :cyan
|
55
|
+
configatron.mack.log.colors.error = :red
|
56
|
+
configatron.mack.log.colors.fatal = :red
|
57
|
+
configatron.mack.log.colors.warn = :yellow
|
58
|
+
configatron.mack.log.colors.completed = :purple
|
59
|
+
configatron.mack.log.use_colors = true
|
60
|
+
configatron.mack.log.time_format = '%Y-%m-%d %H:%M:%S'
|
61
|
+
|
62
|
+
if Mack.env?(:production)
|
63
|
+
configatron.mack.use_lint = false
|
64
|
+
configatron.mack.show_exceptions = false
|
65
|
+
configatron.mack.log.level = :info
|
66
|
+
configatron.mack.log.detailed_requests = true
|
67
|
+
configatron.mack.log.use_colors = false
|
68
|
+
end
|
69
|
+
|
70
|
+
if Mack.env?(:development)
|
71
|
+
configatron.mack.cache_classes = false
|
72
|
+
configatron.mack.log.level = :debug
|
73
|
+
end
|
22
74
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
75
|
+
if Mack.env?(:test)
|
76
|
+
configatron.mack.cookie_values = {}
|
77
|
+
configatron.mack.session_store = :test
|
78
|
+
configatron.mack.disable_forgery_detector = true
|
79
|
+
configatron.mack.run_remote_tests = true
|
80
|
+
configatron.mack.log.level = :error
|
81
|
+
end
|
27
82
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
} unless self.const_defined?("DEFAULTS_PRODUCTION")
|
36
|
-
|
37
|
-
# use local memory and store stuff for 5 minutes:
|
38
|
-
DEFAULTS_DEVELOPMENT = {
|
39
|
-
"mack::cache_classes" => false,
|
40
|
-
"log_level" => "debug"
|
41
|
-
} unless self.const_defined?("DEFAULTS_DEVELOPMENT")
|
42
|
-
|
43
|
-
# use local memory and store stuff for 1 hour:
|
44
|
-
DEFAULTS_TEST = {
|
45
|
-
"log_level" => "error",
|
46
|
-
"run_remote_tests" => true,
|
47
|
-
"mack::cookie_values" => {},
|
48
|
-
"mack::session_store" => "test",
|
49
|
-
"mack::disable_forgery_detector" => true
|
50
|
-
} unless self.const_defined?("DEFAULTS_TEST")
|
51
|
-
|
52
|
-
unless self.const_defined?("DEFAULTS")
|
53
|
-
DEFAULTS = {
|
54
|
-
"mack::render_url_timeout" => 5,
|
55
|
-
"mack::cache_classes" => true,
|
56
|
-
"mack::use_lint" => true,
|
57
|
-
"mack::show_exceptions" => true,
|
58
|
-
"mack::use_sessions" => true,
|
59
|
-
"mack::session_id" => "_mack_session_id",
|
60
|
-
"mack::cookie_values" => {
|
61
|
-
"path" => "/"
|
62
|
-
},
|
63
|
-
"mack::site_domain" => "http://localhost:3000",
|
64
|
-
"mack::testing_framework" => "rspec",
|
65
|
-
"mack::rspec_file_pattern" => "test/**/*_spec.rb",
|
66
|
-
"mack::test_case_file_pattern" => "test/**/*_test.rb",
|
67
|
-
"log::detailed_requests" => true,
|
68
|
-
"log::db_color" => "cyan",
|
69
|
-
"log::error_color" => "red",
|
70
|
-
"log::fatal_color" => "red",
|
71
|
-
"log::warn_color" => "yellow",
|
72
|
-
"log::completed_color" => "purple",
|
73
|
-
"log_level" => "info",
|
74
|
-
"mack::session_store" => "cookie",
|
75
|
-
"cookie_session_store::expiry_time" => 4.hours
|
76
|
-
}#.merge(eval("DEFAULTS_#{Mack.env.upcase}"))
|
77
|
-
end
|
78
|
-
|
79
|
-
app_config.load_hash(DEFAULTS, "mack_defaults")
|
80
|
-
app_config.load_hash(eval("DEFAULTS_#{Mack.env.upcase}"), "mack_defaults_#{Mack.env}")
|
81
|
-
app_config.load_file(Mack::Paths.app_config("default.yml"))
|
82
|
-
app_config.load_file(Mack::Paths.app_config("#{Mack.env}.yml"))
|
83
|
-
# app_config.reload
|
83
|
+
if File.exists?(Mack::Paths.configatron('default.rb'))
|
84
|
+
require Mack::Paths.configatron('default.rb')
|
85
|
+
end
|
86
|
+
|
87
|
+
if File.exists?(Mack::Paths.configatron("#{Mack.env}.rb"))
|
88
|
+
require Mack::Paths.configatron("#{Mack.env}.rb")
|
89
|
+
end
|
84
90
|
|
85
|
-
|
86
|
-
|
87
|
-
conf = {}
|
88
|
-
fcs.each_pair do |k, v|
|
89
|
-
unless v.is_a?(Application::Configuration::Namespace)
|
90
|
-
conf[k.to_s] = v unless k.to_s.match("__")
|
91
|
-
end
|
91
|
+
def self.dump
|
92
|
+
configatron.inspect
|
92
93
|
end
|
93
|
-
|
94
|
+
|
95
|
+
LOADED = true
|
96
|
+
|
94
97
|
end
|
95
98
|
|
96
99
|
end
|
@@ -1,11 +1,6 @@
|
|
1
1
|
boot_load(:helpers, :logging) do
|
2
2
|
# Include ApplicationHelper into all controllers:
|
3
|
-
Mack.logger.debug "Initializing helpers..." unless
|
4
|
-
# adding application_helper module into all defined controllers
|
5
|
-
if Object.const_defined?("ApplicationHelper")
|
6
|
-
deprecate_method("ApplicationHelper", "Mack::ViewHelpers::ApplicationHelper", "0.7.0")
|
7
|
-
ApplicationHelper.include_safely_into(Mack::Rendering::ViewTemplate)
|
8
|
-
end
|
3
|
+
Mack.logger.debug "Initializing helpers..." unless configatron.mack.log.disable_initialization_logging
|
9
4
|
|
10
5
|
module Mack
|
11
6
|
module ControllerHelpers # :nodoc:
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Mack
|
2
|
+
module Logging # :nodoc:
|
3
|
+
|
4
|
+
class BasicLayout < ::Logging::Layout # :nodoc:
|
5
|
+
|
6
|
+
def format(event)
|
7
|
+
obj = format_obj(event.data)
|
8
|
+
sprintf("%*s:\t[%s]\t%s\n", ::Logging::MAX_LEVEL_LENGTH, ::Logging::LNAMES[event.level], Time.now.strftime(configatron.mack.log.time_format), obj)
|
9
|
+
end
|
10
|
+
|
11
|
+
end # BasicLayout
|
12
|
+
|
13
|
+
end # Logging
|
14
|
+
end # Mack
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Mack
|
2
|
+
module Logging # :nodoc:
|
3
|
+
|
4
|
+
class ColorLayout < Mack::Logging::BasicLayout # :nodoc:
|
5
|
+
|
6
|
+
def format(event)
|
7
|
+
message = super(event)
|
8
|
+
if message.match(/^(SELECT|INSERT|UPDATE|DELETE|CREATE|DROP)/)
|
9
|
+
return Mack::Utils::Ansi::Color.wrap(configatron.mack.log.colors.db, message)
|
10
|
+
else
|
11
|
+
color = configatron.mack.log.colors.retrieve(event.level_name.downcase.to_sym, nil)
|
12
|
+
if color
|
13
|
+
return Mack::Utils::Ansi::Color.wrap(color, message)
|
14
|
+
else
|
15
|
+
return message
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end # ColorLayout
|
21
|
+
|
22
|
+
end # Logging
|
23
|
+
end # Mack
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Mack
|
2
|
+
module Logging # :nodoc:
|
3
|
+
|
4
|
+
# Used to house a list of filters for parameter logging. The initial list
|
5
|
+
# includes password and password_confirmation
|
6
|
+
class Filter
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
# The list of parameters you want filtered for logging.
|
10
|
+
attr_reader :list
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@list = [:password, :password_confirmation]
|
14
|
+
end
|
15
|
+
|
16
|
+
# Adds 'n' number of parameter names to the list
|
17
|
+
def add(*args)
|
18
|
+
@list << args
|
19
|
+
@list.flatten!
|
20
|
+
end
|
21
|
+
|
22
|
+
# Removes 'n' number of parameter names from the list
|
23
|
+
def remove(*args)
|
24
|
+
@list.delete_values(*args)
|
25
|
+
end
|
26
|
+
|
27
|
+
class << self
|
28
|
+
|
29
|
+
def remove(*args)
|
30
|
+
Mack::Logging::Filter.instance.remove(*args)
|
31
|
+
end
|
32
|
+
|
33
|
+
def add(*args)
|
34
|
+
Mack::Logging::Filter.instance.add(*args)
|
35
|
+
end
|
36
|
+
|
37
|
+
def list
|
38
|
+
Mack::Logging::Filter.instance.list
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end # Filter
|
44
|
+
end # Logging
|
45
|
+
end # Mack
|
@@ -1,6 +1,30 @@
|
|
1
1
|
boot_load(:logging, :configuration) do
|
2
|
-
|
2
|
+
|
3
|
+
require 'logging'
|
3
4
|
require File.join(File.dirname(__FILE__), "..", "utils", "ansi", "ansi_color")
|
5
|
+
require File.join(File.dirname(__FILE__), 'logging', 'filter')
|
6
|
+
require File.join(File.dirname(__FILE__), 'logging', 'basic_layout')
|
7
|
+
require File.join(File.dirname(__FILE__), 'logging', 'color_layout')
|
8
|
+
|
9
|
+
module Logging # :nodoc:
|
10
|
+
|
11
|
+
def self.level_name_from_num(num)
|
12
|
+
h = ivar_cache do
|
13
|
+
Logging::LEVELS.invert
|
14
|
+
end
|
15
|
+
h[num]
|
16
|
+
end
|
17
|
+
|
18
|
+
class LogEvent # :nodoc:
|
19
|
+
|
20
|
+
def level_name
|
21
|
+
::Logging.level_name_from_num(self.level)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end # Logging
|
27
|
+
|
4
28
|
module Mack
|
5
29
|
|
6
30
|
def self.logger
|
@@ -12,102 +36,22 @@ boot_load(:logging, :configuration) do
|
|
12
36
|
end
|
13
37
|
|
14
38
|
def self.reset_logger!
|
15
|
-
log_directory =
|
39
|
+
log_directory = configatron.mack.log.retrieve(:root, Mack::Paths.log)
|
16
40
|
begin
|
17
41
|
FileUtils.mkdir_p(log_directory)
|
18
42
|
rescue Exception => e
|
19
43
|
end
|
20
|
-
|
21
|
-
Mack.logger =
|
22
|
-
Mack.logger.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
if Mack.env == "development"
|
27
|
-
# console:
|
28
|
-
Mack.logger.add(Log4r::StdoutOutputter.new('console', :formatter => format))
|
29
|
-
end
|
30
|
-
|
31
|
-
# file:
|
32
|
-
Mack.logger.add(Log4r::FileOutputter.new('fileOutputter', :filename => File.join(log_directory, "#{Mack.env}.log"), :trunc => false, :formatter => format))
|
44
|
+
|
45
|
+
Mack.logger = ::Logging::RootLogger.new
|
46
|
+
Mack.logger.add_appenders(::Logging::Appenders::File.new(Mack.env, :filename => File.join(log_directory, "#{Mack.env}.log"), :layout => Mack::Logging::BasicLayout.new))
|
47
|
+
Mack.logger.add_appenders(::Logging::Appenders::Stdout.new(:layout => Mack::Logging::ColorLayout.new)) if Mack.env?(:development)
|
48
|
+
Mack.logger.level = configatron.mack.log.retrieve(:level, :info)
|
33
49
|
end
|
34
50
|
|
35
|
-
end
|
51
|
+
end # Mack
|
36
52
|
|
37
53
|
unless Mack.logger
|
38
|
-
module Log4r # :nodoc:
|
39
|
-
class IOOutputter # :nodoc:
|
40
|
-
|
41
|
-
# let's not do this more than once. :)
|
42
|
-
unless Log4r::IOOutputter.private_instance_methods.include?("old_write")
|
43
|
-
|
44
|
-
alias_method :old_write, :write
|
45
|
-
|
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))
|
50
|
-
else
|
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
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end # IOOutputter
|
64
|
-
end # Log4r
|
65
|
-
|
66
54
|
Mack.reset_logger!
|
67
55
|
end
|
68
56
|
|
69
|
-
|
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
|
75
|
-
|
76
|
-
# The list of parameters you want filtered for logging.
|
77
|
-
attr_reader :list
|
78
|
-
|
79
|
-
def initialize
|
80
|
-
@list = [:password, :password_confirmation]
|
81
|
-
end
|
82
|
-
|
83
|
-
# Adds 'n' number of parameter names to the list
|
84
|
-
def add(*args)
|
85
|
-
@list << args
|
86
|
-
@list.flatten!
|
87
|
-
end
|
88
|
-
|
89
|
-
# Removes 'n' number of parameter names from the list
|
90
|
-
def remove(*args)
|
91
|
-
@list.delete_values(*args)
|
92
|
-
end
|
93
|
-
|
94
|
-
class << self
|
95
|
-
|
96
|
-
def remove(*args)
|
97
|
-
Mack::Logging::Filter.instance.remove(*args)
|
98
|
-
end
|
99
|
-
|
100
|
-
def add(*args)
|
101
|
-
Mack::Logging::Filter.instance.add(*args)
|
102
|
-
end
|
103
|
-
|
104
|
-
def list
|
105
|
-
Mack::Logging::Filter.instance.list
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
57
|
+
end # boot_load
|
@@ -1,5 +1,5 @@
|
|
1
1
|
boot_load(:plugins, :initializers) do
|
2
|
-
Mack.logger.debug "Initializing plugins..." unless
|
2
|
+
Mack.logger.debug "Initializing plugins..." unless configatron.mack.log.disable_initialization_logging
|
3
3
|
plugins = [] # a list of all plugins
|
4
4
|
Dir.glob(Mack::Paths.plugins("*")).each do |d|
|
5
5
|
plugins << d
|
@@ -7,6 +7,9 @@ module Mack
|
|
7
7
|
class Builder < Mack::Rendering::Engine::Base
|
8
8
|
|
9
9
|
def render(io, binding)
|
10
|
+
if io.is_a?(File)
|
11
|
+
io = io.read
|
12
|
+
end
|
10
13
|
@_xml = ::Builder::XmlMarkup.new(:target => @_xml_output, :indent => 1)
|
11
14
|
view_template.instance_variable_set("@_xml", @_xml)
|
12
15
|
eval(io, binding)
|
@@ -6,12 +6,35 @@ module Mack
|
|
6
6
|
class Erubis < Mack::Rendering::Engine::Base
|
7
7
|
|
8
8
|
def render(io, binding)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
io_src = io
|
10
|
+
file_name = nil
|
11
|
+
if io.is_a?(File)
|
12
|
+
io_src = io.read
|
13
|
+
file_name = io.path
|
14
|
+
end
|
15
|
+
|
16
|
+
eruby = nil
|
17
|
+
|
18
|
+
eruby = ::Erubis::Eruby.new(io_src)
|
19
|
+
|
20
|
+
eruby.filename = file_name
|
21
|
+
begin
|
22
|
+
eruby.result(binding)
|
23
|
+
rescue NoMethodError => e
|
24
|
+
if file_name
|
25
|
+
m = NoMethodError.new("undefined method `#{e.name}' for #{e.backtrace[0].match(/(^.+:\d)/).captures.first}")
|
26
|
+
m.set_backtrace(e.backtrace)
|
27
|
+
raise m
|
28
|
+
end
|
29
|
+
raise e
|
30
|
+
rescue NameError => e
|
31
|
+
if file_name
|
32
|
+
m = NameError.new("undefined local variable or method `#{e.name}' for #{e.backtrace[0].match(/(^.+:\d)/).captures.first}")
|
33
|
+
m.set_backtrace(e.backtrace)
|
34
|
+
raise m
|
35
|
+
end
|
36
|
+
raise e
|
13
37
|
end
|
14
|
-
eval(src, binding)
|
15
38
|
end
|
16
39
|
|
17
40
|
def extension
|
@@ -51,17 +74,6 @@ module Mack
|
|
51
74
|
eval( "_buf", the_binding, __FILE__, __LINE__)
|
52
75
|
end
|
53
76
|
|
54
|
-
class TemplateCache # :nodoc:
|
55
|
-
include Singleton
|
56
|
-
|
57
|
-
attr_reader :cache
|
58
|
-
|
59
|
-
def initialize
|
60
|
-
@cache = {}
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
77
|
end # Erubis
|
66
78
|
end # Engines
|
67
79
|
end # Rendering
|
@@ -13,7 +13,7 @@ module Mack
|
|
13
13
|
Mack::Rendering::Engine::Registry.engines[type].each do |e|
|
14
14
|
@engine = find_engine(e).new(self.view_template)
|
15
15
|
find_file(file + ".#{@engine.extension}") do |f|
|
16
|
-
return @engine.render(File.
|
16
|
+
return @engine.render(File.new(f), self.binder)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
raise Mack::Errors::ResourceNotFound.new(file + ".*")
|