Changeset 286
- Timestamp:
- 06/15/07 20:36:06 (1 year ago)
- Files:
-
- trunk/Rakefile (modified) (1 diff)
- trunk/bin/merb (modified) (1 diff)
- trunk/lib/merb.rb (modified) (1 diff)
- trunk/lib/merb/merb_abstract_controller.rb (modified) (2 diffs)
- trunk/lib/merb/merb_controller.rb (modified) (3 diffs)
- trunk/lib/merb/merb_exceptions.rb (modified) (1 diff)
- trunk/lib/merb/merb_part_controller.rb (modified) (2 diffs)
- trunk/lib/merb/merb_plugins.rb (modified) (3 diffs)
- trunk/lib/merb/merb_router.rb (modified) (1 diff)
- trunk/lib/merb/merb_server.rb (modified) (2 diffs)
- trunk/lib/merb/merb_view_context.rb (modified) (1 diff)
- trunk/lib/merb/mixins/controller_mixin.rb (modified) (2 diffs)
- trunk/lib/merb/mixins/render_mixin.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Rakefile
r279 r286 16 16 17 17 NAME = "merb" 18 VERS = "0.3. 5"18 VERS = "0.3.6" 19 19 CLEAN.include ['**/.*.sw?', '*.gem', '.config'] 20 20 trunk/bin/merb
r121 r286 1 #!/usr/ local/bin/ruby1 #!/usr/bin/env ruby 2 2 3 3 require 'rubygems' trunk/lib/merb.rb
r281 r286 16 16 17 17 module Merb 18 VERSION='0.3. 4' unless defined?VERSION18 VERSION='0.3.6' unless defined?VERSION 19 19 class Server 20 20 class << self trunk/lib/merb/merb_abstract_controller.rb
r263 r286 3 3 module Merb 4 4 5 class AbstractController 5 class AbstractController 6 6 include Merb::RenderMixin 7 7 8 8 class_inheritable_accessor :before_filters 9 9 class_inheritable_accessor :after_filters 10 10 11 11 def dispatch(action=:to_s) 12 start = Time.now13 setup_session if respond_to?:setup_session14 12 caught = catch(:halt) { call_filters(before_filters) } 15 13 @body = case caught … … 28 26 end 29 27 call_filters(after_filters) 30 finalize_session if respond_to?:finalize_session31 MERB_LOGGER.info("Time spent in #{self.class}##{action} action: #{Time.now - start} seconds")32 28 end 33 29 30 protected 31 34 32 # calls a filter chain according to rules. 35 33 def call_filters(filter_set) trunk/lib/merb/merb_controller.rb
r284 r286 13 13 # puts that into params as well. 14 14 class Controller < AbstractController 15 15 16 16 17 class_inheritable_accessor :_session_id_key … … 20 21 include Merb::ResponderMixin 21 22 extend Merb::StatefulMixin 23 24 class << self 25 def callable_actions 26 @callable_actions ||= Set.new(public_instance_methods - hidden_actions) 27 end 28 29 def hidden_actions 30 write_inheritable_attribute(:hidden_actions, Merb::Controller.public_instance_methods) unless read_inheritable_attribute(:hidden_actions) 31 read_inheritable_attribute(:hidden_actions) 32 end 33 34 # Hide each of the given methods from being callable as actions. 35 def hide_action(*names) 36 write_inheritable_attribute(:hidden_actions, hidden_actions | names.collect { |n| n.to_s }) 37 end 38 end 22 39 23 attr_accessor :status, :body, :request 40 41 attr_reader :status, :body, :request 24 42 25 43 MULTIPART_REGEXP = /\Amultipart\/form-data.*boundary=\"?([^\";,]+)/n.freeze … … 64 82 end 65 83 84 85 86 def dispatch(action=:index) 87 start = Time.now 88 if !self.class.callable_actions.include?(action.to_s) 89 @status = 404 90 @body = IO.read(DIST_ROOT / 'public/404.html') rescue "404: Not Found" 91 MERB_LOGGER.info "Action: #{action} not in callable_actions: #{self.class.callable_actions.inspect}" 92 else 93 setup_session if respond_to?:setup_session 94 super(action) 95 finalize_session if respond_to?:finalize_session 96 end 97 MERB_LOGGER.info("Time spent in #{self.class}##{action} action: #{Time.now - start} seconds") 98 end 99 66 100 # accessor for @request. Please use request and 67 101 # never @request directly. trunk/lib/merb/merb_exceptions.rb
r214 r286 17 17 # format exception message for browser display 18 18 def self.html_exception(e) 19 ::Merb::Server.show_error ? ErrorResponse.new(e).out : "500 Internal Server Error!" 19 if ::Merb::Server.show_error 20 ErrorResponse.new(e).out 21 else 22 IO.read(DIST_ROOT / 'piblic/500.html') rescue "500 Internal Server Error!" 23 end 20 24 end 21 25 trunk/lib/merb/merb_part_controller.rb
r269 r286 3 3 self._template_root = File.expand_path(DIST_ROOT / "app/parts/views") 4 4 5 def initialize(web_controller =self)5 def initialize(web_controller) 6 6 @web_controller = web_controller 7 7 end … … 10 10 old_action = params[:action] 11 11 params[:action] = action 12 caught = catch(:halt) { call_filters(before_filters) } 13 body = case caught 14 when :filter_chain_completed 15 send(action) 16 when String 17 caught 18 when nil 19 filters_halted 20 when Symbol 21 send(caught) 22 when Proc 23 caught.call(self) 24 else 25 raise MerbControllerError, "The part before filter chain is broken dude. wtf?" 26 end 27 call_filters(after_filters) 12 super(action) 28 13 params[:action] = old_action 29 body14 @body 30 15 end 31 16 trunk/lib/merb/merb_plugins.rb
r282 r286 9 9 class PluginManager 10 10 11 cattr_accessor :gem_name, :gem_spec, :options 11 def self.gem_name 12 @@gem_name 13 end 14 15 def self.gem_spec 16 @@gem_spec 17 end 18 19 def self.options 20 @@options 21 end 22 23 def self.gem_name=(val) 24 @@gem_name = val 25 end 26 27 def self.gem_spec=(val) 28 @@gem_spec = val 29 end 30 31 def self.options=(val) 32 @@options = val 33 end 34 12 35 13 36 # Run a particular plugin action … … 42 65 raise "Plugin already installed!" if plugin_installed? 43 66 44 gem_spec = find_locally or install_gem67 self.gem_spec = find_locally or install_gem 45 68 46 69 run_install_script … … 137 160 installer = Gem::RemoteInstaller.new(options) 138 161 139 options.each do |opt|162 @@options.each do |opt| 140 163 installer.sources << opt.gsub(/source=/, '') if opt.scan(/^source=/) != [] 141 164 options[:version] = "> #{opt.gsub(/version=/, '')}" if opt.scan(/^version=/) != [] trunk/lib/merb/merb_router.rb
r246 r286 7 7 class << self 8 8 9 def prepare (&block)9 def prepare 10 10 @@matcher = RouteMatcher.new 11 11 @@generator = RouteGenerator.new trunk/lib/merb/merb_server.rb
r281 r286 100 100 end 101 101 102 opts.on("-P", "--plugin ACTION NAME", " Installa plugin called NAME") do |action|102 opts.on("-P", "--plugin ACTION NAME", "Do ACTION with a plugin called NAME") do |action| 103 103 options[:plugin] = [action, ARGV] || nil 104 104 end … … 209 209 if @@merb_opts[:plugin] 210 210 require 'merb/merb_plugins' 211 require 'pp'212 pp @@merb_opts[:plugin]213 211 ::Merb::PluginManager.action(@@merb_opts[:plugin].shift, @@merb_opts[:plugin][0].shift, @@merb_opts[:plugin]) 214 212 exit! trunk/lib/merb/merb_view_context.rb
r279 r286 54 54 55 55 def request 56 @controller.request56 @controller.request 57 57 end 58 58 trunk/lib/merb/mixins/controller_mixin.rb
r279 r286 1 1 module Merb 2 2 module ControllerMixin 3 4 def url(path, o={}) 5 ::Merb::Router.generator.generate(path,o) 6 end 7 8 protected 3 9 NAME_REGEX = /Content-Disposition:.* name="?([^\";]*)"?/ni.freeze 4 10 CONTENT_TYPE_REGEX = /Content-Type: (.*)\r\n/ni.freeze … … 100 106 end 101 107 102 def url(path, o={})103 ::Merb::Router.generator.generate(path,o)104 end105 108 106 109 # parses a query string or the payload of a POST trunk/lib/merb/mixins/render_mixin.rb
r263 r286 121 121 end 122 122 123 # this returns a ViewContext object populated with all 124 # the instance variables in your controller. This is used 125 # as the view context object for the Erubis templates. 126 def cached_view_context 127 @_view_context_cache ||= ViewContext.new(self) 128 end 129 130 def clean_view_context 131 ViewContext.new(self) 132 end 123 133 124 134 125 # does a render with no layout. Also sets the … … 167 158 private 168 159 160 # this returns a ViewContext object populated with all 161 # the instance variables in your controller. This is used 162 # as the view context object for the Erubis templates. 163 def cached_view_context 164 @_view_context_cache ||= ViewContext.new(self) 165 end 166 167 def clean_view_context 168 ViewContext.new(self) 169 end 170 169 171 def wrap_layout(content, opts={}) 170 172 if opts[:layout] != :application
