fixie-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ # fixie-rails
2
+
3
+ This is simiply a packaged up copy of [Ryhan Hassan](https://github.com/rthprog)'s [Fixie.js](https://github.com/rthprog/fixie)
4
+
5
+ To learn more, check out [fixiejs.com](http://www.fixiejs.com "fixiejs")
6
+
7
+ # Installation
8
+
9
+ For Rails 3.1 and greater, the fixie.js will be added to the asset pipeline and available for you to use. Add the following line to the app/assets/javascripts/application.js file.
10
+
11
+ //= require fixie
12
+
13
+ ## License
14
+
15
+ The MIT License
16
+
17
+ Copyright (c) 2012 Ryhan Hassan
18
+
19
+ 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:
20
+
21
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
22
+
23
+ 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.
24
+
@@ -0,0 +1,2 @@
1
+ require "fixie-rails/version"
2
+ require "fixie-rails/engine"
@@ -0,0 +1,7 @@
1
+ module Fixie
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ # Ohai, Rails, I has some vendor for you!
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Fixie
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,209 @@
1
+ /*
2
+ * Fixie.js
3
+ * by Ryhan Hassan
4
+ * ryhanh@me.com
5
+ *
6
+ * Automagically adds filler content
7
+ * whenever an element has class="fixie".
8
+ * Hope you find it useful :)
9
+ */
10
+ var fixie = (
11
+
12
+ function () {
13
+
14
+ if (typeof window.getElementsByClassName != 'function') {
15
+ document.getElementsByClassName = function (cl) {
16
+ var retnode = [];
17
+ var myclass = new RegExp('\\b' + cl + '\\b');
18
+ var elem = this.getElementsByTagName('*');
19
+ for (var i = 0; i < elem.length; i++) {
20
+ var classes = elem[i].className;
21
+ if (myclass.test(classes)) retnode.push(elem[i]);
22
+ }
23
+ return retnode;
24
+ };
25
+ }
26
+
27
+ /*
28
+ * Spec
29
+ * Here are some functions you might find useful
30
+ *
31
+ * fixie_handler(element)
32
+ * fixie_handle_elements(elements)
33
+ *
34
+ * fixie_fetchWord();
35
+ * fixie_fetchPhrase();
36
+ * fixie_fetchSentence();
37
+ * fixie_fetchParagraph();
38
+ * fixie_fetchParagraphs();
39
+ *
40
+ */
41
+
42
+
43
+ /*
44
+ * fixie_handler(element)
45
+ *
46
+ * Takes in an element and adds filler content.
47
+ * Returns false if tag is unrecognized.
48
+ */
49
+ function fixie_handler(element) {
50
+ if (!/^\s*$/.test(element.innerHTML)){
51
+ var childs = element.children;
52
+ if(childs.length){
53
+ for(var fixie_i = 0; fixie_i < childs.length; fixie_i++){
54
+ fixie_handler(childs[fixie_i]);
55
+ }
56
+ }
57
+ return true;
58
+ }
59
+ switch (element.nodeName.toLowerCase()) {
60
+ case 'b':
61
+ case 'em':
62
+ case 'strong':
63
+ case 'button':
64
+ case 'th':
65
+ case 'td':
66
+ case 'title':
67
+ case 'tr':
68
+ element.innerHTML = fixie_fetchWord();
69
+ break;
70
+
71
+ case 'header':
72
+ case 'cite':
73
+ case 'caption':
74
+ case 'mark':
75
+ case 'q':
76
+ case 's':
77
+ case 'u':
78
+ case 'small':
79
+ case 'span':
80
+ case 'code':
81
+ case 'pre':
82
+ case 'li':
83
+ case 'dt':
84
+ case 'h1':
85
+ case 'h2':
86
+ case 'h3':
87
+ case 'h4':
88
+ case 'h5':
89
+ case 'h6':
90
+ element.innerHTML = fixie_fetchPhrase();
91
+ break;
92
+
93
+ case 'footer':
94
+ case 'aside':
95
+ case 'summary':
96
+ case 'blockquote':
97
+ case 'p':
98
+ element.innerHTML = fixie_fetchParagraph();
99
+ break;
100
+
101
+ case 'article':
102
+ case 'section':
103
+ element.innerHTML = fixie_fetchParagraphs()
104
+ break;
105
+
106
+ /* Special cases */
107
+ case 'a':
108
+ element.href = "http://ryhan.me/";
109
+ element.innerHTML = "www." + fixie_fetchWord() + fixie_capitalize(fixie_fetchWord()) + ".com";
110
+ break;
111
+
112
+ case 'img':
113
+ var width = element.getAttribute('height') || element.setAttribute('width', 250) || 250;
114
+ var height = element.getAttribute('height') || element.setAttribute('height', 100) || 100;
115
+ element.src = "http://placehold.it/" + width + "x" + height;
116
+ break;
117
+
118
+ default:
119
+ element.innerHTML = fixie_fetchSentence();
120
+ return false;
121
+ }
122
+ return true;
123
+ }
124
+
125
+ // Handle an array of elements
126
+ function fixie_handle_elements(elements){
127
+ for (var i = 0; i < elements.length; i++) {
128
+ fixie_handler(elements[i]);
129
+ }
130
+ }
131
+
132
+
133
+ // Begin generator
134
+ var fixie_wordlibrary = ["I", "8-bit", "ethical", "reprehenderit", "delectus", "non", "latte", "fixie", "mollit", "authentic", "1982", "moon", "helvetica", "dreamcatcher", "esse", "vinyl", "nulla", "Carles", "bushwick", "bronson", "clothesline", "fin", "frado", "jug", "kale", "organic", "local", "fresh", "tassel", "liberal", "art", "the", "of", "bennie", "chowder", "daisy", "gluten", "hog", "capitalism", "is", "vegan", "ut", "farm-to-table", "etsy", "incididunt", "sunt", "twee", "yr", "before", "gentrify", "whatever", "wes", "Anderson", "chillwave", "dubstep", "sriracha", "voluptate", "pour-over", "esse", "trust-fund", "Pinterest", "Instagram", "DSLR", "vintage", "dumpster", "totally", "selvage", "gluten-free", "brooklyn", "placeat", "delectus", "sint", "magna", "brony", "pony", "party", "beer", "shot", "narwhal", "salvia", "letterpress", "art", "party", "street-art", "seitan", "anime", "wayfarers", "non-ethical", "viral", "iphone", "anim", "polaroid", "gastropub", "city", 'classy', 'original', 'brew']
135
+
136
+ function fixie_capitalize(string) {
137
+ return string.charAt(0).toUpperCase() + string.slice(1);
138
+ }
139
+
140
+ function fixie_fetchWord() {
141
+ return fixie_wordlibrary[constrain(0, fixie_wordlibrary.length - 1 )];
142
+ }
143
+
144
+ function constrain(min, max){
145
+ return Math.round(Math.random() * (max - min) + min)
146
+ }
147
+
148
+ function fixie_fetch(min, max, func){
149
+ var fixie_length = constrain(min, max) ;
150
+ var result = [];
151
+ for (var fixie_i = 0; fixie_i < fixie_length ; fixie_i++) {
152
+ result.push(func());
153
+ }
154
+ return fixie_capitalize(result.join(' '));
155
+ }
156
+
157
+ function fixie_fetchPhrase() {
158
+ return fixie_fetch(3, 5, fixie_fetchWord);
159
+ }
160
+
161
+ function fixie_fetchSentence() {
162
+ return fixie_fetch(4, 9, fixie_fetchWord) + '.';
163
+ }
164
+
165
+ function fixie_fetchParagraph() {
166
+ return fixie_fetch(3, 7, fixie_fetchSentence);
167
+ }
168
+
169
+ function fixie_fetchParagraphs() {
170
+ var fixie_length = constrain(3, 7);
171
+ var fixie_str = "";
172
+ for (var fixie_i = 0; fixie_i < fixie_length - 1; fixie_i++) {
173
+ fixie_str += "<p>" + fixie_fetchParagraph() + "</p>";
174
+ }
175
+ return fixie_str;
176
+ }
177
+
178
+
179
+
180
+ // Handle all elements with class 'fixie'
181
+ fixie_handle_elements(document.getElementsByClassName('fixie'));
182
+
183
+ // Handle elements which match give css selectors
184
+ function init_str(selector_str) {
185
+ if (!document.querySelectorAll) {
186
+ return false;
187
+ }
188
+ try {
189
+ fixie_handle_elements(document.querySelectorAll(selector_str));
190
+ return true;
191
+ }
192
+ catch (err) {
193
+ return false;
194
+ }
195
+ }
196
+
197
+ return {
198
+ /* returns true if successful, false otherwise */
199
+ 'init': function(strOrArr) {
200
+ if (typeof strOrArr === "object") {
201
+ return init_str(strOrArr.join(","));
202
+ }
203
+ else {
204
+ return init_str(strOrArr);
205
+ }
206
+ }
207
+ };
208
+
209
+ })();
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fixie-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christopher Sexton
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-05 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Ryhan Hassan's awesome Fixie.js packaged up for the rails asset pipeline
15
+ email:
16
+ - github@codeography.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - vendor/assets/javascripts/fixie.js
22
+ - lib/fixie-rails/engine.rb
23
+ - lib/fixie-rails/version.rb
24
+ - lib/fixie-rails.rb
25
+ - README.md
26
+ homepage: http://fixiejs.com/
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project: fixie-rails
46
+ rubygems_version: 1.8.15
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: Fixie.js for Rails Asset Pipeline
50
+ test_files: []