embootstrap-rails 0.0.2

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.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ embootstrap-rails
2
+ =================
3
+
4
+ An Ember based port of the Bootstrap plugins for integration into Rails.
5
+
6
+ Take advantage of the assets pipeline to include just the needed plugins, implemented in an Ember way and customizable.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'EmbootstrapRails'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1 @@
1
+ EmBootstrap = Ember.Namespace.create();
@@ -0,0 +1,180 @@
1
+ //= require ./embootstrap
2
+
3
+ EmBootstrap.Typeahead = Ember.TextField.extend({
4
+ valueBinding: 'filter',
5
+
6
+ matchingsUrl: null,
7
+
8
+ filter: '',
9
+ matchings: [],
10
+ highlightedMatching: null,
11
+
12
+ didInsertElement: function () {
13
+ var dropdown = this.get('matchingsView').create({
14
+ typeahead: this
15
+ });
16
+ dropdown.append($('.ember-application'));
17
+
18
+ this.set('dropdown', dropdown);
19
+ this.$().focus();
20
+ },
21
+
22
+ willDestroyElement: function () {
23
+ this.get('dropdown').remove();
24
+ },
25
+
26
+ matchingsView: Ember.CollectionView.extend({
27
+ tagName: 'ul',
28
+ classNames: 'typeahead dropdown-menu'.w(),
29
+ classNameBindings: 'content.length:show:hide',
30
+
31
+ contentBinding: 'typeahead.matchings',
32
+
33
+ didInsertElement: function () {
34
+ var
35
+ el = this.$(),
36
+ parent = this.get('typeahead').$(),
37
+ parentOffset = parent.offset();
38
+
39
+ el.css({
40
+ position: 'fixed',
41
+ top: parentOffset.top + parent.outerHeight(),
42
+ left: parentOffset.left
43
+ });
44
+ }.observes('content.length'),
45
+
46
+ itemViewClass: Ember.View.extend({
47
+ tagName: 'li',
48
+ classNameBindings: 'highlighted:active',
49
+ template: Ember.Handlebars.compile('<a {{action selectMatching view.content target="view.parentView.typeahead"}}>{{view.content.name}}</a>'),
50
+
51
+ highlightedMatchingBinding: 'parentView.typeahead.highlightedMatching',
52
+
53
+ highlighted: function () {
54
+ return this.get('content') === this.get('highlightedMatching');
55
+ }.property('highlightedMatching')
56
+ })
57
+ }),
58
+
59
+ matchingsChanged: function () {
60
+ var
61
+ matchings = this.get('matchings'),
62
+ highlightedMatching = this.get('highlightedMatching');
63
+
64
+ if (!Ember.empty(matchings)) {
65
+ if (!(highlightedMatching && matchings.contains(highlightedMatching))) {
66
+ this.set('highlightedMatching', matchings[0]);
67
+ }
68
+ }
69
+ }.observes('matchings.@each'),
70
+
71
+ keyUp: function (event) {
72
+ switch (event.keyCode) {
73
+ case 9: // tab
74
+ case 13: // enter
75
+ case 27: // escape
76
+ event.preventDefault();
77
+ break;
78
+ case 38: // up
79
+ event.preventDefault();
80
+ this.previousMatching();
81
+ break;
82
+ case 40: // down
83
+ event.preventDefault();
84
+ this.nextMatching();
85
+ break;
86
+ }
87
+ event.stopPropagation();
88
+ },
89
+
90
+ previousMatching: function () {
91
+ var
92
+ matchings = this.get('matchings'),
93
+ highlightedMatching = this.get('highlightedMatching'),
94
+ index = matchings.indexOf(highlightedMatching);
95
+
96
+ if (index === 0) {
97
+ highlightedMatching = matchings.get('lastObject');
98
+ } else {
99
+ highlightedMatching = matchings[index - 1];
100
+ }
101
+ this.set('highlightedMatching', highlightedMatching);
102
+ },
103
+
104
+ nextMatching: function () {
105
+ var
106
+ matchings = this.get('matchings'),
107
+ highlightedMatching = this.get('highlightedMatching'),
108
+ index = matchings.indexOf(highlightedMatching) + 1;
109
+
110
+ if (index === matchings.get('length')) {
111
+ highlightedMatching = matchings.get('firstObject');
112
+ } else {
113
+ highlightedMatching = matchings[index];
114
+ }
115
+ this.set('highlightedMatching', highlightedMatching);
116
+ },
117
+
118
+ insertNewline: function () {
119
+ this.selectMatching({ context: this.get('highlightedMatching') });
120
+ },
121
+
122
+ selectMatching: function (event) {
123
+ this.set('filter', '');
124
+ this.set('matchings', []);
125
+ this.$().focus();
126
+ this.matchingSelected(event.context);
127
+ },
128
+
129
+ updateMatchings: function () {
130
+ var
131
+ self = this,
132
+ filter = this.get('filter'),
133
+ matchings = this.get('matchings'),
134
+ lostMatchings = matchings.copy();
135
+
136
+ if (filter) {
137
+ this.filterChanged(
138
+ filter,
139
+ function (data, callback) {
140
+ self._retrieveMatchings({
141
+ url: self.get('matchingsUrl'),
142
+ data: data,
143
+ dataType: 'json',
144
+ async: false,
145
+ success: callback
146
+ });
147
+ },
148
+ function (freshMatchings) {
149
+ freshMatchings.forEach(function (matching) {
150
+ var alreadyExisting = matchings.findProperty('id', matching.id);
151
+ if (alreadyExisting) {
152
+ lostMatchings.removeObject(alreadyExisting);
153
+ } else {
154
+ matchings.pushObject(matching);
155
+ }
156
+ });
157
+ lostMatchings.forEach(function (lostMatching) {
158
+ matchings.removeObject(lostMatching);
159
+ });
160
+ });
161
+ } else {
162
+ this.set('matchings', []);
163
+ }
164
+ }.observes('filter'),
165
+
166
+ _retrieveMatchings: function (params) {
167
+ $.ajax(params);
168
+ },
169
+
170
+ /**
171
+ Default implementation, you should override this method to customize request params/matchings handling.
172
+ */
173
+ filterChanged: function (filter, retrieveMatchings, processMatchings) {
174
+ retrieveMatchings({
175
+ filter: filter
176
+ }, function (data) {
177
+ processMatchings(data.matchings);
178
+ });
179
+ }
180
+ });
@@ -0,0 +1,3 @@
1
+ module EmbootstrapRails
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,7 @@
1
+ module EmbootstrapRails
2
+ module Rails
3
+
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embootstrap-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mike Aski
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-07 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Take advantage of the assets pipeline to include just the needed plugins,
15
+ implemented in an Ember way and customizable.
16
+ email:
17
+ - mike.aski@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/embootstrap-rails.rb
23
+ - lib/embootstrap-rails/version.rb
24
+ - lib/assets/javascripts/embootstrap/typeahead.js
25
+ - lib/assets/javascripts/embootstrap/embootstrap.js
26
+ - MIT-LICENSE
27
+ - Rakefile
28
+ - README.md
29
+ homepage: https://github.com/Status-101/embootstrap-rails
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ segments:
42
+ - 0
43
+ hash: 3026814939654337449
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ segments:
51
+ - 0
52
+ hash: 3026814939654337449
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.24
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: An Ember based port of the Bootstrap plugins for integration into Rails.
59
+ test_files: []