Permalink
Browse files

Initial commit, needs documentation

  • Loading branch information...
0 parents commit ca227d126048fe262e5c94194cd846c124878d22 @ejschmitt committed Sep 7, 2009
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Erick Schmitt
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 README
@@ -0,0 +1,13 @@
+Jsvars
+======
+
+Introduction goes here.
+
+
+Example
+=======
+
+Example goes here.
+
+
+Copyright (c) 2009 [name of plugin creator], released under the MIT license
23 Rakefile
@@ -0,0 +1,23 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the jsvars plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the jsvars plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Jsvars'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
2 init.rb
@@ -0,0 +1,2 @@
+ActionController::Base.send :include, Jsvars
+ActionController::Base.send :after_filter, :include_jsvars
1 install.rb
@@ -0,0 +1 @@
+# Install hook code here
11 lib/.svn/all-wcprops
@@ -0,0 +1,11 @@
+K 25
+svn:wc:ra_dav:version-url
+V 90
+/!svn/ver/3551/repo/projects/product/brandconnect/trunk/railsapp/vendor/plugins/jsvars/lib
+END
+jsvars.rb
+K 25
+svn:wc:ra_dav:version-url
+V 100
+/!svn/ver/3551/repo/projects/product/brandconnect/trunk/railsapp/vendor/plugins/jsvars/lib/jsvars.rb
+END
69 lib/.svn/entries
@@ -0,0 +1,69 @@
+9
+
+dir
+3574
+http://svn.eng.vitrue.com/repo/projects/product/brandconnect/trunk/railsapp/vendor/plugins/jsvars/lib
+http://svn.eng.vitrue.com
+
+
+
+2009-09-03T16:04:46.434318Z
+3551
+erick
+
+
+svn:special svn:externals svn:needs-lock
+
+
+
+
+
+
+
+
+
+
+
+ed038e9a-8caf-e94d-a586-6c6eaae76fb0
+
+
+
+
+
+
+0
+
+jsvars.rb
+file
+
+
+
+
+2009-09-02T21:54:08.000000Z
+b15d49fd6346804cc3a405f0a143e4da
+2009-09-03T16:04:46.434318Z
+3551
+erick
+has-props
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+2090
+
1 lib/.svn/format
@@ -0,0 +1 @@
+9
5 lib/.svn/prop-base/jsvars.rb.svn-base
@@ -0,0 +1,5 @@
+K 13
+svn:eol-style
+V 6
+native
+END
62 lib/.svn/text-base/jsvars.rb.svn-base
@@ -0,0 +1,62 @@
+require 'json'
+
+module Jsvars
+ def self.included(base)
+ base.send(:include, InstanceMethods)
+ end
+
+ module InstanceMethods
+ def jsvars
+ @jsvars = @jsvars || Hash.new
+ end
+
+ def include_jsvars
+ jsvars = @jsvars
+ name = 'jsvars'
+ return unless jsvars
+ close_tag_index = response.body.index /<\/body>/i
+ js_assignments = []
+ jsvars.each do |variable, value|
+ js_assignments <<
+ "
+ if (typeof(#{ variable }) === 'object') {
+ jsvars.objectExtend(#{ variable }, #{ value.to_json });
+ }
+ else {
+ var #{ variable } = #{ value.to_json };
+ }
+ "
+ end
+
+ added_HTML =
+ # this really should be in its own .js file... but its so simple it almost seems pointless
+ "
+ <!-- added by the #{ name } plugin -->
+ <script>
+ var jsvars;
+ (function () {
+ jsvars = {
+ objectExtend: function (mainObject) {
+ var i;
+ for (i = 1; i < arguments.length; i += 1) {
+ for (prop in arguments[i]){
+ if (arguments[i].hasOwnProperty(prop)) {
+ mainObject[prop] = arguments[i][prop];
+ }
+ }
+ }
+ return mainObject;
+ } //end func
+ }
+ }());
+
+ #{ js_assignments.join }
+
+ </script>
+ <!-- end #{ name } plugin code -->
+ ".gsub(/\t/, " ").squeeze(' ')
+
+ response.body.insert close_tag_index, added_HTML if close_tag_index
+ end
+ end
+end
53 lib/jsvars.rb
@@ -0,0 +1,53 @@
+require 'json'
+
+module Jsvars
+ def self.included(base)
+ base.send(:include, InstanceMethods)
+ end
+
+ module InstanceMethods
+ def jsvars
+ @jsvars = @jsvars || Hash.new
+ end
+
+ def include_jsvars
+ jsvars = @jsvars
+ name = 'jsvars'
+ return unless jsvars
+ close_tag_index = response.body.index /<\/body>/i
+ js_assignments = []
+ jsvars.each do |variable, value|
+ js_assignments <<
+"if (typeof(#{ variable }) === 'object') {jsvars.objExtend(#{ variable }, #{ value.to_json });}
+else {var #{ variable } = #{ value.to_json }};"
+ end
+
+ methods =
+ '
+ var jsvars = {
+ objExtend: function (mainObject) {
+ for (var i = 1; i < arguments.length; i += 1) {
+ for (prop in arguments[i]){
+ if (arguments[i].hasOwnProperty(prop)) {
+ mainObject[prop] = arguments[i][prop];
+ }
+ }
+ }
+ return mainObject;
+ }
+ }
+ '
+ methods = methods.gsub(/\n|\r|\t/, ' ').squeeze(' ')
+
+ added_HTML =
+"<!-- 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
+ end
+ end
+end
11 tasks/.svn/all-wcprops
@@ -0,0 +1,11 @@
+K 25
+svn:wc:ra_dav:version-url
+V 92
+/!svn/ver/3469/repo/projects/product/brandconnect/trunk/railsapp/vendor/plugins/jsvars/tasks
+END
+jsvars_tasks.rake
+K 25
+svn:wc:ra_dav:version-url
+V 110
+/!svn/ver/3469/repo/projects/product/brandconnect/trunk/railsapp/vendor/plugins/jsvars/tasks/jsvars_tasks.rake
+END
69 tasks/.svn/entries
@@ -0,0 +1,69 @@
+9
+
+dir
+3574
+http://svn.eng.vitrue.com/repo/projects/product/brandconnect/trunk/railsapp/vendor/plugins/jsvars/tasks
+http://svn.eng.vitrue.com
+
+
+
+2009-08-31T21:14:57.880456Z
+3469
+erick
+
+
+svn:special svn:externals svn:needs-lock
+
+
+
+
+
+
+
+
+
+
+
+ed038e9a-8caf-e94d-a586-6c6eaae76fb0
+
+
+
+
+
+
+0
+
+jsvars_tasks.rake
+file
+
+
+
+
+2009-08-31T19:14:03.000000Z
+dd1072ac6bd44739fb121b1ae3cd2bad
+2009-08-31T21:14:57.880456Z
+3469
+erick
+has-props
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+84
+
1 tasks/.svn/format
@@ -0,0 +1 @@
+9
5 tasks/.svn/prop-base/jsvars_tasks.rake.svn-base
@@ -0,0 +1,5 @@
+K 13
+svn:eol-style
+V 6
+native
+END
4 tasks/.svn/text-base/jsvars_tasks.rake.svn-base
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :jsvars do
+# # Task goes here
+# end
4 tasks/jsvars_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :jsvars do
+# # Task goes here
+# end
17 test/.svn/all-wcprops
@@ -0,0 +1,17 @@
+K 25
+svn:wc:ra_dav:version-url
+V 91
+/!svn/ver/3469/repo/projects/product/brandconnect/trunk/railsapp/vendor/plugins/jsvars/test
+END
+jsvars_test.rb
+K 25
+svn:wc:ra_dav:version-url
+V 106
+/!svn/ver/3469/repo/projects/product/brandconnect/trunk/railsapp/vendor/plugins/jsvars/test/jsvars_test.rb
+END
+test_helper.rb
+K 25
+svn:wc:ra_dav:version-url
+V 106
+/!svn/ver/3469/repo/projects/product/brandconnect/trunk/railsapp/vendor/plugins/jsvars/test/test_helper.rb
+END
103 test/.svn/entries
@@ -0,0 +1,103 @@
+9
+
+dir
+3574
+http://svn.eng.vitrue.com/repo/projects/product/brandconnect/trunk/railsapp/vendor/plugins/jsvars/test
+http://svn.eng.vitrue.com
+
+
+
+2009-08-31T21:14:57.880456Z
+3469
+erick
+
+
+svn:special svn:externals svn:needs-lock
+
+
+
+
+
+
+
+
+
+
+
+ed038e9a-8caf-e94d-a586-6c6eaae76fb0
+
+
+
+
+
+
+0
+
+jsvars_test.rb
+file
+
+
+
+
+2009-08-31T19:14:03.000000Z
+2ea4def785db2132c625a5453bb40d96
+2009-08-31T21:14:57.880456Z
+3469
+erick
+has-props
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+153
+
+test_helper.rb
+file
+
+
+
+
+2009-08-31T19:14:03.000000Z
+0f57f5fd3650bdad64fa70be9fd4f761
+2009-08-31T21:14:57.880456Z
+3469
+erick
+has-props
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+78
+
1 test/.svn/format
@@ -0,0 +1 @@
+9
5 test/.svn/prop-base/jsvars_test.rb.svn-base
@@ -0,0 +1,5 @@
+K 13
+svn:eol-style
+V 6
+native
+END
5 test/.svn/prop-base/test_helper.rb.svn-base
@@ -0,0 +1,5 @@
+K 13
+svn:eol-style
+V 6
+native
+END
8 test/.svn/text-base/jsvars_test.rb.svn-base
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class JsvarsTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
3 test/.svn/text-base/test_helper.rb.svn-base
@@ -0,0 +1,3 @@
+require 'rubygems'
+require 'active_support'
+require 'active_support/test_case'
8 test/jsvars_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class JsvarsTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
3 test/test_helper.rb
@@ -0,0 +1,3 @@
+require 'rubygems'
+require 'active_support'
+require 'active_support/test_case'
1 uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here

0 comments on commit ca227d1

Please sign in to comment.