chaves-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3@chaves-rails
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in chaves-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ Copyright © 2012 Phil Cohen <github@phlippers.net>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the “Software”), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # chaves-rails
2
+
3
+ [Chaves.js](https://github.com/jayroh/chaves.js), bundled for Rails 3.0 and up.
4
+
5
+
6
+ ## Rails 3.1+
7
+
8
+ For Rails 3.1 and greater, the files will be added to the asset pipeline and available for you to use.
9
+
10
+ To enable:
11
+
12
+ * Add the following line to the file `app/assets/javascripts/application.js` (or other [sprockets](https://github.com/sstephenson/sprockets) manifest):
13
+
14
+ ``` javascript
15
+ //= require jquery.chaves
16
+ ```
17
+
18
+
19
+ ### Installation
20
+
21
+ * Add `chaves-rails` to your Gemfile
22
+ * Run `bundle`
23
+
24
+ Enjoy!
25
+
26
+
27
+ ## Rails 3.0
28
+
29
+ This gem adds a single generator to Rails 3, `chaves:install`. Running the generator will install the JavaScript file necessary to use Chaves.
30
+
31
+ ### Installation
32
+
33
+ * Add `chaves-rails` to your Gemfile
34
+ * Run `bundle`
35
+ * Invoke the generator: `rails generate chaves:install`
36
+ * Add the following to your layout or view files:
37
+
38
+ ```erb
39
+ <%= javascript_include_tag "jquery.chaves" %>
40
+ ```
41
+
42
+ You're done!
43
+
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
52
+
53
+
54
+ ## License
55
+
56
+ **chaves-rails**
57
+
58
+ * Freely distributable and licensed under the [MIT license](http://phlipper.mit-license.org/2012/license.html).
59
+ * Copyright (c) 2012 Phil Cohen (github@phlippers.net) [![endorse](http://api.coderwall.com/phlipper/endorsecount.png)](http://coderwall.com/phlipper)
60
+ * http://phlippers.net/
61
+
62
+ **Chaves.js**
63
+
64
+ * Dual licensed under the MIT and GPL licenses.
65
+ * Copyright (c) 2012 Joel Oliveira
66
+ * https://github.com/jayroh/chaves.js
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/chaves/rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Phil Cohen"]
6
+ gem.email = ["github@phlippers.net"]
7
+ gem.description = %q{chaves.js, bundled for Rails 3.0 and up.}
8
+ gem.summary = %q{chaves.js, bundled for Rails 3.0 and up.}
9
+ gem.homepage = "https://github.com/phlipper/chaves-rails"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "chaves-rails"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Chaves::Rails::VERSION
17
+
18
+ gem.add_dependency "railties", ">= 3.0.0"
19
+ gem.add_development_dependency "bundler", ">= 1.1.0"
20
+ gem.add_development_dependency "rake", "~> 0.9.2.2"
21
+ end
@@ -0,0 +1 @@
1
+ require "chaves/rails"
@@ -0,0 +1,6 @@
1
+ module Chaves
2
+ module Rails
3
+ require "chaves/rails/engine"
4
+ require "chaves/rails/version"
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ # Configure Rails 3.1 to have assets in the load path
2
+ module Chaves
3
+ module Rails
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module Chaves
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ CHAVESJS_VERSION = "0.1.0"
5
+ end
6
+ end
@@ -0,0 +1,35 @@
1
+ require "rails"
2
+
3
+ # Supply generator for Rails 3.0.x or if asset pipeline is not enabled
4
+ if ::Rails.version < "3.1" || !::Rails.application.config.assets.enabled
5
+ module Chaves
6
+ module Generators
7
+ class InstallGenerator < ::Rails::Generators::Base
8
+ desc "This generator installs jquery.chaves #{Chaves::Rails::CHAVESJS_VERSION}"
9
+ source_root File.expand_path("../../../../../vendor/assets", __FILE__)
10
+
11
+ def copy_javascript
12
+ say_status("copying", "jquery.chaves.js", :green)
13
+ copy_file "javascripts/jquery.chaves.js", "public/javascripts/jquery.chaves.js"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ else
19
+ module Chaves
20
+ module Generators
21
+ class InstallGenerator < ::Rails::Generators::Base
22
+ desc "Just show instructions so people will know what to do when mistakenly using generator for Rails 3.1 apps"
23
+
24
+ def do_nothing
25
+ say_status("deprecated", "You are using Rails 3.1 with the asset pipeline enabled, so this generator is not needed.")
26
+ say_status("", "The necessary files are already in your asset pipeline.")
27
+ say_status("", "Just add `//= require jquery.chaves` to your app/assets/javascripts/application.js")
28
+ say_status("", "If you upgraded your app from Rails 3.0 and still have jquery.chaves.js in your public assets folders, be sure to remove them.")
29
+ say_status("", "If you do not want the asset pipeline enabled, you may turn it off in application.rb and re-run this generator.")
30
+ # ok, nothing
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,132 @@
1
+ // Generated by CoffeeScript 1.3.3
2
+ (function() {
3
+
4
+ $.fn.extend({
5
+ chaves: function(options) {
6
+ var self;
7
+ self = $.fn.chaves;
8
+ options = $.extend({}, self.default_options, options);
9
+ return $(this).each(function(i, el) {
10
+ return self.init(el, options);
11
+ });
12
+ }
13
+ });
14
+
15
+ $.extend($.fn.chaves, {
16
+ version: '0.1.0',
17
+ default_options: {
18
+ activeClass: 'active',
19
+ bindings: [],
20
+ childSelector: '> *',
21
+ className: 'jquery-chaves',
22
+ enableUpDown: false,
23
+ helpModalClass: 'jquery-chaves-help',
24
+ linkSelector: 'a:first',
25
+ scope: 'all',
26
+ searchSelector: '.search,\
27
+ #search,\
28
+ input[type="text"][value*="earch"],\
29
+ input[type="text"][placeholder*="earch"]'
30
+ },
31
+ init: function(el, options) {
32
+ var addToHelp, clickActive, downkeys, goDown, goUp, hideHelp, register_all_bindings, searchFocus, showHelp, upkeys,
33
+ _this = this;
34
+ this.options = options;
35
+ this.bindings = $.extend([], options.bindings);
36
+ this.el = $(el).addClass(options.className);
37
+ this.children = this.el.find(options.childSelector);
38
+ this.active = this.children.first().addClass(options.activeClass);
39
+ this.help = this.findOrCreateHelp();
40
+ downkeys = 'j';
41
+ upkeys = 'k';
42
+ if (options.enableUpDown) {
43
+ downkeys += ", down";
44
+ upkeys += ", up";
45
+ }
46
+ register_all_bindings = function() {
47
+ var binding, _i, _len, _ref, _results;
48
+ _ref = _this.bindings;
49
+ _results = [];
50
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
51
+ binding = _ref[_i];
52
+ key(binding[0], _this.options.scope, binding[2]);
53
+ _results.push(addToHelp(binding[0], binding[1]));
54
+ }
55
+ return _results;
56
+ };
57
+ addToHelp = function(keys, description) {
58
+ return _this.help.find('dl').append("<dt>" + keys + "</dt><dd>" + description + "</dd>");
59
+ };
60
+ goUp = function() {
61
+ var prev;
62
+ if ((_this.active.prev().length)) {
63
+ prev = _this.active.prev().addClass(_this.options.activeClass);
64
+ _this.active.removeClass(_this.options.activeClass);
65
+ _this.active = prev;
66
+ return _this.readjust(150);
67
+ }
68
+ };
69
+ goDown = function() {
70
+ var next;
71
+ if ((_this.active.next().length)) {
72
+ next = _this.active.next().addClass(_this.options.activeClass);
73
+ _this.active.removeClass(_this.options.activeClass);
74
+ _this.active = next;
75
+ return _this.readjust(0);
76
+ }
77
+ };
78
+ showHelp = function() {
79
+ return _this.help.toggleClass('visible');
80
+ };
81
+ hideHelp = function() {
82
+ return _this.help.removeClass('visible');
83
+ };
84
+ searchFocus = function() {
85
+ _this.search = $(_this.options.searchSelector);
86
+ return window.setTimeout((function() {
87
+ return _this.search.focus();
88
+ }), 10);
89
+ };
90
+ clickActive = function() {
91
+ var link;
92
+ link = _this.active.find(_this.options.linkSelector);
93
+ if (link.trigger('click').attr('target') === '_blank') {
94
+ return window.open(link.attr('href'), 'popped');
95
+ } else {
96
+ return window.location.href = link.attr('href');
97
+ }
98
+ };
99
+ this.bindings.push([upkeys, 'Move selection up.', goUp]);
100
+ this.bindings.push([downkeys, 'Move selection down.', goDown]);
101
+ this.bindings.push(['shift+/', 'Toggle help dialog.', showHelp]);
102
+ this.bindings.push(['esc, escape', 'Close help dialog.', hideHelp]);
103
+ this.bindings.push(['/', 'Focus on search.', searchFocus]);
104
+ this.bindings.push(['enter', 'Open/click element.', clickActive]);
105
+ return register_all_bindings();
106
+ },
107
+ readjust: function(buffer) {
108
+ var top;
109
+ if (this.elementOutOfViewport(this.active[0])) {
110
+ top = this.active.offset().top - buffer;
111
+ return $(window).scrollTop(top).trigger('scroll');
112
+ }
113
+ },
114
+ elementOutOfViewport: function(el) {
115
+ var rect;
116
+ if (el) {
117
+ rect = el.getBoundingClientRect();
118
+ return !(rect.top >= 0 && rect.left >= 0 && rect.bottom <= window.innerHeight && rect.right <= window.innerWidth);
119
+ }
120
+ },
121
+ findOrCreateHelp: function() {
122
+ var help, helpSelector;
123
+ helpSelector = "." + this.options.helpModalClass;
124
+ if (!$(helpSelector).length) {
125
+ $('body').append("<div class=" + this.options.helpModalClass + "></div>");
126
+ help = $(helpSelector).append('<h3>Keyboard Shortcuts</h3><dl></dl>');
127
+ }
128
+ return $(helpSelector);
129
+ }
130
+ });
131
+
132
+ }).call(this);
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chaves-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Phil Cohen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.1.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.2.2
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2.2
62
+ description: chaves.js, bundled for Rails 3.0 and up.
63
+ email:
64
+ - github@phlippers.net
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .ruby-version
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - chaves-rails.gemspec
76
+ - lib/chaves-rails.rb
77
+ - lib/chaves/rails.rb
78
+ - lib/chaves/rails/engine.rb
79
+ - lib/chaves/rails/version.rb
80
+ - lib/generators/chaves/install/install_generator.rb
81
+ - vendor/assets/javascripts/jquery.chaves.js
82
+ homepage: https://github.com/phlipper/chaves-rails
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
95
+ - 0
96
+ hash: -3417646482602324312
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
104
+ - 0
105
+ hash: -3417646482602324312
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.8.24
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: chaves.js, bundled for Rails 3.0 and up.
112
+ test_files: []