marxjs-rails 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65723bad7dab05355d86345f2266b62d67094c61
4
- data.tar.gz: 6eeca9bf25b28cd2fda2b1711131d5d061384abc
3
+ metadata.gz: 7b6f79caca0be1c6f08059bb7c9c0317484559cd
4
+ data.tar.gz: e19f46b9f25005b5d49b66ece78785b6150fb1f1
5
5
  SHA512:
6
- metadata.gz: d99db0819c191cf73ca7f60b8804a28da3fc227bc7dbff59c48aec0fc59d4f0d295878f45585e420fa815173225692d378f24a628cca9da52e11c6194ed4a7ab
7
- data.tar.gz: fd84e317ac87aefac986fad944a623c40e7b175c2505288a86299ffdf4f71b7ea632fa45597be5224acb117eb9da7784ea0f72102b64f495428106de91ceb3b5
6
+ metadata.gz: 3c0d6f3d65ab87283d777dee4be3174b652911d40b63f0fbd3fdf6187a8ae0086872c7fe919cc48a0ac44ab764b842bff66bdb206ebee41f8b5d1d8987359ff2
7
+ data.tar.gz: 37ad2189e9668c2fb2ef316369896b0e2f8959bfaade9dbd739900dbd7895911372c01c76bd2c19b6b9394909d6e881adcaafbec9c963ba2dbb48c5039e7f4ea
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # Marxjs::Rails
1
+ # marxjs-rails gem
2
2
 
3
- TODO: Write a gem description
3
+ Marx.js was created for developers building web applications with long forms. Marx.js is a plugin that gives the developer the ability to populate any and all the fields in their forms easily and with a small 10kb file.
4
+
5
+ Forms are populated with Marx Brother names, years of their movies and quotes from those movies.
4
6
 
5
7
  ## Installation
6
8
 
