html_namespacing 0.2.0 → 0.3.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.
@@ -10,7 +10,11 @@ module HtmlNamespacing
10
10
  module Rails
11
11
  def self.install(options = {})
12
12
  @options = options
13
- install_rails_2_3(options)
13
+ if ::Rails::VERSION::MAJOR == 3
14
+ install_rails_3(options)
15
+ else
16
+ install_rails_2_3(options)
17
+ end
14
18
  end
15
19
 
16
20
  # Called by ActionView
@@ -47,7 +51,7 @@ module HtmlNamespacing
47
51
  end
48
52
 
49
53
  def self.template_formats
50
- @formats ||= Set.new(@options[:template_formats] || ['html'])
54
+ @formats ||= Set.new((@options[:template_formats] || [:html]).collect(&:to_sym))
51
55
  end
52
56
 
53
57
  module Helpers
@@ -58,7 +62,8 @@ module HtmlNamespacing
58
62
  def html_namespacing_javascript_tag(framework, options = {})
59
63
  js = html_namespacing_javascript(framework, options)
60
64
  unless js.blank?
61
- "<script type=\"text/javascript\"><!--//--><![CDATA[//><!--\n#{js}//--><!]]></script>"
65
+ s = "<script type=\"text/javascript\"><!--//--><![CDATA[//><!--\n#{js}//--><!]]></script>"
66
+ s.respond_to?(:html_safe) && s.html_safe || s
62
67
  end
63
68
  end
64
69
 
@@ -90,7 +95,8 @@ module HtmlNamespacing
90
95
  css = html_namespacing_styles(options)
91
96
  unless css.blank?
92
97
  attribute_string = style_tag_attributes.map{|k,v| " #{k}=\"#{v}\""}.join
93
- "<style type=\"text/css\"#{attribute_string}>#{css}</style>"
98
+ s = "<style type=\"text/css\"#{attribute_string}>#{css}</style>"
99
+ s.respond_to?(:html_safe) && s.html_safe || s
94
100
  end
95
101
  end
96
102
 
@@ -150,7 +156,7 @@ module HtmlNamespacing
150
156
 
151
157
  private
152
158
 
153
- def self.install_rails_2_3(options = {})
159
+ def self.install_rails_all_versions(options)
154
160
  if options[:javascript]
155
161
  ::ActionView::Base.class_eval do
156
162
  attr_writer(:html_namespacing_rendered_paths)
@@ -161,12 +167,16 @@ module HtmlNamespacing
161
167
  end
162
168
 
163
169
  ::ActionView::Template.class_eval do
164
- def render_with_html_namespacing(view, local_assigns = {})
165
- html = render_without_html_namespacing(view, local_assigns)
170
+ def render_with_html_namespacing(*args, &block)
171
+ html = render_without_html_namespacing(*args, &block)
166
172
 
167
- view.html_namespacing_rendered_paths << path_without_format_and_extension if view.respond_to?(:html_namespacing_rendered_paths)
173
+ view = args.first
168
174
 
169
- if HtmlNamespacing::Plugin::Rails.template_formats.include?(format)
175
+ if view.respond_to?(:html_namespacing_rendered_paths)
176
+ view.html_namespacing_rendered_paths << html_namespacing_key
177
+ end
178
+
179
+ if HtmlNamespacing::Plugin::Rails.template_formats.include?(html_namespacing_format)
170
180
  add_namespace_to_html(html, view)
171
181
  else
172
182
  html
@@ -177,14 +187,49 @@ module HtmlNamespacing
177
187
  private
178
188
 
179
189
  def add_namespace_to_html(html, view)
180
- HtmlNamespacing::add_namespace_to_html(html, html_namespace)
181
- rescue ArgumentError => e
182
- HtmlNamespacing::Plugin::Rails.handle_exception(e, self, view)
183
- html # unless handle_exception() raised something
190
+ ret = begin
191
+ HtmlNamespacing::add_namespace_to_html(html, html_namespace)
192
+ rescue ArgumentError => e
193
+ HtmlNamespacing::Plugin::Rails.handle_exception(e, self, view)
194
+ html # unless handle_exception() raised something
195
+ end
196
+ ret.respond_to?(:html_safe) && ret.html_safe || ret
184
197
  end
185
198
 
186
199
  def html_namespace
187
- HtmlNamespacing::Plugin::Rails.path_to_namespace(path_without_format_and_extension)
200
+ HtmlNamespacing::Plugin::Rails.path_to_namespace(html_namespacing_key)
201
+ end
202
+ end
203
+ end
204
+
205
+ def self.install_rails_3(options = {})
206
+ self.install_rails_all_versions(options)
207
+
208
+ ::ActionView::Template.class_eval do
209
+ private
210
+
211
+ def html_namespacing_key
212
+ virtual_path
213
+ end
214
+
215
+ def html_namespacing_format
216
+ formats.first
217
+ end
218
+ end
219
+ end
220
+
221
+ def self.install_rails_2_3(options = {})
222
+ self.install_rails_all_versions(options)
223
+
224
+ ::ActionView::Template.class_eval do
225
+ private
226
+
227
+ def html_namespacing_key
228
+ path_without_format_and_extension
229
+ end
230
+
231
+ def html_namespacing_format
232
+ format.to_sym
188
233
  end
189
234
  end
190
235
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_namespacing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - adamh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-30 00:00:00 -05:00
12
+ date: 2010-04-08 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -70,5 +70,5 @@ signing_key:
70
70
  specification_version: 3
71
71
  summary: Automatic HTML namespacing
72
72
  test_files:
73
- - spec/c_extension_spec.rb
74
73
  - spec/spec_helper.rb
74
+ - spec/c_extension_spec.rb