Changeset 286

Show
Ignore:
Timestamp:
06/15/07 20:36:06 (1 year ago)
Author:
e.@brainspl.at
Message:

lots of little refactors. protected and private methods are not callable from the web now. bump version to 0.3.6

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Rakefile

    r279 r286  
    1616 
    1717NAME = "merb" 
    18 VERS = "0.3.5
     18VERS = "0.3.6
    1919CLEAN.include ['**/.*.sw?', '*.gem', '.config'] 
    2020 
  • trunk/bin/merb

    r121 r286  
    1 #!/usr/local/bin/ruby 
     1#!/usr/bin/env ruby 
    22 
    33require 'rubygems' 
  • trunk/lib/merb.rb

    r281 r286  
    1616 
    1717module Merb 
    18   VERSION='0.3.4' unless defined?VERSION 
     18  VERSION='0.3.6' unless defined?VERSION 
    1919  class Server 
    2020    class << self 
  • trunk/lib/merb/merb_abstract_controller.rb

    r263 r286  
    33module Merb 
    44   
    5   class AbstractController 
     5  class AbstractController                  
    66    include Merb::RenderMixin 
    7  
     7     
    88    class_inheritable_accessor :before_filters 
    99    class_inheritable_accessor :after_filters 
    10  
     10     
    1111    def dispatch(action=:to_s) 
    12       start = Time.now 
    13       setup_session if respond_to?:setup_session 
    1412      caught = catch(:halt) { call_filters(before_filters) } 
    1513      @body = case caught 
     
    2826      end 
    2927      call_filters(after_filters)  
    30       finalize_session if respond_to?:finalize_session 
    31       MERB_LOGGER.info("Time spent in #{self.class}##{action} action: #{Time.now - start} seconds") 
    3228    end 
    33    
     29     
     30  protected 
     31     
    3432    # calls a filter chain according to rules. 
    3533    def call_filters(filter_set) 
  • trunk/lib/merb/merb_controller.rb

    r284 r286  
    1313  # puts that into params as well. 
    1414  class Controller < AbstractController 
     15 
    1516     
    1617    class_inheritable_accessor :_session_id_key  
     
    2021    include Merb::ResponderMixin 
    2122    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 
    2239     
    23     attr_accessor :status, :body, :request 
     40     
     41    attr_reader :status, :body, :request 
    2442 
    2543    MULTIPART_REGEXP = /\Amultipart\/form-data.*boundary=\"?([^\";,]+)/n.freeze 
     
    6482    end 
    6583 
     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       
    66100    # accessor for @request. Please use request and  
    67101    # never @request directly. 
  • trunk/lib/merb/merb_exceptions.rb

    r214 r286  
    1717  # format exception message for browser display   
    1818  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 
    2024  end   
    2125   
  • trunk/lib/merb/merb_part_controller.rb

    r269 r286  
    33    self._template_root = File.expand_path(DIST_ROOT / "app/parts/views") 
    44     
    5     def initialize(web_controller=self
     5    def initialize(web_controller
    66      @web_controller = web_controller 
    77    end 
     
    1010      old_action = params[:action] 
    1111      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) 
    2813      params[:action] = old_action 
    29       body 
     14      @body 
    3015    end 
    3116     
  • trunk/lib/merb/merb_plugins.rb

    r282 r286  
    99  class PluginManager 
    1010     
    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 
    1235 
    1336    # Run a particular plugin action 
     
    4265      raise "Plugin already installed!" if plugin_installed? 
    4366       
    44       gem_spec = find_locally or install_gem  
     67      self.gem_spec = find_locally or install_gem  
    4568       
    4669      run_install_script 
     
    137160        installer = Gem::RemoteInstaller.new(options) 
    138161         
    139         options.each do |opt| 
     162        @@options.each do |opt| 
    140163          installer.sources << opt.gsub(/source=/, '') if opt.scan(/^source=/) != [] 
    141164          options[:version] = "> #{opt.gsub(/version=/, '')}" if opt.scan(/^version=/) != [] 
  • trunk/lib/merb/merb_router.rb

    r246 r286  
    77    class << self 
    88       
    9       def prepare(&block) 
     9      def prepare 
    1010        @@matcher = RouteMatcher.new 
    1111        @@generator = RouteGenerator.new 
  • trunk/lib/merb/merb_server.rb

    r281 r286  
    100100          end 
    101101           
    102           opts.on("-P", "--plugin ACTION NAME", "Install a plugin called NAME") do |action| 
     102          opts.on("-P", "--plugin ACTION NAME", "Do ACTION with a plugin called NAME") do |action| 
    103103            options[:plugin] = [action, ARGV] || nil 
    104104          end 
     
    209209        if @@merb_opts[:plugin] 
    210210          require 'merb/merb_plugins' 
    211           require 'pp' 
    212           pp @@merb_opts[:plugin] 
    213211          ::Merb::PluginManager.action(@@merb_opts[:plugin].shift, @@merb_opts[:plugin][0].shift, @@merb_opts[:plugin]) 
    214212          exit! 
  • trunk/lib/merb/merb_view_context.rb

    r279 r286  
    5454     
    5555    def request 
    56       @controller.request   
     56      @controller.request   
    5757    end 
    5858             
  • trunk/lib/merb/mixins/controller_mixin.rb

    r279 r286  
    11module Merb 
    22  module ControllerMixin 
     3     
     4    def url(path, o={}) 
     5      ::Merb::Router.generator.generate(path,o) 
     6    end 
     7     
     8    protected 
    39    NAME_REGEX = /Content-Disposition:.* name="?([^\";]*)"?/ni.freeze 
    410    CONTENT_TYPE_REGEX = /Content-Type: (.*)\r\n/ni.freeze 
     
    100106    end 
    101107     
    102     def url(path, o={}) 
    103       ::Merb::Router.generator.generate(path,o) 
    104     end 
    105108     
    106109    # parses a query string or the payload of a POST 
  • trunk/lib/merb/mixins/render_mixin.rb

    r263 r286  
    121121    end 
    122122 
    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  
    133124     
    134125    # does a render with no layout. Also sets the 
     
    167158    private 
    168159     
     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     
    169171      def wrap_layout(content, opts={}) 
    170172        if opts[:layout] != :application