utility_box 0.1.0

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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in utility_box.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Grant Klinsing
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,44 @@
1
+ # UtilityBox
2
+
3
+ UtilityBox suppllies you will a bunch of CSS and Javascript niceties
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'utility_box'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install utility_box
18
+
19
+ ## What's Included?
20
+
21
+ ### Javascripts
22
+
23
+ - connection_manager
24
+ - ellipsis
25
+ - events
26
+ - form
27
+ - preload_images
28
+ - pusher
29
+ - strings
30
+ - tables
31
+
32
+ ### Stylesheets
33
+
34
+ - [Twitter Bootstrap SASS](https://github.com/thomas-mcdonald/bootstrap-sass)
35
+ - [Font Awesome SASS](https://github.com/littlebtc/font-awesome-sass-rails)
36
+ - mixins
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,93 @@
1
+ #= require utility_box/utility_box_namespace
2
+ #= require utility_box/forms
3
+
4
+ # @class connectionManager
5
+ # A simple global interface for ajax calls and handlebars templates
6
+ #
7
+ # @method get
8
+ # resource [Handlebar Template]
9
+ # data [Object]
10
+ #
11
+ # @method post
12
+ # resource [Handlebar Template]
13
+ # data [Object]
14
+ #
15
+ # @method put
16
+ # resource [Handlebar Template]
17
+ # data [Object]
18
+ #
19
+ # @method destroy
20
+ # resource [Handlebar Template]
21
+ # data [Object]
22
+ #
23
+ # Example:
24
+ #
25
+ # file team_url.hbs
26
+ # /api/v1/team/{{id}}
27
+ #
28
+ # file script.js
29
+ # var conn = window.utilityBox.connectionManager()
30
+ # conn.get('team_url', {id: 1})
31
+ # conn.success(function(data){
32
+ # console.log(data)
33
+ # });
34
+ class window.utilityBox.connectionManager
35
+
36
+ constructor : ->
37
+ # gather tokens for each ajax call
38
+ @apiToken = $('meta[name="api-token"]').attr('content')
39
+ @csrfToken = $('meta[name="csrf-token"]').attr('content')
40
+
41
+ # add progress event to ajax calls
42
+ originalXhr = $.ajaxSettings.xhr
43
+ $.ajaxSetup({
44
+ progress: $.noop
45
+ xhr: ->
46
+ xhr = originalXhr()
47
+ if xhr instanceof window.XMLHttpRequest
48
+ xhr.addEventListener('progress', this.progress, false)
49
+
50
+ if xhr.upload
51
+ xhr.upload.addEventListener('progress', this.progress, false)
52
+
53
+ xhr.setRequestHeader 'X-CSRF-Token', @csrfToken
54
+ xhr
55
+ })
56
+
57
+ get : (resource, data={}) ->
58
+ @_send @_buildParams('GET', resource, data)
59
+
60
+ post : (resource, data={}) ->
61
+ @_send @_buildParams('POST', resource, data)
62
+
63
+ put : (resource, data={}) ->
64
+ @_send @_buildParams('PUT', resource, data)
65
+
66
+ destroy : (resource, data={}) ->
67
+ @_send @_buildParams('DELETE', resource, data)
68
+
69
+ _send : (params) ->
70
+ return $.ajax(params)
71
+
72
+ _buildParams : (method = 'POST', resource, data={}) ->
73
+ if method == 'GET'
74
+ formData = $.param(data)
75
+ else
76
+ formData = new FormData()
77
+ for key, val of window.utilityBox.parameterizeObject(data)
78
+ formData.append key, val
79
+
80
+ params = {
81
+ type : method
82
+ url : @buildEndpoint(resource, data)
83
+ username : 'x'
84
+ password : @apiToken
85
+ dataType : 'json'
86
+ data : formData
87
+ cache : false,
88
+ contentType : false,
89
+ processData : false
90
+ }
91
+
92
+ buildEndpoint : (resource='base_uri', data) ->
93
+ JST["endpoints/#{resource}"](data)
@@ -0,0 +1,22 @@
1
+
2
+ # Animate an ellipsis witin elements with the attribute 'data-animate="ellipsis"'
3
+ # Frame 1 .
4
+ # Frame 2 ..
5
+ # Frame 3 ...
6
+ # Frame 4 .
7
+ # Etc..
8
+ $(document).ready () ->
9
+ $('[data-animate="ellipsis"]').each (idx, ele) ->
10
+ ellipsis = $ ele
11
+ counter = 0
12
+ timer = setInterval () ->
13
+ counter++
14
+ counter = 0 if counter > 3
15
+ num = 0
16
+ arr = []
17
+ while num < counter
18
+ num++
19
+ arr.push '.'
20
+
21
+ ellipsis.text arr.join('')
22
+ , 750
@@ -0,0 +1,13 @@
1
+ #= require utility_box/utility_box_namespace
2
+
3
+ # @method isClickOutsideElement
4
+ # event [Event]
5
+ # element [DOM Element]
6
+ # Determines whether or not a click is outside of the element passed in
7
+ window.utilityBox.isClickOutsideElement = (event, element) ->
8
+ target = $ event.target
9
+
10
+ if target[0] == element[0] || element.children(target).length > 0
11
+ return false
12
+ else
13
+ return true
@@ -0,0 +1,63 @@
1
+ #= require utility_box/utility_box_namespace
2
+
3
+ # @method parameterizeObject
4
+ # data [Object]
5
+ # Generate correctly formatted parameters for xhr2
6
+ #
7
+ # {
8
+ # id: 1234567890,
9
+ # person: {
10
+ # first_name: 'Grant',
11
+ # last_name : 'Klinsing',
12
+ # meta : {
13
+ # foo: 'bar',
14
+ # test: [100, 200]
15
+ # }
16
+ # }
17
+ # }
18
+ #
19
+ # Will become:
20
+ #
21
+ # id = 1234567890
22
+ # person[first_name] = 'Grant'
23
+ # person[last_name] = 'Klinsing'
24
+ # person[meta][foo] = 'bar'
25
+ # person[meta][test] = [100, 200]
26
+ window.utilityBox.parameterizeObject = (data) ->
27
+ obj = {}
28
+
29
+ accLoop = (key, val) ->
30
+ if $.isPlainObject val
31
+ for k, v of val
32
+ k = "#{key}[#{k}]"
33
+ accLoop(k, v)
34
+ else
35
+ obj[key] = val
36
+ return
37
+
38
+ for key, val of data
39
+ accLoop(key, val)
40
+
41
+ obj
42
+
43
+ # @method serializeForm
44
+ # form [element|jQuery Element]
45
+ window.utilityBox.serializeForm = (form) ->
46
+ obj = {}
47
+ # if jQuery, break it down
48
+ form = form[0] if form.jquery
49
+ $.makeArray(form.querySelectorAll('input, select, textarea')).forEach (input) ->
50
+ if input.type == 'file'
51
+ obj[input.name] = input.files[0]
52
+ else
53
+ obj[input.name] = input.value
54
+
55
+ # remove properites that are undefined
56
+ for key, val of obj
57
+ if val == undefined
58
+ delete obj[key]
59
+
60
+ obj
61
+
62
+ $(document).ready () ->
63
+ $('[data-is="datepicker"]').datepicker()
@@ -0,0 +1,22 @@
1
+ #= require utility_box/utility_box_namespace
2
+
3
+ # @method preloadImages
4
+ # urls [String, Array]
5
+ # callback [Function]
6
+ # callback fired when all images have loaded
7
+ window.utilityBox.preloadImages = (urls, callback) ->
8
+ urls = [urls] if typeof urls == 'string'
9
+ images = []
10
+ loaded = 0
11
+ increment = ->
12
+ loaded++
13
+ if callback? && loaded == urls.length
14
+ callback()
15
+ urls.forEach (url, i) ->
16
+ img = images[i]
17
+ img = new Image()
18
+ # we want to increment on each of these events
19
+ img.onload = increment
20
+ img.onerror = increment
21
+ img.onabort = increment
22
+ img.src = url
@@ -0,0 +1,13 @@
1
+ # Pusher.js.coffee
2
+ # This file is used to establish a pusher connection and any defaults or
3
+ # channel subscriptions that should be established globally for an artist.
4
+ #
5
+ #= require utility_box/utility_box_namespace
6
+ #= require pusher
7
+ #
8
+
9
+ do ->
10
+ key = $('meta[name=pusher-key]').attr('content')
11
+
12
+ if key
13
+ window.utilityBox.pusher = new Pusher(key)
@@ -0,0 +1,29 @@
1
+ #= require utility_box/utility_box_namespace
2
+
3
+ # @method titleize
4
+ # str [String]
5
+ # Titleize a string
6
+ window.utilityBox.titleize = (str) ->
7
+ str.charAt(0).toUpperCase() + str.slice(1)
8
+
9
+ # @method formatJSONErrors
10
+ # str [String, Object]
11
+ # withKeys [Boolean]
12
+ # Takes a JSON object and convert it to a readable sentence
13
+ #
14
+ # Example:
15
+ # {email: ["must be at least 6 characters","must contain a number and a letter"]}
16
+ # will be translated to:
17
+ # ["email must be at least 6 characters and must contain a number and a letter"]
18
+ window.utilityBox.formatJSONErrors = (str, withKeys) ->
19
+ errors = if typeof str == 'string' then JSON.parse(str) else str
20
+ $.map errors, (val, key) ->
21
+ values = val.join(' and ')
22
+ str = window.utilityBox.titleize "#{key} #{values}"
23
+
24
+ if withKeys?
25
+ obj = {}
26
+ obj[key] = str
27
+ obj
28
+ else
29
+ str
@@ -0,0 +1,2 @@
1
+ $(document).on 'click', 'tr[data-href]', (e) ->
2
+ window.location = $(e.currentTarget).attr('data-href')
@@ -0,0 +1 @@
1
+ window.utilityBox = window.utilityBox || {}
@@ -0,0 +1,9 @@
1
+ //= require utility_box/utility_box_namespace
2
+ //= require utility_box/connection_manager
3
+ //= require utility_box/ellipsis
4
+ //= require utility_box/events
5
+ //= require utility_box/forms
6
+ //= require utility_box/preload_images
7
+ //= require utility_box/pusher
8
+ //= require utility_box/strings
9
+ //= require utility_box/tables
@@ -0,0 +1,24 @@
1
+ @mixin gradient($first, $second) {
2
+ background-color: $first;
3
+ background: -moz-linear-gradient(top, $first 0%, $second 100%);
4
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,$first), color-stop(100%,$second));
5
+ background: -webkit-linear-gradient(top, $first 0%,$second 100%);
6
+ background: -o-linear-gradient(top, $first 0%,$second 100%);
7
+ background: -ms-linear-gradient(top, $first 0%,$second 100%);
8
+ background: linear-gradient(to bottom, $first 0%,$second 100%);
9
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='$first', endColorstr='$second',GradientType=0 );
10
+ }
11
+
12
+ @mixin trans($property: all, $time: 1s, $effect: ease, $delay: 0) {
13
+ -moz-transition: $property $time $effect $delay;
14
+ -webkit-transition: $property $time $effect $delay;
15
+ -ms-transition: $property $time $effect $delay;
16
+ -o-transition: $property $time $effect $delay;
17
+ transition: $property $time $effect $delay;
18
+ }
19
+
20
+ @mixin border-box {
21
+ box-sizing: border-box;
22
+ -moz-box-sizing: border-box;
23
+ -webkit-box-sizing: border-box;
24
+ }
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require utility_box/mixins
3
+ */
@@ -0,0 +1,5 @@
1
+ module UtilityBox
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "utility_box/rails/version"
2
+
3
+ module UtilityBox
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ require 'pusher_rails'
2
+ require 'bootstrap-sass'
3
+ require 'font-awesome-sass-rails'
4
+
5
+ require "utility_box/rails"
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: utility_box
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Grant Klinsing
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bootstrap-sass
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.2.2.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: 2.2.2.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: font-awesome-sass-rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pusher_rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: railties
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '3.1'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '3.1'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rails
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '3.1'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '3.1'
94
+ description: CSS and JS utility toolbox for Rails
95
+ email:
96
+ - grant@digitalopera.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - lib/utility_box/rails/version.rb
102
+ - lib/utility_box/rails.rb
103
+ - lib/utility_box.rb
104
+ - app/assets/javascripts/utility_box/connection_manager.js.coffee
105
+ - app/assets/javascripts/utility_box/ellipsis.js.coffee
106
+ - app/assets/javascripts/utility_box/events.js.coffee
107
+ - app/assets/javascripts/utility_box/forms.js.coffee
108
+ - app/assets/javascripts/utility_box/preload_images.js.coffee
109
+ - app/assets/javascripts/utility_box/pusher.js.coffee
110
+ - app/assets/javascripts/utility_box/strings.js.coffee
111
+ - app/assets/javascripts/utility_box/tables.js.coffee
112
+ - app/assets/javascripts/utility_box/utility_box_namespace.js.coffee
113
+ - app/assets/javascripts/utility_box.js
114
+ - app/assets/stylesheets/utility_box/mixins.css.scss
115
+ - app/assets/stylesheets/utility_box.css
116
+ - Gemfile
117
+ - LICENSE.txt
118
+ - Rakefile
119
+ - README.md
120
+ homepage: ''
121
+ licenses: []
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 1.8.23
141
+ signing_key:
142
+ specification_version: 3
143
+ summary: Adds a bunch of utility Javascript and CSS scaffolding via Twiiter Bootstrap
144
+ test_files: []