renderit 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/README.rdoc +5 -1
  2. data/VERSION +1 -1
  3. data/lib/renderit.rb +96 -34
  4. data/renderit.gemspec +54 -0
  5. metadata +5 -4
data/README.rdoc CHANGED
@@ -20,6 +20,10 @@ will be used.
20
20
 
21
21
  In order to use those tempates, default view or layout have to be present. You will not be able to render 'application_new' layout in case you have no 'application' layout.
22
22
 
23
- Have fun :)
23
+ == Rails compatibility
24
+
25
+ In order to use this gem with rails 2.3.*, you just have to put 'config.gem "renderit"' string in config/environment.rb file.
26
+
27
+ In order to user this gem with rails 3, you have to require 'renderit' gem in Gemfile and create some file (I prefer renderit.rb) in config/initializers folder where 'RenderIt.load_config' line should be present.
24
28
 
25
29
  Copyright (c) 2010 Andrey Romanov. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/lib/renderit.rb CHANGED
@@ -1,36 +1,3 @@
1
- class ActionController::Base
2
- private
3
-
4
- # default_render method for ActionController::Base is redefined
5
- # in order to render views for specific browsers (depending on user_agent)
6
- def default_render
7
- @renderit_template ||= RenderIt.get_template_name(request)
8
- template_path = default_template_name + '_' + @renderit_template
9
- if view_paths.find_template(template_path, default_template_format)
10
- render template_path
11
- end
12
- rescue ActionView::MissingTemplate => e
13
- render default_template_name
14
- end
15
-
16
- # default_layout method for ActionController::Base is redefined
17
- # in order to render layouts for specific browsers (depending on user_agent)
18
- def default_layout
19
- @renderit_template = RenderIt.get_template_name(request)
20
- layout = self.class.read_inheritable_attribute(:layout)
21
- return layout unless self.class.read_inheritable_attribute(:auto_layout)
22
- begin
23
- rendered_layout = find_layout(layout+ '_' + @renderit_template, default_template_format)
24
- rescue ActionView::MissingTemplate
25
- end
26
- return rendered_layout if rendered_layout
27
- find_layout(layout, default_template_format)
28
- rescue ActionView::MissingTemplate
29
- nil
30
- end
31
-
32
- end
33
-
34
1
  class RenderIt
35
2
  # Default regular expressions to define browser and its version
36
3
  DEFAULT_BROWSERS_CONFIG = {
@@ -123,4 +90,99 @@ class RenderIt
123
90
 
124
91
  end
125
92
 
126
- RenderIt.load_config
93
+
94
+ RAILS_THREE_REGEXP = /^3/
95
+
96
+ if RAILS_THREE_REGEXP =~ Rails.version # If rails version is 3
97
+
98
+ module AbstractController
99
+ module Rendering
100
+
101
+ def _normalize_options(options)
102
+ if options[:partial] == true
103
+ options[:partial] = action_name
104
+ end
105
+ if (options.keys & [:partial, :file, :template]).empty?
106
+ options[:prefix] ||= _prefix
107
+ end
108
+
109
+ options[:template] ||= (options[:action] || action_name).to_s
110
+ if (@renderit_template ||= RenderIt.get_template_name(request))
111
+ begin
112
+ template_name = options[:template]+'_'+@renderit_template
113
+ if lookup_context.find_template(template_name, options[:prefix])
114
+ options[:template] = template_name
115
+ end
116
+ rescue ActionView::MissingTemplate => e
117
+ end
118
+ end
119
+ options
120
+ end
121
+
122
+ end
123
+
124
+ end
125
+
126
+ module AbstractController
127
+ module Layouts
128
+
129
+ def _normalize_options(options)
130
+ super
131
+ if _include_layout?(options)
132
+ layout = options.key?(:layout) ? options.delete(:layout) : :default
133
+ value = _layout_for_option(layout)
134
+ if (value && (@renderit_template ||= RenderIt.get_template_name(request)) )
135
+ begin
136
+ template_name = value+'_'+@renderit_template
137
+ if lookup_context.find_template(template_name, 'layouts')
138
+ value = template_name
139
+ end
140
+ rescue ActionView::MissingTemplate => e
141
+ end
142
+ end
143
+ options[:layout] = (value =~ /\blayouts/ ? value : "layouts/#{value}") if value
144
+ end
145
+ end
146
+
147
+ end
148
+ end
149
+
150
+
151
+ else # If rails version is 2.3.*
152
+
153
+ class ActionController::Base
154
+ private
155
+
156
+ # default_render method for ActionController::Base is redefined
157
+ # in order to render views for specific browsers (depending on user_agent)
158
+ def default_render
159
+ @renderit_template ||= RenderIt.get_template_name(request)
160
+ template_path = default_template_name + '_' + @renderit_template
161
+ if view_paths.find_template(template_path, default_template_format)
162
+ render template_path
163
+ end
164
+ rescue ActionView::MissingTemplate => e
165
+ render default_template_name
166
+ end
167
+
168
+ # default_layout method for ActionController::Base is redefined
169
+ # in order to render layouts for specific browsers (depending on user_agent)
170
+ def default_layout
171
+ @renderit_template = RenderIt.get_template_name(request)
172
+ layout = self.class.read_inheritable_attribute(:layout)
173
+ return layout unless self.class.read_inheritable_attribute(:auto_layout)
174
+ begin
175
+ rendered_layout = find_layout(layout+ '_' + @renderit_template, default_template_format)
176
+ rescue ActionView::MissingTemplate
177
+ end
178
+ return rendered_layout if rendered_layout
179
+ find_layout(layout, default_template_format)
180
+ rescue ActionView::MissingTemplate
181
+ nil
182
+ end
183
+
184
+ end
185
+
186
+ RenderIt.load_config
187
+
188
+ end
data/renderit.gemspec ADDED
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{renderit}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andrey Romanov"]
12
+ s.date = %q{2010-08-09}
13
+ s.description = %q{Renders different templates depending on browser user_agent.}
14
+ s.email = %q{judo.ras@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/renderit.rb",
27
+ "renderit.gemspec",
28
+ "test/helper.rb",
29
+ "test/test_renderit.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/romanoff/renderit}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.7}
35
+ s.summary = %q{Renders different templates depending on browser user_agent.}
36
+ s.test_files = [
37
+ "test/helper.rb",
38
+ "test/test_renderit.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
47
+ else
48
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
52
+ end
53
+ end
54
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renderit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrey Romanov
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-05 00:00:00 +03:00
18
+ date: 2010-08-09 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -49,6 +49,7 @@ files:
49
49
  - Rakefile
50
50
  - VERSION
51
51
  - lib/renderit.rb
52
+ - renderit.gemspec
52
53
  - test/helper.rb
53
54
  - test/test_renderit.rb
54
55
  has_rdoc: true