Skip to content

Commit 89df60b

Browse files
committed
Initial commit
0 parents  commit 89df60b

File tree

8 files changed

+120
-0
lines changed

8 files changed

+120
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.gem
2+
.bundle
3+
Gemfile.lock
4+
pkg/*
5+

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source "http://rubygems.org"
2+
3+
# Specify your gem's dependencies in evil_vk_ads.gemspec
4+
gemspec

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Gon gem — get your Rails variables in your js
2+
3+
TODO: write description
4+
5+
## Usage
6+
7+
TODO: write usage
8+
9+
## Installation
10+
11+
Puts this line into `Gemfile` then run `$ bundle`:
12+
13+
``` ruby
14+
gem 'gon', '0.1.0'
15+
```
16+
17+
Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
18+
19+
``` ruby
20+
config.gem 'gon', :version => '0.1.0'
21+
```
22+
23+
Or manually install variants gem: `$ gem install gon`
24+
25+
## Contributors
26+
27+
* @gazay
28+
29+
Special thanks to @brainopia and @kossnocorp.
30+
31+
## License
32+
33+
The MIT License
34+
35+
Copyright (c) 2011 gazay
36+
37+
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:
38+
39+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
40+
41+
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.

Rakefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require 'rubygems'
2+
require 'rake'
3+
require 'bundler'
4+
Bundler::GemHelper.install_tasks

gon.gemspec

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- encoding: utf-8 -*-
2+
$:.push File.expand_path("../lib", __FILE__)
3+
require "gon/version"
4+
5+
Gem::Specification.new do |s|
6+
s.name = "gon"
7+
s.version = Gon::VERSION
8+
s.platform = Gem::Platform::RUBY
9+
s.authors = ['gazay']
10+
s.email = ['[email protected]']
11+
s.homepage = ""
12+
s.summary = %q{Get your Rails variables in your JS}
13+
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!}
14+
15+
# s.rubyforge_project = "gem"
16+
17+
s.files = `git ls-files`.split("\n")
18+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20+
s.require_paths = ["lib"]
21+
end

lib/gon.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require 'action_view'
2+
require 'gon/helpers'
3+
4+
module Gon
5+
def self.method_missing(m, *args, &block)
6+
gon_variables(m.to_s, args[0])
7+
end
8+
9+
def self.gon_variables(name=nil, value=nil)
10+
data = Rails.cache.read('gon_variables') || {}
11+
12+
new_data = {}
13+
new_data[name] = value if name && value
14+
15+
Rails.cache.delete('gon_variables')
16+
Rails.cache.write('gon_variables', (new_data.merge data))
17+
end
18+
end

lib/gon/helpers.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Gon
2+
module Helpers
3+
def self.included base
4+
base.send(:include, InstanceMethods)
5+
end
6+
7+
module InstanceMethods
8+
def include_gon
9+
javascript_include_tag 'http://gaziev.com/files/gon.js'
10+
end
11+
12+
def gon_variables
13+
data = Rails.cache.read('gon_variables') || {}
14+
15+
data.to_s.gsub('=>', ' : ')
16+
end
17+
end
18+
19+
end
20+
end
21+
22+
module ActionView::Helpers
23+
include Gon::Helpers
24+
end

lib/gon/version.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Gon
2+
VERSION = '0.1.0'
3+
end

0 commit comments

Comments
 (0)