Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 89df60be5ed267cd571cda20ea3dd3efa57c6d99 @gazay committed
Showing with 120 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +4 −0 Gemfile
  3. +41 −0 README.md
  4. +4 −0 Rakefile
  5. +21 −0 gon.gemspec
  6. +18 −0 lib/gon.rb
  7. +24 −0 lib/gon/helpers.rb
  8. +3 −0 lib/gon/version.rb
5 .gitignore
@@ -0,0 +1,5 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
+
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in evil_vk_ads.gemspec
+gemspec
41 README.md
@@ -0,0 +1,41 @@
+# Gon gem — get your Rails variables in your js
+
+TODO: write description
+
+## Usage
+
+TODO: write usage
+
+## Installation
+
+Puts this line into `Gemfile` then run `$ bundle`:
+
+``` ruby
+gem 'gon', '0.1.0'
+```
+
+Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
+
+``` ruby
+config.gem 'gon', :version => '0.1.0'
+```
+
+Or manually install variants gem: `$ gem install gon`
+
+## Contributors
+
+* @gazay
+
+Special thanks to @brainopia and @kossnocorp.
+
+## License
+
+The MIT License
+
+Copyright (c) 2011 gazay
+
+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.
4 Rakefile
@@ -0,0 +1,4 @@
+require 'rubygems'
+require 'rake'
+require 'bundler'
+Bundler::GemHelper.install_tasks
21 gon.gemspec
@@ -0,0 +1,21 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "gon/version"
+
+Gem::Specification.new do |s|
+ s.name = "gon"
+ s.version = Gon::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ['gazay']
+ s.email = ['alex.gaziev@gmail.com']
+ s.homepage = ""
+ s.summary = %q{Get your Rails variables in your JS}
+ s.description = %q{If you need to send some data to your js files and you don't want to do this with long way trough views and parsing - use this force!}
+
+ # s.rubyforge_project = "gem"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end
18 lib/gon.rb
@@ -0,0 +1,18 @@
+require 'action_view'
+require 'gon/helpers'
+
+module Gon
+ def self.method_missing(m, *args, &block)
+ gon_variables(m.to_s, args[0])
+ end
+
+ def self.gon_variables(name=nil, value=nil)
+ data = Rails.cache.read('gon_variables') || {}
+
+ new_data = {}
+ new_data[name] = value if name && value
+
+ Rails.cache.delete('gon_variables')
+ Rails.cache.write('gon_variables', (new_data.merge data))
+ end
+end
24 lib/gon/helpers.rb
@@ -0,0 +1,24 @@
+module Gon
+ module Helpers
+ def self.included base
+ base.send(:include, InstanceMethods)
+ end
+
+ module InstanceMethods
+ def include_gon
+ javascript_include_tag 'http://gaziev.com/files/gon.js'
+ end
+
+ def gon_variables
+ data = Rails.cache.read('gon_variables') || {}
+
+ data.to_s.gsub('=>', ' : ')
+ end
+ end
+
+ end
+end
+
+module ActionView::Helpers
+ include Gon::Helpers
+end
3 lib/gon/version.rb
@@ -0,0 +1,3 @@
+module Gon
+ VERSION = '0.1.0'
+end

0 comments on commit 89df60b

Please sign in to comment.
Something went wrong with that request. Please try again.