Permalink
Browse files

updated to work better in partials and files not rendered as full lay…

…outs.
  • Loading branch information...
1 parent cb20b87 commit 0d7de0f19edb6bd8aa8a6c346625fe8cc9c47eca @ejschmitt committed Sep 12, 2009
Showing with 7 additions and 5 deletions.
  1. +7 −5 lib/jsvars.rb
View
@@ -13,8 +13,7 @@ def jsvars
def include_jsvars
jsvars = @jsvars
name = 'jsvars'
- return unless jsvars
- close_tag_index = response.body.index /<\/body>/i
+ return unless jsvars && response && response.content_type && response.content_type[/html|fbml/i]
js_assignments = []
jsvars.each do |variable, value|
js_assignments <<
@@ -61,15 +60,18 @@ def include_jsvars
'
methods = methods.gsub(/\n|\r|\t/, ' ').squeeze(' ')
- added_HTML =
+ added_script =
"<!-- added by the #{ name } plugin -->
<script type='text/javascript'>
#{ methods }
#{ js_assignments.join }
</script>
<!-- end #{ name } plugin code -->"
-
- response.body.insert close_tag_index, added_HTML if close_tag_index
+ index = response.body.index(/<\/body>/i) || -1
+ response.body.insert index, added_script
end
end
end
+
+
+

0 comments on commit 0d7de0f

Please sign in to comment.