mack 0.8.0 → 0.8.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ === 0.8.0.2
2
+ * [#190] Fixed ViewTemplate methods can easily be overridden
3
+
1
4
  === 0.8.0
2
5
  * [#187] Fixed: When an exception is raised, the request doesn't get 'logged'
3
6
  * [#185] Fixed: .html is being appended to logged requests when there's a 404
@@ -272,7 +272,7 @@ module Mack
272
272
  private
273
273
  def do_render
274
274
  render unless @view_template
275
- @rendered_action = @view_template.compile_and_render
275
+ @rendered_action = @view_template._compile_and_render
276
276
  end
277
277
 
278
278
  def layout
@@ -28,7 +28,7 @@ module Mack
28
28
  # Example:
29
29
  # app/views/users/show.html.erb
30
30
  def render
31
- a_file = File.join(self.controller_view_path, "#{self.render_value}.#{self.options[:format]}")
31
+ a_file = File.join(self.controller_view_path, "#{self._render_value}.#{self._options[:format]}")
32
32
  render_file(a_file)
33
33
  end
34
34
 
@@ -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.new(f), self.binder)
16
+ return @engine.render(File.new(f), self._binder)
17
17
  end
18
18
  end
19
19
  raise Mack::Errors::ResourceNotFound.new(file + ".*")
@@ -10,8 +10,8 @@ module Mack
10
10
  class Inline < Mack::Rendering::Type::Base
11
11
 
12
12
  def render
13
- @engine = find_engine((self.options[:engine] || :erubis)).new(self.view_template)
14
- return @engine.render(self.render_value, self.binder)
13
+ @engine = find_engine((self._options[:engine] || :erubis)).new(self.view_template)
14
+ return @engine.render(self._render_value, self._binder)
15
15
  end
16
16
 
17
17
  # Passes concatenation messages through to the Mack::Rendering::Engine object.
@@ -12,7 +12,7 @@ module Mack
12
12
  # Example:
13
13
  # app/views/layouts/application.html.erb
14
14
  def render
15
- l_file = Mack::Paths.layouts("#{self.options[:layout]}.#{self.options[:format]}")
15
+ l_file = Mack::Paths.layouts("#{self._options[:layout]}.#{self._options[:format]}")
16
16
  begin
17
17
  render_file(l_file, :layout)
18
18
  rescue Mack::Errors::ResourceNotFound => e
@@ -15,7 +15,7 @@ module Mack
15
15
  # Example:
16
16
  # app/views/users/_form.html.erb
17
17
  def render
18
- partial = self.render_value.to_s
18
+ partial = self._render_value.to_s
19
19
  parts = partial.split("/")
20
20
  if parts.size == 1
21
21
  # it's local to this controller
@@ -26,7 +26,7 @@ module Mack
26
26
  parts[parts.size - 1] = "_" << parts.last
27
27
  partial = Mack::Paths.views(parts)
28
28
  end
29
- partial = "#{partial}.#{self.options[:format]}"
29
+ partial = "#{partial}.#{self._options[:format]}"
30
30
  render_file(partial, :partial)
31
31
  end
32
32
 
@@ -9,9 +9,9 @@ module Mack
9
9
  # Attempts to find the file on disk and return it. If no file extension is provided then the 'format'
10
10
  # of the request is appended to the file name.
11
11
  def render
12
- p_file = self.render_value
12
+ p_file = self._render_value
13
13
  if File.extname(p_file).blank?
14
- p_file = "#{p_file}.#{self.options[:format]}"
14
+ p_file = "#{p_file}.#{self._options[:format]}"
15
15
  end
16
16
  find_file(Mack::Paths.public(p_file)) do |f|
17
17
  return File.open(f).read
@@ -13,7 +13,7 @@ module Mack
13
13
  # Example:
14
14
  # <%= render(:template, "users/show") %> # => app/views/users/show.html.erb
15
15
  def render
16
- t_file = Mack::Paths.views("#{self.render_value}.#{self.options[:format]}")
16
+ t_file = Mack::Paths.views("#{self._render_value}.#{self._options[:format]}")
17
17
  render_file(t_file, :template)
18
18
  end
19
19
 
@@ -9,7 +9,7 @@ module Mack
9
9
  class Text < Mack::Rendering::Type::Base
10
10
 
11
11
  def render
12
- self.render_value
12
+ self._render_value
13
13
  end
14
14
 
15
15
  end # Text
@@ -32,8 +32,8 @@ module Mack
32
32
 
33
33
  # Retrieves the contents of the url using either GET or POST, passing along any specified parameters.
34
34
  def render
35
- options = {:method => :get, :raise_exception => false}.merge(self.options)
36
- url = self.render_value
35
+ options = {:method => :get, :raise_exception => false}.merge(self._options)
36
+ url = self._render_value
37
37
  remote = url.match(/^[a-zA-Z]+:\/\//)
38
38
  case options[:method]
39
39
  when :get
@@ -43,7 +43,7 @@ module Mack
43
43
  end
44
44
  else
45
45
  do_render_local_url(url, options) do |url, options|
46
- Rack::MockRequest.new(self.app_for_rendering).get(url, options)
46
+ Rack::MockRequest.new(self._app_for_rendering).get(url, options)
47
47
  end
48
48
  end
49
49
  when :post
@@ -53,7 +53,7 @@ module Mack
53
53
  end
54
54
  else
55
55
  do_render_local_url(url, options) do |url, options|
56
- Rack::MockRequest.new(self.app_for_rendering).post(url, options)
56
+ Rack::MockRequest.new(self._app_for_rendering).post(url, options)
57
57
  end
58
58
  end
59
59
  else
@@ -23,9 +23,9 @@ module Mack
23
23
 
24
24
  # See Mack::Rendering::Type::FileBase render_file for more information.
25
25
  def render
26
- self.options[:format] = "xml"
27
- self.controller.response["Content-Type"] = Mack::Utils::MimeTypes[self.options[:format]]
28
- x_file = File.join(self.controller_view_path, "#{self.render_value}.#{self.options[:format]}")
26
+ self._options[:format] = "xml"
27
+ self.controller.response["Content-Type"] = Mack::Utils::MimeTypes[self._options[:format]]
28
+ x_file = File.join(self.controller_view_path, "#{self._render_value}.#{self._options[:format]}")
29
29
  render_file(x_file, :xml)
30
30
  end
31
31
 
@@ -5,25 +5,25 @@ module Mack
5
5
  class ViewTemplate
6
6
 
7
7
  # Allows access to any options passed into the template.
8
- attr_accessor :options
9
- attr_accessor :render_type
10
- attr_accessor :render_value
8
+ attr_accessor :_options
9
+ attr_accessor :_render_type
10
+ attr_accessor :_render_value
11
11
 
12
12
  def initialize(render_type, render_value, options = {})
13
- self.render_type = render_type
14
- self.render_value = render_value
15
- self.options = options
13
+ self._render_type = render_type
14
+ self._render_value = render_value
15
+ self._options = options
16
16
  @_yield_to_cache = {}
17
17
  Thread.current[:view_template] = self
18
18
  # Define methods for :locals
19
- (self.options[:locals] || {}).each do |k,v|
19
+ (self._options[:locals] || {}).each do |k,v|
20
20
  define_instance_method(k) {v}
21
21
  end
22
22
  end
23
23
 
24
24
  # Allows access to the current Mack::Controller object.
25
25
  def controller
26
- self.options[:controller]
26
+ self._options[:controller]
27
27
  end
28
28
 
29
29
  # Returns the Mack::Request associated with the current Mack::Controller object.
@@ -57,8 +57,8 @@ module Mack
57
57
  # <%= render(:partial, :latest_news) %>
58
58
  # <%= render(:url, "http://www.mackframework.com") %>
59
59
  def render(render_type, render_value, options = {})
60
- options = self.options.merge({:layout => false}).merge(options)
61
- Mack::Rendering::ViewTemplate.new(render_type, render_value, options).compile_and_render
60
+ options = self._options.merge({:layout => false}).merge(options)
61
+ Mack::Rendering::ViewTemplate.new(render_type, render_value, options)._compile_and_render
62
62
  end
63
63
 
64
64
  # Returns a string stored using content_for.
@@ -93,18 +93,18 @@ module Mack
93
93
  # Transfers all the instance variables from the controller to the current instance of
94
94
  # the view template. This call is cached, so it only happens once, regardless of the number
95
95
  # of times it is called.
96
- def compile
97
- ivar_cache("compiled_template") do
98
- self.options.symbolize_keys!
99
- transfer_vars(self.controller)
96
+ def _compile
97
+ ivar_cache("_compiled_template") do
98
+ self._options.symbolize_keys!
99
+ _transfer_vars(self.controller)
100
100
  end
101
101
  end
102
102
 
103
- # Fully compiles and renders the view and, if applicable, it's layout.
104
- def compile_and_render
105
- self.compile
106
- content_for(:view, render_view)
107
- render_layout
103
+ # Fully _compiles and renders the view and, if applicable, it's layout.
104
+ def _compile_and_render
105
+ self._compile
106
+ content_for(:view, _render_view)
107
+ _render_layout
108
108
  end
109
109
 
110
110
  # Passes concatenation messages through to the Mack::Rendering::Type object.
@@ -117,7 +117,7 @@ module Mack
117
117
  # Primarily used by Mack::Rendering::Type::Url when dealing with 'local' urls.
118
118
  # This returns an instance of the current application to run additional requests
119
119
  # through.
120
- def app_for_rendering
120
+ def _app_for_rendering
121
121
  ivar_cache do
122
122
  Mack::Utils::Server.build_app
123
123
  end
@@ -125,25 +125,25 @@ module Mack
125
125
 
126
126
  # Returns the binding of the current view template to be used with
127
127
  # the engines to render.
128
- def binder
128
+ def _binder
129
129
  binding
130
130
  end
131
131
 
132
132
  private
133
133
 
134
- def render_layout
135
- if @_render_type.allow_layout? && self.options[:layout]
134
+ def _render_layout
135
+ if @_render_type.allow_layout? && self._options[:layout]
136
136
  return Mack::Rendering::Type::Layout.new(self).render
137
137
  end
138
138
  return yield_to(:view)
139
139
  end
140
140
 
141
- def render_view
142
- @_render_type = find_render_type(self.render_type).new(self)
141
+ def _render_view
142
+ @_render_type = _find_render_type(self._render_type).new(self)
143
143
  @_render_type.render
144
144
  end
145
145
 
146
- def find_file(*path)
146
+ def _find_file(*path)
147
147
  f = File.join(path)
148
148
  if File.exists?(f)
149
149
  yield f
@@ -151,13 +151,13 @@ module Mack
151
151
  end
152
152
 
153
153
  # Transfer instance variables from the controller to the view.
154
- def transfer_vars(x)
154
+ def _transfer_vars(x)
155
155
  x.instance_variables.each do |v|
156
156
  self.instance_variable_set(v, x.instance_variable_get(v))
157
157
  end
158
158
  end
159
159
 
160
- def find_render_type(e)
160
+ def _find_render_type(e)
161
161
  eval("Mack::Rendering::Type::#{e.to_s.camelcase}")
162
162
  end
163
163
 
data/lib/mack/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mack
2
- VERSION = '0.8.0' unless const_defined?("VERSION")
2
+ VERSION = '0.8.0.2' unless const_defined?("VERSION")
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - "="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.8.0
33
+ version: 0.8.0.2
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: configatron