Skip to content

Commit

Permalink
updated to work better in partials and files not rendered as full lay…
Browse files Browse the repository at this point in the history
…outs.
  • Loading branch information
ejschmitt committed Sep 12, 2009
1 parent cb20b87 commit 0d7de0f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/jsvars.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<
Expand Down Expand Up @@ -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.