@@ -1,6 +1,6 @@
1
1
  window.Marx = function(options) {
2
2
  var _this = this;
3
- return $.getJSON("http://marxjs.sparkmasterflex.com:9292/quotes", function(data) {
3
+ return $.getJSON("http://marxjs.sparkmasterflex.com:9292/characters", function(data) {
4
4
  _this.marx_json = data;
5
5
  return _this.initialize(options);
6
6
  });
@@ -34,7 +34,7 @@ $.extend(Marx.prototype, {
34
34
  create_controls: function() {
35
35
  var open_controls,
36
36
  _this = this;
37
- $('body').append("<div class=\"marx-js-controls " + this.settings.position + "\">\n <link rel=\"stylesheet\" href=\"/assets/marx.css\">\n</div>");
37
+ $('body').append("<div class=\"marx-js-controls " + this.settings.position + "\">\n <link rel=\"stylesheet\" href=\"http://marxjs.sparkmasterflex.com:9292/marx.css\">\n</div>");
38
38
  this.$el = $('.marx-js-controls');
39
39
  open_controls = this.settings.controls !== 'toggle-all' ? "<a href='#open-controls' class='open-controls'>MarxJS</a>" : "<div class=\"open-controls\">\n <a href=\"#advanced-controls\" class=\"advanced-controls\" title=\"Show Advanced Controls\">Advanced Controls</a>\n <a href=\"#standard-controls\" class=\"standard-controls\" title=\"Show Standard Controls\">Standard Controls</a>\n <a href=\"#populate-whole-form\" class=\"populate-whole-form\" title=\"Populate Whole Form\">MarxJS</a>\n</div>";
40
40
  this.$el.append(open_controls);
@@ -80,33 +80,50 @@ $.extend(Marx.prototype, {
80
80
  return this.$el.find(el);
81
81
  },
82
82
  add_standard_controls: function() {
83
- var standard,
83
+ var action, standard, _i, _len, _ref,
84
84
  _this = this;
85
- standard = "<div class=\"marx-standard-controls\">\n <h4>Populate Form Fields</h4>\n <div class=\"marx-js-group\">\n <p>Populate whole form</p>\n <a class='populate-whole-form' href=\"#populate-whole-form\">Go</a>\n </div>\n <div class=\"marx-js-group\">\n <p>Populate TextAreas</p>\n <a href=\"#populate-textareas\" class=\"populate-textareas\">Go</a>\n </div>\n <div class=\"marx-js-group\">\n <p>Populate Inputs</p>\n <a href=\"#populate-inputs\" class=\"populate-inputs\">Go</a>\n </div>\n <div class=\"marx-js-group\">\n <p>Populate Check Boxes</p>\n <a href=\"#populate-checkboxes\" class=\"populate-checkboxes\">Go</a>\n </div>\n <div class=\"marx-js-group\">\n <p>Populate Radio Buttons</p>\n <a href=\"#populate-radios\" class=\"populate-radios\">Go</a>\n </div>\n <div class=\"marx-js-group\">\n <p>Populate Select Boxes</p>\n <a href=\"#populate-selects\" class=\"populate-selects\">Go</a>\n </div>\n</div>";
85
+ standard = "<div class=\"marx-standard-controls\">\n <h4>Populate Form Fields</h4>\n</div>";
86
86
  this.$('.open-controls').before(standard);
87
+ _ref = [['populate-whole-form', 'Populate Whole Form'], ['populate-textareas', 'Populate TextAreas'], ['populate-inputs', 'Populate Inputs'], ['populate-checkboxes', 'Populate Check Boxes'], ['populate-radios', 'Populate Radio Buttons'], ['populate-selects', 'Populate Select Boxes']];
88
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
89
+ action = _ref[_i];
90
+ $('.marx-standard-controls').append(this.build_action(action));
91
+ }
87
92
  return this.$('.marx-standard-controls a').click(function(e) {
88
93
  return _this.popluate_selected_fields(e);
89
94
  });
90
95
  },
91
96
  add_advanced_controls: function() {
92
- var advanced,
97
+ var action, advanced, _i, _len, _ref,
93
98
  _this = this;
94
- advanced = "<div class=\"marx-advanced-controls\">\n <h4>Advanced Options</h4>\n <div class=\"marx-js-group\">\n <p>Clear Form</p>\n <a href=\"#clear-form\" class=\"clear-form\">Go</a>\n </div>\n <div class=\"marx-js-group\">\n <p>Populate and Submit</p>\n <a href=\"#populate-submit\" class=\"populate-submit\">Go</a>\n </div>\n <div class=\"marx-js-group\">\n <p><span data-text=\"Hide\">Show</span> Hidden Fields</p>\n <a href=\"#show-hidden\" class=\"show-hidden\">Go</a>\n </div>\n <div class=\"marx-js-group\">\n <p><span data-text=\"Collapse\">Expand</span> Select Boxes</p>\n <a href=\"#expand-select\" class=\"expand-select\">Go</a>\n </div>\n <div class=\"marx-js-group ipsum\">\n <p>Generate Ipsum<br />\n <input min=\"1\" max=\"" + this.settings.max_ipsum + "\" type=\"number\" value='" + this.settings.ipsum + "' class=\"no-populate\" name=\"ipsum\" /> Paragraphs\n </p>\n <a href=\"#generate-ipsum\" class=\"generate-ipsum\">Go</a>\n </div>\n</div>";
99
+ advanced = "<div class=\"marx-advanced-controls\">\n <h4>Advanced Options</h4>\n</div>";
95
100
  this.$('.open-controls').before(advanced);
101
+ _ref = [['clear-form', 'Clear Form'], ['populate-submit', 'Populate and Submit'], ['show-hidden', '<span data-text="Hide">Show</span> Hidden Fields'], ['expand-select', '<span data-text="Collapse">Expand</span> Select Boxes'], ['random-image', 'Download Random Image'], ['generate-ipsum', 'Generate Ipsum']];
102
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
103
+ action = _ref[_i];
104
+ $('.marx-advanced-controls').append(this.build_action(action));
105
+ }
96
106
  if (this.settings.controls === 'toggle-advanced') {
97
- this.$('.marx-advanced-controls').hide();
98
- this.$('.marx-standard-controls').append("<a href='#advanced' class='marx-toggle-advanced'>&laquo; Advanced</a>");
99
- this.$('a.marx-toggle-advanced').click(function(e) {
100
- var txt;
101
- txt = $(e.target).hasClass('opened') ? "&laquo; Advanced" : "Close &raquo;";
102
- _this.$(e.target).toggleClass('opened').html(txt);
103
- return _this.$('.marx-advanced-controls').toggle();
104
- });
107
+ this.set_toggle_advanced();
105
108
  }
106
109
  return this.$('.marx-advanced-controls a').click(function(e) {
107
110
  return _this.advanced_actions(e);
108
111
  });
109
112
  },
113
+ build_action: function(action) {
114
+ return "<div class=\"marx-js-group\">\n <p>" + action[1] + "</p>\n <a href=\"#" + action[0] + "\" class=\"" + action[0] + "\">Go</a>\n</div>";
115
+ },
116
+ set_toggle_advanced: function() {
117
+ var _this = this;
118
+ this.$('.marx-advanced-controls').hide();
119
+ this.$('.marx-standard-controls').append("<a href='#advanced' class='marx-toggle-advanced'>&laquo; Advanced</a>");
120
+ return this.$('a.marx-toggle-advanced').click(function(e) {
121
+ var txt;
122
+ txt = $(e.target).hasClass('opened') ? "&laquo; Advanced" : "Close &raquo;";
123
+ _this.$(e.target).toggleClass('opened').html(txt);
124
+ return _this.$('.marx-advanced-controls').toggle();
125
+ });
126
+ },
110
127
  /*=========================
111
128
  POPULATE FORM METHODS
112
129
  =========================
@@ -124,39 +141,43 @@ $.extend(Marx.prototype, {
124
141
  var _this = this;
125
142
  this.effected.inputs = 0;
126
143
  return $.each($("" + this.settings.form + " input"), function(i, input) {
127
- var obj, val_arr;
144
+ var brother, movie, obj, strings, value;
128
145
  if (!($(input).val() !== "" || $(input).hasClass('no-populate'))) {
129
146
  if (['checkbox', 'radio', 'hidden'].indexOf($(input).attr('type') < 0)) {
130
147
  _this.effected.inputs += 1;
131
148
  }
132
- obj = _this.marx_json[Math.floor(Math.random() * _this.marx_json.length)];
133
- val_arr = [obj.brother, obj.movie_name];
134
- if (obj.alt_brother != null) {
135
- val_arr.push(obj.alt_brother);
136
- }
137
- if (['text', 'password'].indexOf($(input).attr('type') >= 0)) {
138
- $(input).attr('data-marx-d', true).val(val_arr[Math.floor(Math.random() * val_arr.length)]);
139
- }
140
- if ($(input).attr('type') === 'number') {
141
- $(input).attr('data-marx-d', true).val(obj.movie_year);
142
- }
143
- if ($(input).attr('type') === 'email') {
144
- $(input).attr('data-marx-d', true).val("" + obj.brother + "@" + (obj.movie_name.toLowerCase().replace(/\s/g, '')) + ".com");
145
- }
146
- if ($(input).attr('type') === 'date') {
147
- return $(input).attr('data-marx-d', true).val("" + obj.movie_year + "-01-01");
148
- }
149
+ obj = _this.get_random();
150
+ brother = JSON.parse(obj.brother);
151
+ movie = JSON.parse(obj.movie);
152
+ strings = [brother.name, movie.name, obj.first_name, obj.last_name, obj.description].filter(function() {
153
+ return true;
154
+ });
155
+ value = (function() {
156
+ switch ($(input).attr('type')) {
157
+ case 'number':
158
+ return movie.year;
159
+ case 'email':
160
+ return "" + (brother.name.toLowerCase().replace(/\s/g, '')) + "@" + (movie.name.toLowerCase().replace(/\s/g, '')) + ".com";
161
+ case 'url':
162
+ return "http://" + (movie.name.toLowerCase().replace(/\s/g, '')) + ".com";
163
+ case 'date':
164
+ return "" + movie.year + "-01-01";
165
+ default:
166
+ return strings[Math.floor(Math.random() * strings.length)];
167
+ }
168
+ })();
169
+ return $(input).attr('data-marx-d', true).val(value);
149
170
  }
150
171
  });
151
172
  },
152
173
  populate_textareas: function() {
153
174
  var _this = this;
154
175
  this.effected.textareas = 0;
155
- return $.each($("" + this.settings.form + " textarea"), function(i, input) {
156
- var obj;
157
- _this.effected.textareas += 1;
158
- obj = _this.marx_json[Math.floor(Math.random() * _this.marx_json.length)];
159
- return $(input).attr('data-marx-d', true).val(obj.body);
176
+ return $.getJSON("http://marxjs.sparkmasterflex.com:9292/quotes", function(data) {
177
+ return $.each($("" + _this.settings.form + " textarea"), function(i, input) {
178
+ _this.effected.textareas += 1;
179
+ return $(input).attr('data-marx-d', true).val(data[Math.floor(Math.random() * data.length)].body);
180
+ });
160
181
  });
161
182
  },
162
183
  populate_checkboxes: function() {
@@ -260,12 +281,11 @@ $.extend(Marx.prototype, {
260
281
  _this = this;
261
282
  $('.marx-generated-ipsum').remove();
262
283
  num = this.$('.ipsum input').val();
263
- $ipsum = $("<div class='marx-generated-ipsum " + this.settings.position + "'>\n <h4>Marx Ipsum</h4>\n <a href='#close' class='marx-ipsum-close'>X</a>\n <div class='container'></div>\n</div>");
284
+ $ipsum = $("<div class='marx-generated-ipsum " + this.settings.position + "'>\n <h4>Marx Ipsum</h4>\n <a href='#close' class='marx-ipsum-close'>X</a>\n <div class='marx-container'></div>\n</div>");
264
285
  $('body').append($ipsum);
265
286
  return $.getJSON("http://marxjs.sparkmasterflex.com:9292/monologues", function(data) {
266
287
  var i, max, monologues, _i;
267
288
  max = num > data.length ? data.length - 1 : num;
268
- console.log("Generated the maximum amount of paragraphs available: " + data.length);
269
289
  monologues = data.sort(function() {
270
290
  return 0.5 - Math.random();
271
291
  });
@@ -278,6 +298,9 @@ $.extend(Marx.prototype, {
278
298
  });
279
299
  });
280
300
  },
301
+ get_random: function() {
302
+ return this.marx_json[Math.floor(Math.random() * this.marx_json.length)];
303
+ },
281
304
  /*=====================
282
305
  EVENTS
283
306
  =====================
@@ -323,8 +346,8 @@ $.extend(Marx.prototype, {
323
346
  $('select[data-marx-d=true] option:eq(0)').attr('selected', true);
324
347
  break;
325
348
  case 'populate-submit':
326
- $.when(this.populate_inputs(), this.populate_textareas(), this.populate_checkboxes(), this.populate_radios(), this.populate_selects()).then(function() {
327
- $(e.target).replace("<span class='spinner'>Loading</span>");
349
+ $.when(this.populate_whole_form()).then(function() {
350
+ $(e.target).replaceWith("<span class='spinner'>Loading</span>");
328
351
  return setTimeout(function() {
329
352
  return $('form').submit();
330
353
  }, 500);
@@ -346,6 +369,9 @@ $.extend(Marx.prototype, {
346
369
  }
347
370
  });
348
371
  break;
372
+ case 'random-image':
373
+ window.location = "http://marxjs.sparkmasterflex.com:9292/get-image";
374
+ break;
349
375
  case 'generate-ipsum':
350
376
  this.generate_ipsum();
351
377
  }
@@ -85,7 +85,7 @@
85
85
  position: absolute;
86
86
  display: block;
87
87
  width: 195px;
88
- background-image: url(groucho.png);
88
+ background-image: url(http://marxjs.sparkmasterflex.com/assets/icons/groucho.png);
89
89
  background-color: #ddd;
90
90
  background-repeat: no-repeat;
91
91
  background-position: 5px center;
@@ -120,9 +120,9 @@
120
120
  background-size: 24px 24px;
121
121
  text-align: left; }
122
122
  .marx-js-controls .open-controls a.standard-controls {
123
- background-image: url(standard.png); }
123
+ background-image: url(http://marxjs.sparkmasterflex.com/assets/icons/standard.png); }
124
124
  .marx-js-controls .open-controls a.advanced-controls {
125
- background-image: url(advanced.png); }
125
+ background-image: url(http://marxjs.sparkmasterflex.com/assets/icons/advanced.png); }
126
126
 
127
127
  .bottom-right, .bottom-left {
128
128
  bottom: 0;
@@ -197,3 +197,5 @@
197
197
  background-color: #333;
198
198
  text-align: center;
199
199
  text-decoration: none; }
200
+
201
+ /*# sourceMappingURL=marx.css.map */
@@ -1,5 +1,5 @@
1
1
  module Marxjs
2
2
  module Rails
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marxjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Raymond
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-20 00:00:00.000000000 Z
11
+ date: 2014-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: railties
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>'
45
+ - - ">"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>'
52
+ - - ">"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.1'
55
55
  description: MARXjs was created for developers building web applications with long
@@ -62,15 +62,15 @@ executables: []
62
62
  extensions: []
63
63
  extra_rdoc_files: []
64
64
  files:
65
- - lib/marxjs/rails/version.rb
66
- - lib/marxjs/rails.rb
65
+ - MIT-LICENSE
66
+ - README.md
67
67
  - app/assets/images/advanced.png
68
68
  - app/assets/images/groucho.png
69
69
  - app/assets/images/standard.png
70
70
  - app/assets/javascripts/marx.js
71
71
  - app/assets/stylesheets/marx.css
72
- - MIT-LICENSE
73
- - README.md
72
+ - lib/marxjs/rails.rb
73
+ - lib/marxjs/rails/version.rb
74
74
  homepage: https://github.com/Sparkmasterflex/marxjs-rails
75
75
  licenses:
76
76
  - MIT
@@ -81,17 +81,17 @@ require_paths:
81
81
  - lib
82
82
  required_ruby_version: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - '>='
84
+ - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - '>='
89
+ - - ">="
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.0.14
94
+ rubygems_version: 2.4.2
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: A JavaScript plugin for populating forms to speed up testing