merb-core 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -326,7 +326,7 @@ module Merb
326
326
  #
327
327
  # :api: public
328
328
  def escape_xml(obj)
329
- Erubis::XmlHelper.escape_xml(obj.to_s)
329
+ Merb::Parse.escape_xml(obj.to_s)
330
330
  end
331
331
  alias h escape_xml
332
332
  alias escape_html escape_xml
@@ -32,27 +32,29 @@ module Merb::Template
32
32
  path.gsub(/[^\.a-zA-Z0-9]/, "__").gsub(/\./, "_")
33
33
  end
34
34
 
35
- # For a given path, get an IO object that responds to #path.
36
- #
37
- # This is so that plugins can override this if they provide
38
- # mechanisms for specifying templates that are not just simple
39
- # files. The plugin is responsible for ensuring that the fake
40
- # path provided will work with #template_for, and thus the
41
- # RenderMixin in general.
42
- #
43
- # ==== Parameters
44
- # path<String>:: A full path to find a template for. This is the
45
- # path that the RenderMixin assumes it should find the template
46
- # in.
47
- #
48
- # ==== Returns
49
- # IO#path:: An IO object that responds to path (File or VirtualFile).
50
- #
51
- # :api: plugin
52
- # @overridable
53
- def load_template_io(path)
54
- file = Dir["#{path}.{#{template_extensions.join(',')}}"].first
55
- File.open(file, "r") if file
35
+ chainable do
36
+ # For a given path, get an IO object that responds to #path.
37
+ #
38
+ # This is so that plugins can override this if they provide
39
+ # mechanisms for specifying templates that are not just simple
40
+ # files. The plugin is responsible for ensuring that the fake
41
+ # path provided will work with #template_for, and thus the
42
+ # RenderMixin in general.
43
+ #
44
+ # ==== Parameters
45
+ # path<String>:: A full path to find a template for. This is the
46
+ # path that the RenderMixin assumes it should find the template
47
+ # in.
48
+ #
49
+ # ==== Returns
50
+ # IO#path:: An IO object that responds to path (File or VirtualFile).
51
+ #
52
+ # :api: plugin
53
+ # @overridable
54
+ def load_template_io(path)
55
+ file = Dir["#{path}.{#{template_extensions.join(',')}}"].first
56
+ File.open(file, "r") if file
57
+ end
56
58
  end
57
59
 
58
60
  # Get the name of the template method for a particular path.
@@ -7,3 +7,4 @@ end
7
7
 
8
8
  require File.dirname(__FILE__) / "core_ext" / "kernel"
9
9
  require File.dirname(__FILE__) / "core_ext" / "hash"
10
+ require File.dirname(__FILE__) / "core_ext" / "class"
@@ -0,0 +1,34 @@
1
+ class Class
2
+ # Allows the definition of methods on a class that will be available via
3
+ # super.
4
+ #
5
+ # ==== Examples
6
+ # class Foo
7
+ # chainable do
8
+ # def hello
9
+ # "hello"
10
+ # end
11
+ # end
12
+ # end
13
+ #
14
+ # class Foo
15
+ # def hello
16
+ # super + " Merb!"
17
+ # end
18
+ # end
19
+ #
20
+ # Foo.new.hello #=> "hello Merb!"
21
+ #
22
+ # ==== Parameters
23
+ # &blk::
24
+ # a block containing method definitions that should be
25
+ # marked as chainable
26
+ #
27
+ # ==== Returns
28
+ # Module:: The anonymous module that was created
29
+ def chainable(&blk)
30
+ mod = Module.new(&blk)
31
+ include mod
32
+ mod
33
+ end
34
+ end
@@ -194,6 +194,17 @@ module Merb
194
194
  }
195
195
  end
196
196
 
197
+ # ==== Parameters
198
+ # s<String>:: String to XML escape.
199
+ #
200
+ # ==== returns
201
+ # String:: The escaped string.
202
+ #
203
+ # :api: public
204
+ def self.escape_xml(s)
205
+ Erubis::XmlHelper.escape_xml(s)
206
+ end
207
+
197
208
  private
198
209
 
199
210
  # Converts a query string snippet to a hash and adds it to existing
@@ -1,21 +1,55 @@
1
+ begin
2
+ require "ruby-prof"
3
+ rescue LoadError => e
4
+ Merb.fatal! "You need ruby-prof installed to use the profiler middleware", e
5
+ end
6
+
1
7
  module Merb
2
8
  module Rack
3
9
  class Profiler < Merb::Rack::Middleware
4
10
 
5
11
  # :api: private
6
- def initialize(app, min=1, iter=1)
12
+ def initialize(app, types = [RubyProf::ALLOCATIONS, RubyProf::PROCESS_TIME])
7
13
  super(app)
8
- @min, @iter = min, iter
14
+ @types = types
9
15
  end
10
16
 
11
17
  # :api: plugin
12
18
  def call(env)
13
- __profile__("profile_output", @min, @iter) do
14
- @app.call(env)
19
+ measure_names = { RubyProf::ALLOCATIONS => 'allocations',
20
+ RubyProf::PROCESS_TIME => 'time', RubyProf::MEMORY => "memory" }
21
+
22
+ ret = nil
23
+
24
+ GC.disable
25
+ @types.each do |type|
26
+ next if type.nil?
27
+
28
+ if GC.respond_to?(:enable_stats)
29
+ GC.enable_stats || GC.clear_stats
30
+ end
31
+
32
+ RubyProf.measure_mode = type
33
+ RubyProf.start
34
+ 100.times do
35
+ ret = super
36
+ end
37
+ result = RubyProf.stop
38
+ printer = RubyProf::CallTreePrinter.new(result)
39
+ path = "merb_profile_results" / env["PATH_INFO"]
40
+ FileUtils.mkdir_p(path)
41
+ printer.print(
42
+ File.open(
43
+ "#{path}/callgrind.out.#{measure_names[RubyProf::measure_mode]}",
44
+ 'w'))
45
+
46
+ GC.disable_stats if GC.respond_to?(:disable_stats)
15
47
  end
48
+ GC.enable
49
+ ret
16
50
  end
17
51
 
18
52
 
19
53
  end
20
54
  end
21
- end
55
+ end
@@ -1,4 +1,4 @@
1
1
  module Merb
2
- VERSION = '1.0.4' unless defined?(Merb::VERSION)
2
+ VERSION = '1.0.5' unless defined?(Merb::VERSION)
3
3
  DM_VERSION = '0.9.8' unless defined?(Merb::DM_VERSION)
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-08 00:00:00 -08:00
12
+ date: 2008-12-15 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -90,7 +90,7 @@ dependencies:
90
90
  requirements:
91
91
  - - ">="
92
92
  - !ruby/object:Gem::Version
93
- version: 0.9.7
93
+ version: 0.9.9
94
94
  version:
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: webrat
@@ -140,6 +140,7 @@ files:
140
140
  - lib/merb-core/controller/mixins/responder.rb
141
141
  - lib/merb-core/controller/template.rb
142
142
  - lib/merb-core/core_ext
143
+ - lib/merb-core/core_ext/class.rb
143
144
  - lib/merb-core/core_ext/hash.rb
144
145
  - lib/merb-core/core_ext/kernel.rb
145
146
  - lib/merb-core/core_ext.rb