link_to_ujs 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MTljYjE3ODcyODIxZjMyMzE1YmE2M2RiZmNkNGQzZDVmMTg2OTU2Yw==
5
+ data.tar.gz: !binary |-
6
+ YWJmNzM2MmJhYjE4NGYwNTZhZGRhNDJiOGE3NjU1ZTJiZWNkZDM3Zg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YTZlOGExMWNhYzI2MzQwMjZhOGIwNWYzNzQ3NzgwYWE5ZjU3YzlkN2FlOWJm
10
+ NGFkMGViM2Q4NDAzMGU1YzY5MDE2ZGI2MGEyZjNlODU3MzRhMjEwMWVhMDlj
11
+ NGQxMDc3OTFiOTE2ODE2ZGJkYWViMTEzOTY4YzNhY2Q3ZDA0MDU=
12
+ data.tar.gz: !binary |-
13
+ OTAzZGZlY2QxMTRhNmIyNDFmNTdkZDhkY2RkY2YzMGY2NjA4OWVjMmU0OGY0
14
+ NDc4NTlhYzA5ZTQxNGI1MjViN2IxM2EyMzg1OGFmZDRlM2M3ZjIwMDhhMDMy
15
+ ZDEwYzRkODkwODA5NzMyNWE5NWM0YjVkODZlOTg4NmJmZDE3NjY=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in link_to_ujs.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 gagoar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # LinkToUjs
2
+
3
+ link_to_function it's dead
4
+
5
+ long life to link_to_ujs
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'link_to_ujs'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install link_to_ujs
20
+
21
+ ## Usage
22
+
23
+ just replace your's link_to_function with link_to_ujs. that's it.
24
+
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,33 @@
1
+ (function ($, undefined) {
2
+ /**
3
+ * link_to_ujs
4
+ * https://github.com/gagoar/link_to_ujs
5
+ **/
6
+ 'use strict';
7
+
8
+ var LinkToUjs;
9
+ $.LinkToUjs = LinkToUjs = {
10
+ selector: 'a[data-ujs][data-ref]'
11
+ , codeStorage: {}
12
+ , onClick: function(e){
13
+ e.preventDefault()
14
+ var $el = $(this)
15
+ , ref = $el.data('ref')
16
+ , code = $.LinkToUjs.codeStorage[ref]
17
+
18
+ console.log(e, code)
19
+ if(ref){
20
+ if( typeof $.LinkToUjs.codeStorage[ref] == 'function' )
21
+ $.LinkToUjs.codeStorage[ref] = new Function(e,code)
22
+
23
+ $.LinkToUjs.codeStorage[ref](e)
24
+ }
25
+ }
26
+ , bind: function(){
27
+ $(document).on('click', this.selector, this.onClick);
28
+ }
29
+ }
30
+ $(function () {
31
+ $.LinkToUjs.bind();
32
+ });
33
+ })(jQuery);
@@ -0,0 +1,13 @@
1
+ require 'link_to_ujs/version'
2
+ require 'active_support'
3
+
4
+ module LinkToUjs
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ ActiveSupport.on_load(:action_view) do
8
+ require 'link_to_ujs/action_view/helpers/javascript_helper'
9
+ include LinkToUjs::ActionView::Helpers::JavaScriptHelper
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,43 @@
1
+ module LinkToUjs
2
+ module ActionView
3
+ module Helpers
4
+ module JavaScriptHelper
5
+ # Returns a link whose +onclick+ handler triggers the passed JavaScript.
6
+ #
7
+ # The helper receives a name, JavaScript code, and an optional hash of HTML options. The
8
+ # name is used as the link text and the JavaScript code goes into the +onclick+ attribute.
9
+ # If +html_options+ has an <tt>:onclick</tt>, that one is put before +function+. Once all
10
+ # the JavaScript is set, the helper appends "; return false;".
11
+ #
12
+ # The +href+ attribute of the tag is set to "#" unless +html_options+ has one.
13
+ #
14
+ # link_to_function "Greeting", "alert('Hello world!')", :class => "nav_link"
15
+ # # => <a class="nav_link" href="#" onclick="alert('Hello world!'); return false;">Greeting</a>
16
+ #
17
+ def link_to_ujs(name, function, html_options={})
18
+ href = html_options[:href] || '#'
19
+ content_tag(:a, name, html_options.merge(href: href, data: {ujs: true, ref:ujs_converter(function)}))
20
+ end
21
+
22
+ def ujs_converter(code)
23
+ ref = SecureRandom.hex(5)
24
+ set_ujs(ref, code)
25
+ ref
26
+ end
27
+
28
+ def set_ujs(ref, code)
29
+ @ujs ||= {}
30
+ @ujs[ref] = Rails.production? ? Uglifier.compile(code) : code
31
+ end
32
+
33
+ def ujs_content
34
+ content_for :ujs do
35
+ javascript_tag "$.LinkToUjs.codeStorage = #{@ujs.to_json}"
36
+ end
37
+ content_for(:ujs)
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module LinkToUjs
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'link_to_ujs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'link_to_ujs'
8
+ spec.version = LinkToUjs::VERSION
9
+ spec.authors = ['gagoar']
10
+ spec.email = ['xeroice@gmail.com']
11
+ spec.description = %q{link_to_function with ujs magic}
12
+ spec.summary = %q{link_to_function its the past , long live to link_to_ujs}
13
+ spec.homepage = ""
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: link_to_ujs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - gagoar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: link_to_function with ujs magic
42
+ email:
43
+ - xeroice@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/assets/javascripts/linkToUjs.js
54
+ - lib/link_to_ujs.rb
55
+ - lib/link_to_ujs/action_view/helpers/javascript_helper.rb
56
+ - lib/link_to_ujs/version.rb
57
+ - link_to_ujs.gemspec
58
+ homepage: ''
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.0.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: link_to_function its the past , long live to link_to_ujs
82
+ test_files: []