Changeset 1228
- Timestamp:
- 01/09/08 11:45:24 (9 months ago)
- Files:
-
- trunk/README (modified) (7 diffs)
- trunk/Rakefile (modified) (1 diff)
- trunk/app_generators/merb/templates/config/dependencies.rb (modified) (2 diffs)
- trunk/app_generators/merb/templates/config/merb_init.rb (modified) (2 diffs)
- trunk/lib/merb.rb (modified) (2 diffs)
- trunk/lib/merb/abstract_controller.rb (modified) (1 diff)
- trunk/lib/merb/assets.rb (modified) (3 diffs)
- trunk/lib/merb/boot_loader.rb (added)
- trunk/lib/merb/caching.rb (modified) (1 diff)
- trunk/lib/merb/caching/action_cache.rb (modified) (1 diff)
- trunk/lib/merb/caching/fragment_cache.rb (modified) (1 diff)
- trunk/lib/merb/caching/store/file_cache.rb (modified) (1 diff)
- trunk/lib/merb/config.rb (added)
- trunk/lib/merb/controller.rb (modified) (4 diffs)
- trunk/lib/merb/core_ext/kernel.rb (modified) (10 diffs)
- trunk/lib/merb/dispatcher.rb (modified) (4 diffs)
- trunk/lib/merb/logger.rb (modified) (1 diff)
- trunk/lib/merb/mail_controller.rb (modified) (2 diffs)
- trunk/lib/merb/mailer.rb (modified) (1 diff)
- trunk/lib/merb/mixins/basic_authentication.rb (modified) (2 diffs)
- trunk/lib/merb/mixins/controller.rb (modified) (1 diff)
- trunk/lib/merb/mixins/general_controller.rb (modified) (2 diffs)
- trunk/lib/merb/mixins/render.rb (modified) (1 diff)
- trunk/lib/merb/mixins/view_context.rb (modified) (1 diff)
- trunk/lib/merb/mongrel_handler.rb (modified) (7 diffs)
- trunk/lib/merb/plugins.rb (modified) (1 diff)
- trunk/lib/merb/server.rb (modified) (10 diffs)
- trunk/lib/merb/session/cookie_store.rb (modified) (2 diffs)
- trunk/lib/merb/session/mem_cache_session.rb (modified) (2 diffs)
- trunk/lib/merb/session/memory_session.rb (modified) (3 diffs)
- trunk/lib/merb/template/erubis.rb (modified) (2 diffs)
- trunk/lib/merb/template/haml.rb (modified) (1 diff)
- trunk/lib/merb/upload_handler.rb (modified) (1 diff)
- trunk/lib/merb/view_context.rb (modified) (1 diff)
- trunk/rspec_generators/merb_controller_test/merb_controller_test_generator.rb (modified) (1 diff)
- trunk/spec/fixtures/controllers/dispatch_spec_controllers.rb (modified) (1 diff)
- trunk/spec/fixtures/controllers/render_spec_controllers.rb (modified) (1 diff)
- trunk/spec/merb/abstract_controller_spec.rb (modified) (1 diff)
- trunk/spec/merb/assets_spec.rb (modified) (5 diffs)
- trunk/spec/merb/caching_spec.rb (modified) (2 diffs)
- trunk/spec/merb/cookie_store_spec.rb (modified) (1 diff)
- trunk/spec/merb/dependency_spec.rb (modified) (1 diff)
- trunk/spec/merb/dispatch_spec.rb (modified) (1 diff)
- trunk/spec/merb/handler_spec.rb (modified) (4 diffs)
- trunk/spec/merb/mail_controller_spec.rb (modified) (2 diffs)
- trunk/spec/merb/render_spec.rb (modified) (1 diff)
- trunk/spec/merb/responder_spec.rb (modified) (1 diff)
- trunk/spec/merb/server_spec.rb (modified) (1 diff)
- trunk/spec/merb/upload_handler_spec.rb (modified) (1 diff)
- trunk/spec/merb/view_context_spec.rb (modified) (5 diffs)
- trunk/spec/spec_helper.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/README
r1224 r1228 104 104 105 105 To use your choice ORM, install the appropriate gem and uncomment the appropriate +use_orm+ line in 106 M ERB_ROOT/config/dependencies.rb106 Merb.root/config/dependencies.rb 107 107 108 108 === Controllers 109 109 110 (M ERB_ROOT/app/controllers/*)110 (Merb.root/app/controllers/*) 111 111 112 112 Merb controllers inherit from Merb::Controller and contain built in view/template rendering. … … 118 118 you are going to want to end your functions with a call to +render+. By default, +render+ will 119 119 render the view template associated with your action (in default merb that would be 120 M ERB_ROOT/app/views/<controller>/<action>.html.erb - see the View section for more info.)121 122 Controllers can be generated by calling M ERB_ROOT/script/generate controller ControllerName.123 By default, generated controllers inherit from the Application class (M ERB_ROOT/app/controllers/application.rb)120 Merb.root/app/views/<controller>/<action>.html.erb - see the View section for more info.) 121 122 Controllers can be generated by calling Merb.root/script/generate controller ControllerName. 123 By default, generated controllers inherit from the Application class (Merb.root/app/controllers/application.rb) 124 124 which itself inherits from Merb:Controller. Application is a good place to put code pertinent to all controllers. 125 125 An example would be setting a filter to check if a user is logged in or to preload user data for each controller. … … 179 179 === Views 180 180 181 (M ERB_ROOT/app/views/*)181 (Merb.root/app/views/*) 182 182 183 183 A view can be loosely defined as any data sent back to the client (a "view" of your data.) … … 186 186 By default, a call to +render+ without any options renders the view template associated 187 187 with that controller action. Using the default ERB templating system, this means that a 188 call to +render+ in Posts#index would render the file M ERB_ROOT/app/views/posts/index.html.erb188 call to +render+ in Posts#index would render the file Merb.root/app/views/posts/index.html.erb 189 189 190 190 ==== Layouts 191 191 192 (M ERB_ROOT/app/views/layout/*)192 (Merb.root/app/views/layout/*) 193 193 194 194 Layouts are generic templates in which your specific view templates are rendered. A sample … … 206 206 207 207 By default, +render+ will look for a corresponding layout for your controller in the form 208 of M ERB_ROOT/app/views/layout/<controller>.html.erb . If no specific layout is present,209 +render+ will attempt to use M ERB_ROOT/app/view/layout/application.html.erb208 of Merb.root/app/views/layout/<controller>.html.erb . If no specific layout is present, 209 +render+ will attempt to use Merb.root/app/view/layout/application.html.erb 210 210 211 211 <i>See #render for more details/options, as well as how to use different templating systems … … 230 230 === Helpers 231 231 232 (M ERB_ROOT/app/helpers/*)232 (Merb.root/app/helpers/*) 233 233 234 234 app/helpers/global_helper.rb will be available to all of your views. … … 242 242 def upload 243 243 puts params[:file].inspect 244 FileUtils.mv params[:file][:tempfile].path, M ERB_ROOT+"/uploads/#{params[:file][:filename]}"244 FileUtils.mv params[:file][:tempfile].path, Merb.root+"/uploads/#{params[:file][:filename]}" 245 245 render 246 246 end trunk/Rakefile
r1224 r1228 77 77 desc "Run :package and install the resulting .gem" 78 78 task :install => :package do 79 sh %{#{SUDO} gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no- update-sources --no-rdoc --no-ri}79 sh %{#{SUDO} gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri} 80 80 end 81 81 trunk/app_generators/merb/templates/config/dependencies.rb
r910 r1228 1 1 # Make the app's "gems" directory a place where gems are loaded from 2 2 Gem.clear_paths 3 Gem.path.unshift(M ERB_ROOT/ "gems")3 Gem.path.unshift(Merb.root / "gems") 4 4 5 5 # Make the app's "lib" directory a place where ruby files get "require"d from 6 $LOAD_PATH.unshift(M ERB_ROOT/ "lib")6 $LOAD_PATH.unshift(Merb.root / "lib") 7 7 8 8 ### Merb doesn't come with database support by default. You need … … 35 35 # dependencies "RedCloth" => "> 3.0", "ruby-aes-cext" => "= 1.0" 36 36 37 Merb:: Server.after_app_loads do37 Merb::BootLoader.after_app_loads do 38 38 ### Add dependencies here that must load after the application loads: 39 39 trunk/app_generators/merb/templates/config/merb_init.rb
r853 r1228 5 5 # Your app's dependencies, including your database layer (if any) are defined 6 6 # in config/dependencies.rb 7 require File.join(M ERB_ROOT, 'config', 'dependencies')7 require File.join(Merb.root, 'config', 'dependencies') 8 8 9 9 # Here's where your controllers, helpers, and models, etc. get loaded. If you … … 11 11 # around this file. 12 12 puts "Loading Application..." 13 Merb:: Server.load_application13 Merb::BootLoader.load_application 14 14 15 15 # Load environment-specific configuration 16 require File.join(M ERB_ROOT, 'config', 'environments', MERB_ENV)16 require File.join(Merb.root, 'config', 'environments', Merb.environment) trunk/lib/merb.rb
r1176 r1228 27 27 require 'mongrel' 28 28 end 29 require 'set' 29 30 require 'fileutils' 30 31 require 'merb/erubis_ext' 31 32 require 'merb/logger' 33 require 'merb/version' 32 34 33 require 'set'34 35 autoload :MerbUploadHandler, 'merb/upload_handler' 35 36 autoload :MerbHandler, 'merb/mongrel_handler' 36 37 37 require 'merb/version' 38 module Merb 39 autoload :AbstractController, 'merb/abstract_controller' 40 autoload :Assets, 'merb/assets' 41 autoload :Authentication, 'merb/mixins/basic_authentication' 42 autoload :Caching, 'merb/caching' 43 autoload :Const, 'merb/constants' 44 autoload :Controller, 'merb/controller' 45 autoload :ControllerExceptions, 'merb/exceptions' 46 autoload :ControllerMixin, 'merb/mixins/controller' 47 autoload :Dispatcher, 'merb/dispatcher' 48 autoload :DrbServiceProvider, 'drb_server' 49 autoload :ErubisCaptureMixin, 'merb/mixins/erubis_capture' 50 autoload :GeneralControllerMixin, 'merb/mixins/general_controller' 51 autoload :InlinePartialMixin, 'merb/mixins/inline_partial' 52 autoload :MailController, 'merb/mail_controller' 53 autoload :Mailer, 'merb/mailer' 54 autoload :PartController, 'merb/part_controller' 55 autoload :Plugins, 'merb/plugins' 56 autoload :Rack, 'merb/rack_adapter' 57 autoload :RenderMixin, 'merb/mixins/render' 58 autoload :Request, 'merb/request' 59 autoload :ResponderMixin, 'merb/mixins/responder' 60 autoload :Router, 'merb/router' 61 autoload :Server, 'merb/server' 62 autoload :SessionMixin, 'merb/session' 63 autoload :Template, 'merb/template' 64 autoload :UploadProgress, 'merb/upload_progress' 65 autoload :ViewContext, 'merb/view_context' 66 autoload :ViewContextMixin, 'merb/mixins/view_context' 67 autoload :WebControllerMixin, 'merb/mixins/web_controller' 68 69 # This is where Merb-global variables are set and held 70 class << self 71 def environment 72 @environment 73 end 74 75 def environment=(value) 76 @environment ||= value 77 end 78 79 def load_paths 80 [ "/app/models/**/*.rb", 81 "/app/controllers/application.rb", 82 "/app/controllers/**/*.rb", 83 "/app/helpers/**/*.rb", 84 "/app/mailers/**/*.rb", 85 "/app/parts/**/*.rb", 86 "/config/router.rb" 87 ] 88 end 89 90 # Application paths 91 def root 92 @root || Merb::Config[:merb_root] || Dir.pwd 93 end 94 95 def root_path(*path) 96 File.join(root, *path) 97 end 98 99 def view_path 100 root_path 'app/views' 101 end 102 103 def model_path 104 root_path 'app/models' 105 end 106 107 def application_controller_path 108 root_path 'app/controllers/application.rb' 109 end 110 111 def controller_path 112 root_path 'app/controllers' 113 end 114 115 def helper_path 116 root_path 'app/helpers' 117 end 118 119 def mailer_path 120 root_path 'app/mailers' 121 end 122 123 def part_path 124 root_path 'app/parts' 125 end 126 127 def router_path 128 root_path '/config/router.rb' 129 end 130 131 def root=(value) 132 @root ||= value 133 end 134 135 136 # Logger settings 137 attr :logger, true 138 139 def log_path 140 if $TESTING 141 "#{Merb.root}/log/merb_test.log" 142 elsif !(Merb::Config[:daemonize] || Merb::Config[:cluster] ) 143 STDOUT 144 else 145 "#{Merb.root}/log/merb.#{Merb::Config[:port]}.log" 146 end 147 end 148 149 # Framework paths 150 151 def framework_root 152 @framework_root ||= File.dirname(__FILE__) 153 end 154 155 def framework_path(path) 156 File.join(framework_root, path) 157 end 158 159 def lib_path 160 framework_path 'merb' 161 end 162 163 def skeleton_path 164 framework_path '../app_generators/merb/templates' 165 end 166 end 38 167 39 module Merb40 autoload :Authentication, 'merb/mixins/basic_authentication'41 autoload :ControllerMixin, 'merb/mixins/controller'42 autoload :ErubisCaptureMixin, 'merb/mixins/erubis_capture'43 autoload :InlinePartialMixin, 'merb/mixins/inline_partial'44 autoload :FormControls, 'merb/mixins/form_control'45 autoload :RenderMixin, 'merb/mixins/render'46 autoload :ResponderMixin, 'merb/mixins/responder'47 autoload :ViewContextMixin, 'merb/mixins/view_context'48 autoload :WebControllerMixin, 'merb/mixins/web_controller'49 autoload :GeneralControllerMixin, 'merb/mixins/general_controller'50 autoload :Caching, 'merb/caching'51 autoload :AbstractController, 'merb/abstract_controller'52 autoload :Const, 'merb/constants'53 autoload :Controller, 'merb/controller'54 autoload :Dispatcher, 'merb/dispatcher'55 autoload :DrbServiceProvider, 'drb_server'56 autoload :ControllerExceptions, 'merb/exceptions'57 autoload :MailController, 'merb/mail_controller'58 autoload :Mailer, 'merb/mailer'59 autoload :PartController, 'merb/part_controller'60 autoload :Request, 'merb/request'61 autoload :Router, 'merb/router'62 autoload :Server, 'merb/server'63 autoload :UploadProgress, 'merb/upload_progress'64 autoload :ViewContext, 'merb/view_context'65 autoload :SessionMixin, 'merb/session'66 autoload :Template, 'merb/template'67 autoload :Plugins, 'merb/plugins'68 autoload :Rack,'merb/rack_adapter'69 autoload :Assets, 'merb/assets'70 71 # Set up Merb::Server.config[] as an accessor for @@merb_opts72 class Server73 class << self74 def config() @@merb_opts ||= {} end75 end76 end77 78 168 # Set up default generator scope 79 169 GENERATOR_SCOPE = [:merb_default, :merb, :rspec] 80 170 end 81 171 82 def __DIR__; File.dirname(__FILE__); end 83 lib = File.join(__DIR__, 'merb')84 require File.join(__DIR__, 'merb/core_ext')172 # Load up the core extensions 173 require Merb.framework_path('merb/core_ext') 174 require Merb.framework_path('merb/version') 85 175 86 unless Object.const_defined?('MERB_ENV') 87 MERB_ENV = Merb::Server.config[:environment].nil? ? ($TESTING ? 'test' : 'development') : Merb::Server.config[:environment] 88 end 176 # Set the environment 177 Merb.environment = Merb::Config[:environment] || ($TESTING ? 'test' : 'development') 89 178 90 MERB_FRAMEWORK_ROOT = __DIR__ 91 MERB_ROOT = Merb::Server.config[:merb_root] || Dir.pwd 92 MERB_VIEW_ROOT = MERB_ROOT / "app/views" 93 MERB_SKELETON_DIR = File.join(MERB_FRAMEWORK_ROOT, '../app_generators/merb/templates') 94 logpath = if $TESTING 95 "#{MERB_ROOT}/log/merb_test.log" 96 elsif !(Merb::Server.config[:daemonize] || Merb::Server.config[:cluster] ) 97 STDOUT 98 else 99 "#{MERB_ROOT}/log/merb.#{Merb::Server.config[:port]}.log" 100 end 101 FileUtils.mkdir_p(File.dirname(logpath)) if logpath.is_a?(String) 102 MERB_LOGGER = Merb::Logger.new(logpath) 103 MERB_LOGGER.level = Merb::Logger.const_get(Merb::Server.config[:log_level].upcase) rescue Merb::Logger::INFO 104 MERB_PATHS = [ 105 "/app/models/**/*.rb", 106 "/app/controllers/application.rb", 107 "/app/controllers/**/*.rb", 108 "/app/helpers/**/*.rb", 109 "/app/mailers/**/*.rb", 110 "/app/parts/**/*.rb", 111 "/config/router.rb" 112 ] 113 114 if $TESTING 115 test_files = File.join(lib, 'test', '*.rb') 116 Dir[test_files].each { |file| require file } 117 end 118 119 # If we're in the TEST environment or if running from Rake make sure to load 120 # config/merb.yml - which is normally done by Merb::Server.run 121 Merb::Server.load_config if $TESTING || $RAKE_ENV 179 # Create and setup the logger 180 Merb.logger = Merb::Logger.new(Merb.log_path) 181 Merb.logger.level = Merb::Logger.const_get(Merb::Config[:log_level].upcase) rescue Merb::Logger::INFO 122 182 123 183 # If you don't use the JSON gem, disable auto-parsing of json params too 124 if Merb:: Server.config[:disable_json_gem]184 if Merb::Config[:disable_json_gem] 125 185 Merb::Request::parse_json_params = false 126 186 else … … 132 192 end 133 193 end 194 195 if $TESTING 196 test_files = File.join(Merb.lib_path, 'test', '*.rb') 197 Dir[test_files].each { |file| require file } 198 end trunk/lib/merb/abstract_controller.rb
r1156 r1228 264 264 ) unless [Symbol, String].include? filter.class 265 265 266 M ERB_LOGGER.warn("Filter #{filter} was not found in your filter chain."266 Merb::Logger.warn("Filter #{filter} was not found in your filter chain." 267 267 ) unless filters.reject! {|f| f.first.to_s[filter.to_s] } 268 268 end trunk/lib/merb/assets.rb
r1137 r1228 5 5 # :bundle_assets is explicitly enabled), false if not. 6 6 def self.bundle? 7 (Merb:: Server.config[:environment] == :production) ||8 (!!Merb:: Server.config[:bundle_assets])7 (Merb::Config[:environment] == :production) || 8 (!!Merb::Config[:bundle_assets]) 9 9 end 10 10 … … 18 18 19 19 # Returns the URI path to a particular asset file. If +local_path+ is 20 # true, returns the path relative to the M ERB_ROOT, not the public20 # true, returns the path relative to the Merb.root, not the public 21 21 # directory. Uses the path_prefix, if any is configured. 22 22 # … … 32 32 return "public#{filename}" 33 33 else 34 return "#{Merb:: Server.config[:path_prefix]}#{filename}"34 return "#{Merb::Config[:path_prefix]}#{filename}" 35 35 end 36 36 end trunk/lib/merb/caching.rb
r187 r1228 1 corelib = __DIR__+'/merb/caching'1 corelib = Merb.framework_root + '/merb/caching' 2 2 3 3 %w[ action_cache trunk/lib/merb/caching/action_cache.rb
r590 r1228 63 63 64 64 def _caching_enabled? 65 ::Merb:: Server.config[:cache_templates]65 ::Merb::Config[:cache_templates] 66 66 end 67 67 trunk/lib/merb/caching/fragment_cache.rb
r590 r1228 26 26 27 27 def determine_cache_store 28 if ::Merb:: Server.config[:cache_store].to_s == "file"28 if ::Merb::Config[:cache_store].to_s == "file" 29 29 require 'merb/caching/store/file_cache' 30 30 ::Merb::Caching::Store::FileCache.new trunk/lib/merb/caching/store/file_cache.rb
r762 r1228 10 10 11 11 def initialize(name = "cache", keepalive = nil) 12 @path = File.join(M ERB_ROOT, name)12 @path = File.join(Merb.root, name) 13 13 @keepalive = keepalive 14 14 end trunk/lib/merb/controller.rb
r1159 r1228 19 19 # === Session Store 20 20 # 21 # The session store is set in M ERB_ROOT/config/merb.yml :21 # The session store is set in Merb.root/config/merb.yml : 22 22 # 23 23 # :session_store: your_store … … 84 84 def set_dispatch_variables(request, response, status, headers) 85 85 if request.params.key?(_session_id_key) 86 if Merb:: Server.config[:session_id_cookie_only]86 if Merb::Config[:session_id_cookie_only] 87 87 # This condition allows for certain controller/action paths to allow 88 88 # a session ID to be passed in a query string. This is needed for … … 91 91 # advantage of this in case someone is attempting a session fixation 92 92 # attack 93 if Merb:: Server.config[:query_string_whitelist].include?("#{request.controller_name}/#{request.action}")93 if Merb::Config[:query_string_whitelist].include?("#{request.controller_name}/#{request.action}") 94 94 # FIXME to use routes not controller and action names -----^ 95 95 request.cookies[_session_id_key] = request.params[_session_id_key] … … 116 116 end 117 117 @_benchmarks[:action_time] = Time.now - start 118 M ERB_LOGGER.info("Time spent in #{self.class}##{action} action: #{@_benchmarks[:action_time]} seconds")118 Merb.logger.info("Time spent in #{self.class}##{action} action: #{@_benchmarks[:action_time]} seconds") 119 119 end 120 120 trunk/lib/merb/core_ext/kernel.rb
r1185 r1228 10 10 begin 11 11 # If it's not in ROOT/gems, skip to the next attempt 12 raise LoadError unless File.directory?(M ERB_ROOT/ "gems")12 raise LoadError unless File.directory?(Merb.root / "gems") 13 13 14 14 # cache the gem path 15 15 begin 16 16 # Clear out the paths and reset them to Merb 17 Gem.use_paths(M ERB_ROOT / "gems", [MERB_ROOT/ "gems"])17 Gem.use_paths(Merb.root / "gems", [Merb.root / "gems"]) 18 18 19 19 # Try activating the gem (Failure will raise a LoadError) 20 20 Gem.activate(name, true, *ver) 21 M ERB_LOGGER.info("#{Time.now.httpdate}: loading gem '#{name}' from #{__app_file_trace__.first} ...")21 Merb.logger.info("#{Time.now.httpdate}: loading gem '#{name}' from #{__app_file_trace__.first} ...") 22 22 ensure 23 23 # Either way, set the gem path back to normal … … 30 30 # Try activating again 31 31 Gem.activate(name, true, *ver) 32 M ERB_LOGGER.info("#{Time.now.httpdate}: loading gem '#{name}' from #{__app_file_trace__.first} ...")32 Merb.logger.info("#{Time.now.httpdate}: loading gem '#{name}' from #{__app_file_trace__.first} ...") 33 33 rescue LoadError 34 34 # Failed requiring as a gem, let's try loading with a normal require. … … 63 63 message = "#{Time.now.httpdate}: loading library '#{library}' from #{__app_file_trace__.first} ..." 64 64 puts(message) 65 M ERB_LOGGER.info(message)65 Merb.logger.info(message) 66 66 rescue LoadError 67 67 # TODO: adjust the two messages below to use merb's logger.error/info once logging refactor is complete. 68 68 message = "#{Time.now.httpdate}: <e> Could not find '#{library}' as either a library or gem, loaded from #{__app_file_trace__.first}.\n" 69 69 puts(message) 70 M ERB_LOGGER.error(message)70 Merb.logger.error(message) 71 71 72 72 # Print a helpful message … … 75 75 message << "#{Time.now.httpdate}: <i> * is included within a gem, be sure that you are specifying the gem as a dependency \n" 76 76 puts(message) 77 M ERB_LOGGER.error(message)77 Merb.logger.error(message) 78 78 exit() # Missing library/gem must be addressed. 79 79 end … … 88 88 end 89 89 90 # Used in M ERB_ROOT/dependencies.yml90 # Used in Merb.root/dependencies.yml 91 91 # Tells merb which ORM (Object Relational Mapper) you wish to use. 92 92 # Currently merb has plugins to support ActiveRecord, DataMapper, and Sequel. … … 107 107 end 108 108 109 # Used in M ERB_ROOT/dependencies.yml109 # Used in Merb.root/dependencies.yml 110 110 # Tells merb which testing framework to use. 111 111 # Currently merb supports rspec and test_unit for testing … … 129 129 def __app_file_trace__ 130 130 caller.select do |call| 131 call.include?(M ERB_ROOT) && !call.include?(MERB_ROOT+ "/framework")131 call.include?(Merb.root) && !call.include?(Merb.root + "/framework") 132 132 end.map do |call| 133 file, line = call.scan(Regexp.new("#{M ERB_ROOT}/(.*):(.*)")).first133 file, line = call.scan(Regexp.new("#{Merb.root}/(.*):(.*)")).first 134 134 "#{file}:#{line}" 135 135 end … … 193 193 # Requires ruby-prof (<tt>sudo gem install ruby-prof</tt>) 194 194 # Takes a block and profiles the results of running the block 100 times. 195 # The resulting profile is written out to M ERB_ROOT/log/#{name}.html.195 # The resulting profile is written out to Merb.root/log/#{name}.html. 196 196 # <tt>min</tt> specifies the minimum percentage of the total time a method must take for it to be included in the result. 197 197 # … … 211 211 end 212 212 printer = RubyProf::GraphHtmlPrinter.new(result) 213 path = File.join(M ERB_ROOT, 'log', "#{name}.html")213 path = File.join(Merb.root, 'log', "#{name}.html") 214 214 File.open(path, 'w') do |file| 215 215 printer.print(file, {:min_percent => min, … … 235 235 # Drops a not to the logs that Debugger was not available 236 236 def debugger 237 M ERB_LOGGER.info "\n***** Debugger requested, but was not " +237 Merb.logger.info "\n***** Debugger requested, but was not " + 238 238 "available: Start server with --debugger " + 239 239 "to enable *****\n" trunk/lib/merb/dispatcher.rb
r1059 r1228 3 3 4 4 DEFAULT_ERROR_TEMPLATE = Erubis::MEruby.new((File.read( 5 File.join(M ERB_ROOT, 'app/views/exceptions/internal_server_error.html.erb')) rescue "Internal Server Error!"))5 File.join(Merb.root, 'app/views/exceptions/internal_server_error.html.erb')) rescue "Internal Server Error!")) 6 6 7 7 class << self … … 12 12 13 13 @@mutex = Mutex.new 14 @@use_mutex = ::Merb:: Server.config[:use_mutex]14 @@use_mutex = ::Merb::Config[:use_mutex] 15 15 # This is where we grab the incoming request REQUEST_URI and use that in 16 16 # the merb RouteMatcher to determine which controller and method to run. … … 22 22 start = Time.now 23 23 request = Merb::Request.new(http_request) 24 M ERB_LOGGER.info("Params: #{request.params.inspect}")25 M ERB_LOGGER.info("Cookies: #{request.cookies.inspect}")24 Merb.logger.info("Params: #{request.params.inspect}") 25 Merb.logger.info("Cookies: #{request.cookies.inspect}") 26 26 # user friendly error messages 27 27 if request.route_params.empty? … … 30 30 raise ControllerExceptions::BadRequest, "Route matched, but route did not specify a controller" 31 31 end 32 M ERB_LOGGER.debug("Routed to: #{request.route_params.inspect}")32 Merb.logger. debug("Routed to: #{request.route_params.inspect}") 33 33 # set controller class and the action to call 34 34 klass = request.controller_class 35 35 dispatch_action(klass, request.action, request, response) 36 36 rescue => exception 37 M ERB_LOGGER.error(Merb.exception(exception))37 Merb.logger.error(Merb.exception(exception)) 38 38 exception = controller_exception(exception) 39 39 dispatch_exception(request, response, exception) trunk/lib/merb/logger.rb
r1092 r1228 29 29 @log.write("# Logfile created on %s\n" % [Time.now.to_s]) 30 30 end 31 if !M ERB_ENV.match(/development|test/) &&31 if !Merb.environment.match(/development|test/) && 32 32 !RUBY_PLATFORM.match(/java|mswin/) && 33 33 !(@log == STDOUT) && trunk/lib/merb/mail_controller.rb
r1120 r1228 184 184 # An error should be logged if no template is found instead of an error raised 185 185 if @_missing_templates 186 M ERB_LOGGER.error(e)186 Merb.logger.error(e) 187 187 else 188 188 @_missing_templates = true … … 238 238 if !@mail.html.blank? || !@mail.text.blank? 239 239 @mailer.deliver! 240 M ERB_LOGGER.info "#{method} sent to #{@mail.to} about #{@mail.subject}"240 Merb.logger.info "#{method} sent to #{@mail.to} about #{@mail.subject}" 241 241 else 242 M ERB_LOGGER.info "#{method} was not sent because nothing was rendered for it"242 Merb.logger.info "#{method} was not sent because nothing was rendered for it" 243 243 end 244 244 end trunk/lib/merb/mailer.rb
r1173 r1228 4 4 rescue LoadError 5 5 puts "You need to install the mailfactory gem to use Merb::Mailer" 6 M ERB_LOGGER.warn "You need to install the mailfactory gem to use Merb::Mailer"6 Merb::Logger.warn "You need to install the mailfactory gem to use Merb::Mailer" 7 7 end 8 8 trunk/lib/merb/mixins/basic_authentication.rb
r820 r1228 14 14 def authenticated? 15 15 username, password = *credentials 16 username == Merb:: Server.config[:basic_auth][:username] and password == Merb::Server.config[:basic_auth][:password]16 username == Merb::Config[:basic_auth][:username] and password == Merb::Config[:basic_auth][:password] 17 17 end 18 18 … … 27 27 headers['Content-type'] = 'text/plain' 28 28 headers['Status'] = 'Unauthorized' 29 headers['WWW-Authenticate'] = "Basic realm=\"#{Merb:: Server.config[:basic_auth][:domain]}\""29 headers['WWW-Authenticate'] = "Basic realm=\"#{Merb::Config[:basic_auth][:domain]}\"" 30 30 return 'Unauthorized' 31 31 end trunk/lib/merb/mixins/controller.rb
r1080 r1228 67 67 # 68 68 def redirect(url) 69 M ERB_LOGGER.info("Redirecting to: #{url}")69 Merb.logger.info("Redirecting to: #{url}") 70 70 set_status(302) 71 71 headers['Location'] = url trunk/lib/merb/mixins/general_controller.rb
r1188 r1228 87 87 raise "URL not generated: #{route_name.inspect}, #{new_params.inspect}" 88 88 end 89 url = Merb:: Server.config[:path_prefix] + url if Merb::Server.config[:path_prefix]89 url = Merb::Config[:path_prefix] + url if Merb::Config[:path_prefix] 90 90 url 91 91 end … … 193 193 # 194 194 def format_extension(new_params={}) 195 use_format = Merb:: Server.config[:use_format_in_urls]195 use_format = Merb::Config[:use_format_in_urls] 196 196 if use_format.nil? 197 197 prms = params.merge(new_params) trunk/lib/merb/mixins/render.rb
r1226 r1228 13 13 14 14 self._layout = :application 15 self._template_root = File.expand_path(M ERB_VIEW_ROOT)15 self._template_root = File.expand_path(Merb. view_path) 16 16 self._templates = {} 17 17 self._cached_partials = {} trunk/lib/merb/mixins/view_context.rb
r1139 r1228 56 56 '' 57 57 else 58 if Merb:: Server.config[:path_prefix]59 Merb:: Server.config[:path_prefix] + '/images/'58 if Merb::Config[:path_prefix] 59 Merb::Config[:path_prefix] + '/images/' 60 60 else 61 61 '/images/' trunk/lib/merb/mongrel_handler.rb
r1039 r1228 50 50 benchmarks = {} 51 51 52 M ERB_LOGGER.info("\nRequest: REQUEST_URI: #{52 Merb.logger.info("\nRequest: REQUEST_URI: #{ 53 53 request.params[Mongrel::Const::REQUEST_URI]} (#{Time.now.strftime("%Y-%m-%d %H:%M:%S")})") 54 54 … … 57 57 if @@path_prefix 58 58 if request.params[Mongrel::Const::PATH_INFO] =~ @@path_prefix 59 M ERB_LOGGER.info("Path prefix #{@@path_prefix.inspect} removed from PATH_INFO and REQUEST_URI.")59 Merb.logger.info("Path prefix #{@@path_prefix.inspect} removed from PATH_INFO and REQUEST_URI.") 60 60 request.params[Mongrel::Const::PATH_INFO].sub!(@@path_prefix, '') 61 61 request.params[Mongrel::Const::REQUEST_URI].sub!(@@path_prefix, '') … … 76 76 if get_or_head && @files.can_serve(path_info) 77 77 # File exists as-is so serve it up 78 M ERB_LOGGER.info("Serving static file: #{path_info}")78 Merb.logger.info("Serving static file: #{path_info}") 79 79 @files.process(request,response) 80 80 elsif get_or_head && @files.can_serve(page_cached) 81 81 # Possible cached page, serve it up 82 M ERB_LOGGER.info("Serving static file: #{page_cached}")82 Merb.logger.info("Serving static file: #{page_cached}") 83 83 request.params[Mongrel::Const::PATH_INFO] = page_cached 84 84 @files.process(request,response) … … 90 90 benchmarks[:action] = action 91 91 92 M ERB_LOGGER.info("Routing to controller: #{controller.class} action: #{action}\nRoute Recognition & Parsing HTTP Input took: #{benchmarks[:setup_time]} seconds")92 Merb.logger.info("Routing to controller: #{controller.class} action: #{action}\nRoute Recognition & Parsing HTTP Input took: #{benchmarks[:setup_time]} seconds") 93 93 94 94 sendfile, clength = nil … … 112 112 # we want to emulate X-Sendfile header internally in mongrel 113 113 benchmarks[:sendfile_time] = Time.now - start 114 M ERB_LOGGER.info("X-SENDFILE: #{sendfile}\nComplete Request took: #{114 Merb.logger.info("X-SENDFILE: #{sendfile}\nComplete Request took: #{ 115 115 benchmarks[:sendfile_time]} seconds") 116 116 file_status = File.stat(sendfile) … … 153 153 benchmarks[:total_request_time] = total_request_time 154 154 155 M ERB_LOGGER.info("Request Times: #{benchmarks.inspect}\nResponse status: #{response.status}\nComplete Request took: #{total_request_time} seconds, #{1.0/total_request_time} Requests/Second\n\n")155 Merb.logger.info("Request Times: #{benchmarks.inspect}\nResponse status: #{response.status}\nComplete Request took: #{total_request_time} seconds, #{1.0/total_request_time} Requests/Second\n\n") 156 156 end 157 157 rescue Object => e … … 162 162 response.send_header 163 163 response.write("500 Internal Server Error") 164 M ERB_LOGGER.error(Merb.exception(e))164 Merb.logger.error(Merb.exception(e)) 165 165 ensure 166 M ERB_LOGGER.flush166 Merb.logger.flush 167 167 end 168 168 end trunk/lib/merb/plugins.rb
r708 r1228 2 2 module Plugins 3 3 def self.config 4 @config ||= File.exists?(M ERB_ROOT / "config" / "plugins.yml") ? YAML.load(File.read(MERB_ROOT/ "config" / "plugins.yml")) || {} : {}4 @config ||= File.exists?(Merb.root / "config" / "plugins.yml") ? YAML.load(File.read(Merb.root / "config" / "plugins.yml")) || {} : {} 5 5 end 6 6
