spontaneous 0.2.0.beta5 → 0.2.0.beta6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +39 -0
  4. data/Gemfile +2 -0
  5. data/Readme.markdown +4 -4
  6. data/application/css/core.css.scss +144 -43
  7. data/application/css/definitions.css.scss +50 -16
  8. data/application/css/dialogue.css.scss +5 -2
  9. data/application/css/editing.css.scss +7 -7
  10. data/application/css/font.css.scss +1 -1
  11. data/application/css/meta.css.scss +6 -6
  12. data/application/css/popover.css.scss +6 -6
  13. data/application/css/top.css.scss +8 -1
  14. data/application/js/add_alias_dialogue.js +137 -36
  15. data/application/js/add_home_dialogue.js +10 -10
  16. data/application/js/ajax.js +26 -26
  17. data/application/js/authentication.js +2 -2
  18. data/application/js/box.js +21 -10
  19. data/application/js/box_container.js +13 -7
  20. data/application/js/compatibility.js +19 -17
  21. data/application/js/conflicted_field_dialogue.js +5 -5
  22. data/application/js/content.js +22 -16
  23. data/application/js/content_area.js +62 -33
  24. data/application/js/dialogue.js +16 -16
  25. data/application/js/dom.js +9 -10
  26. data/application/js/edit_panel.js +25 -20
  27. data/application/js/editing.js +21 -8
  28. data/application/js/entry.js +1 -1
  29. data/application/js/extensions.js +11 -11
  30. data/application/js/field/boolean.js +6 -6
  31. data/application/js/field/date.js +1 -1
  32. data/application/js/field/file.js +17 -17
  33. data/application/js/field/image.js +27 -27
  34. data/application/js/field/markdown.js +72 -71
  35. data/application/js/field/select.js +9 -9
  36. data/application/js/field/string.js +3 -3
  37. data/application/js/field/webvideo.js +2 -2
  38. data/application/js/field_preview.js +3 -0
  39. data/application/js/init.js +3 -2
  40. data/application/js/jquery-selection-position.js +13 -13
  41. data/application/js/location.js +17 -12
  42. data/application/js/login.js +2 -2
  43. data/application/js/meta_view/user_admin.js +101 -101
  44. data/application/js/metadata.js +1 -1
  45. data/application/js/page.js +2 -2
  46. data/application/js/page_browser.js +13 -13
  47. data/application/js/page_entry.js +1 -1
  48. data/application/js/panel/root_menu.js +10 -10
  49. data/application/js/popover.js +6 -5
  50. data/application/js/popover_view.js +5 -5
  51. data/application/js/preview.js +10 -4
  52. data/application/js/progress.js +6 -6
  53. data/application/js/properties.js +35 -6
  54. data/application/js/publish.js +43 -43
  55. data/application/js/require.js +14 -14
  56. data/application/js/services.js +3 -3
  57. data/application/js/sharded_upload.js +9 -8
  58. data/application/js/side_bar.js +5 -5
  59. data/application/js/state.js +2 -2
  60. data/application/js/status_bar.js +6 -6
  61. data/application/js/top_bar.js +97 -65
  62. data/application/js/types.js +9 -6
  63. data/application/js/upload.js +4 -4
  64. data/application/js/upload_manager.js +21 -21
  65. data/application/js/user.js +1 -1
  66. data/application/js/vendor/jquery.velocity.min.js +7 -0
  67. data/application/js/views.js +32 -8
  68. data/application/js/views/box_view.js +51 -31
  69. data/application/js/views/page_piece_view.js +17 -15
  70. data/application/js/views/page_view.js +54 -43
  71. data/application/js/views/piece_view.js +44 -37
  72. data/application/static/font/fontawesome-webfont-4f0022f25672c7f501c339cbf98d9117.ttf +0 -0
  73. data/application/views/index.erb +1 -0
  74. data/db/migrations/20130114120000_create_revision_tables.rb +2 -1
  75. data/db/migrations/20130813111009_increase_path_length.rb +11 -2
  76. data/db/migrations/20140506171823_add_index_to_target_id.rb +11 -0
  77. data/db/migrations/20140514090204_add_content_hash.rb +59 -0
  78. data/db/migrations/20140519150253_add_content_hash_timestamp.rb +20 -0
  79. data/lib/spontaneous.rb +0 -1
  80. data/lib/spontaneous/asset/environment.rb +77 -15
  81. data/lib/spontaneous/box.rb +21 -0
  82. data/lib/spontaneous/capistrano/deploy.rb +1 -1
  83. data/lib/spontaneous/capistrano/sync.rb +8 -7
  84. data/lib/spontaneous/change.rb +4 -2
  85. data/lib/spontaneous/cli/fields.rb +7 -3
  86. data/lib/spontaneous/cli/generate.rb +2 -0
  87. data/lib/spontaneous/cli/init.rb +24 -93
  88. data/lib/spontaneous/cli/init/db.rb +94 -0
  89. data/lib/spontaneous/cli/init/mysql.rb +17 -0
  90. data/lib/spontaneous/cli/init/postgresql.rb +33 -0
  91. data/lib/spontaneous/cli/init/sqlite.rb +14 -0
  92. data/lib/spontaneous/cli/site.rb +45 -20
  93. data/lib/spontaneous/collections/box_set.rb +3 -0
  94. data/lib/spontaneous/collections/entry_set.rb +43 -4
  95. data/lib/spontaneous/collections/field_set.rb +14 -2
  96. data/lib/spontaneous/data_mapper.rb +40 -7
  97. data/lib/spontaneous/data_mapper/content_model.rb +1 -1
  98. data/lib/spontaneous/data_mapper/content_model/associations.rb +63 -12
  99. data/lib/spontaneous/data_mapper/content_model/timestamps.rb +9 -14
  100. data/lib/spontaneous/data_mapper/content_table.rb +4 -2
  101. data/lib/spontaneous/data_mapper/dataset.rb +31 -2
  102. data/lib/spontaneous/data_mapper/scope.rb +37 -20
  103. data/lib/spontaneous/errors.rb +6 -0
  104. data/lib/spontaneous/facet.rb +20 -10
  105. data/lib/spontaneous/field/base.rb +8 -1
  106. data/lib/spontaneous/field/file.rb +28 -3
  107. data/lib/spontaneous/field/image.rb +2 -0
  108. data/lib/spontaneous/field/update.rb +6 -0
  109. data/lib/spontaneous/field/webvideo/vimeo.rb +6 -1
  110. data/lib/spontaneous/field/webvideo/vine.rb +1 -1
  111. data/lib/spontaneous/field/webvideo/youtube.rb +1 -1
  112. data/lib/spontaneous/generators/site.rb +6 -4
  113. data/lib/spontaneous/generators/site/.gitignore +1 -0
  114. data/lib/spontaneous/generators/site/Gemfile.tt +3 -3
  115. data/lib/spontaneous/generators/site/config/{indexes.rb.tt → initializers/indexes.rb.tt} +0 -0
  116. data/lib/spontaneous/generators/site/config/initializers/publishing.rb.tt +78 -0
  117. data/lib/spontaneous/generators/site/{config/database.yml.tt → db/mysql2.yml.tt} +7 -6
  118. data/lib/spontaneous/generators/site/db/postgres.yml.tt +25 -0
  119. data/lib/spontaneous/generators/site/db/sqlite3.yml.tt +18 -0
  120. data/lib/spontaneous/generators/site/public/humans.txt.tt +14 -0
  121. data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +51 -0
  122. data/lib/spontaneous/loader.rb +1 -1
  123. data/lib/spontaneous/logger.rb +1 -1
  124. data/lib/spontaneous/media/image/optimizer.rb +1 -1
  125. data/lib/spontaneous/media/image/processor.rb +11 -2
  126. data/lib/spontaneous/media/image/renderable.rb +2 -0
  127. data/lib/spontaneous/model.rb +3 -0
  128. data/lib/spontaneous/model/box/allowed_types.rb +17 -4
  129. data/lib/spontaneous/model/core.rb +36 -3
  130. data/lib/spontaneous/model/core/aliases.rb +5 -2
  131. data/lib/spontaneous/model/core/boxes.rb +6 -0
  132. data/lib/spontaneous/model/core/cascading_change.rb +38 -0
  133. data/lib/spontaneous/model/core/content_hash.rb +171 -0
  134. data/lib/spontaneous/model/core/entries.rb +0 -19
  135. data/lib/spontaneous/model/core/fields.rb +11 -0
  136. data/lib/spontaneous/model/core/modifications.rb +22 -21
  137. data/lib/spontaneous/model/core/render.rb +3 -0
  138. data/lib/spontaneous/model/core/serialisation.rb +18 -17
  139. data/lib/spontaneous/model/page.rb +35 -8
  140. data/lib/spontaneous/model/page/page_tree.rb +20 -8
  141. data/lib/spontaneous/model/page/paths.rb +79 -50
  142. data/lib/spontaneous/model/page/singleton.rb +71 -0
  143. data/lib/spontaneous/model/page/site_map.rb +2 -1
  144. data/lib/spontaneous/model/page/site_timestamps.rb +2 -2
  145. data/lib/spontaneous/model/piece.rb +10 -0
  146. data/lib/spontaneous/output/context.rb +13 -6
  147. data/lib/spontaneous/output/format.rb +30 -5
  148. data/lib/spontaneous/output/helpers/script_helper.rb +8 -0
  149. data/lib/spontaneous/output/helpers/stylesheet_helper.rb +7 -0
  150. data/lib/spontaneous/output/renderable.rb +16 -0
  151. data/lib/spontaneous/output/store.rb +1 -1
  152. data/lib/spontaneous/output/template/renderer.rb +2 -2
  153. data/lib/spontaneous/page_piece.rb +25 -1
  154. data/lib/spontaneous/prototypes/box_prototype.rb +13 -0
  155. data/lib/spontaneous/prototypes/field_prototype.rb +7 -4
  156. data/lib/spontaneous/publishing.rb +10 -5
  157. data/lib/spontaneous/publishing/immediate.rb +32 -349
  158. data/lib/spontaneous/publishing/pipeline.rb +43 -0
  159. data/lib/spontaneous/publishing/progress.rb +186 -0
  160. data/lib/spontaneous/publishing/publish.rb +107 -0
  161. data/lib/spontaneous/publishing/rerender.rb +17 -0
  162. data/lib/spontaneous/publishing/revision.rb +53 -18
  163. data/lib/spontaneous/publishing/simultaneous.rb +1 -1
  164. data/lib/spontaneous/publishing/steps.rb +154 -0
  165. data/lib/spontaneous/publishing/steps/activate_revision.rb +45 -0
  166. data/lib/spontaneous/publishing/steps/archive_old_revisions.rb +22 -0
  167. data/lib/spontaneous/publishing/steps/base_step.rb +49 -0
  168. data/lib/spontaneous/publishing/steps/copy_static_files.rb +74 -0
  169. data/lib/spontaneous/publishing/steps/create_revision_directory.rb +24 -0
  170. data/lib/spontaneous/publishing/steps/generate_rackup_file.rb +51 -0
  171. data/lib/spontaneous/publishing/steps/generate_search_indexes.rb +24 -0
  172. data/lib/spontaneous/publishing/steps/render_revision.rb +69 -0
  173. data/lib/spontaneous/publishing/steps/write_revision_file.rb +43 -0
  174. data/lib/spontaneous/rack/back.rb +3 -1
  175. data/lib/spontaneous/rack/back/alias.rb +9 -8
  176. data/lib/spontaneous/rack/front.rb +1 -1
  177. data/lib/spontaneous/rack/middleware.rb +7 -4
  178. data/lib/spontaneous/rack/middleware/transaction.rb +14 -0
  179. data/lib/spontaneous/rack/page_controller.rb +23 -8
  180. data/lib/spontaneous/revision.rb +5 -10
  181. data/lib/spontaneous/schema.rb +5 -0
  182. data/lib/spontaneous/server.rb +3 -1
  183. data/lib/spontaneous/site.rb +17 -10
  184. data/lib/spontaneous/site/publishing.rb +25 -3
  185. data/lib/spontaneous/site/state.rb +7 -3
  186. data/lib/spontaneous/tasks/database.rake +5 -10
  187. data/lib/spontaneous/utils/database/mysql_dumper.rb +5 -1
  188. data/lib/spontaneous/version.rb +1 -1
  189. data/spontaneous.gemspec +4 -3
  190. data/test/fixtures/example_application/config/initializers/initializer1.rb +1 -0
  191. data/test/fixtures/example_application/config/initializers/initializer2.rb +1 -0
  192. data/test/fixtures/example_application/config/initializers/publishing.rb +13 -0
  193. data/test/fixtures/search/config/{indexes.rb → initializers/indexes.rb} +0 -0
  194. data/test/fixtures/serialisation/root_hash.yaml.erb +10 -4
  195. data/test/functional/test_application.rb +10 -0
  196. data/test/functional/test_back.rb +23 -5
  197. data/test/functional/test_cli.rb +98 -34
  198. data/test/functional/test_front.rb +7 -3
  199. data/test/test_helper.rb +35 -28
  200. data/test/unit/test_alias.rb +20 -3
  201. data/test/unit/test_assets.rb +58 -30
  202. data/test/unit/test_changesets.rb +20 -12
  203. data/test/unit/test_content_hash.rb +496 -0
  204. data/test/unit/test_context.rb +28 -1
  205. data/test/unit/test_controllers.rb +96 -61
  206. data/test/unit/test_crypt.rb +1 -8
  207. data/test/unit/test_datamapper.rb +95 -19
  208. data/test/unit/test_features.rb +1 -4
  209. data/test/unit/test_fields.rb +61 -12
  210. data/test/unit/test_generators.rb +39 -2
  211. data/test/unit/test_images.rb +3 -1
  212. data/test/unit/test_modifications.rb +224 -219
  213. data/test/unit/test_output_store.rb +10 -0
  214. data/test/unit/{test_formats.rb → test_outputs.rb} +75 -6
  215. data/test/unit/test_page.rb +61 -15
  216. data/test/unit/test_plugins.rb +2 -42
  217. data/test/unit/test_publishing_pipeline.rb +1050 -0
  218. data/test/unit/test_render.rb +30 -0
  219. data/test/unit/test_revisions.rb +110 -2
  220. data/test/unit/test_schema.rb +4 -0
  221. data/test/unit/test_search.rb +1 -1
  222. data/test/unit/test_serialisation.rb +6 -1
  223. data/test/unit/test_singletons.rb +159 -0
  224. data/test/unit/test_site.rb +71 -44
  225. metadata +140 -86
  226. data/application/static/font/fontawesome-webfont-1c66a4738b40ef0f6b1abca0ba9a796d.ttf +0 -0
  227. data/test/unit/test_publishing.rb +0 -330
@@ -26,7 +26,7 @@ Spontaneous.Field.Markdown = (function($, S) {
26
26
 
27
27
  initialize: function(input) {
28
28
  this.input = input.bind('keydown.markdown', function(event) {
29
- var key = String.fromCharCode(event.keyCode)
29
+ var key = String.fromCharCode(event.keyCode);
30
30
  if ((event.ctrlKey || event.metaKey) && key === this.key_shortcut()) {
31
31
  this.execute(event);
32
32
  return false;
@@ -34,7 +34,7 @@ Spontaneous.Field.Markdown = (function($, S) {
34
34
  }.bind(this));
35
35
  },
36
36
  key_shortcut: function() {
37
- return "";
37
+ return '';
38
38
  },
39
39
  execute: function(event) {
40
40
  this.wrap();
@@ -44,7 +44,7 @@ Spontaneous.Field.Markdown = (function($, S) {
44
44
  before = s.before, middle = s.selection, after = s.after, wrapped;
45
45
  // if ((end - start) <= 0 ) { return; }
46
46
  if (this.matches_selection(middle)) {
47
- wrapped = this.remove(middle)
47
+ wrapped = this.remove(middle);
48
48
  } else {
49
49
  wrapped = this.surround(middle);
50
50
  }
@@ -59,13 +59,13 @@ Spontaneous.Field.Markdown = (function($, S) {
59
59
  var selected = state.selection, m, l;
60
60
  m = /^( +)/.exec(selected);
61
61
  if (m) {
62
- l = m[1].length
62
+ l = m[1].length;
63
63
  state.start += l;
64
64
  state.selection = selected.substr(l);
65
65
  }
66
66
  m = /( +)$/.exec(selected);
67
67
  if (m) {
68
- l = m[1].length
68
+ l = m[1].length;
69
69
  state.end -= l;
70
70
  state.selection = selected.substr(0, selected.length-l);
71
71
  }
@@ -74,23 +74,23 @@ Spontaneous.Field.Markdown = (function($, S) {
74
74
  expand_selection: function(state) {
75
75
  state = this.fix_selection_whitespace(state);
76
76
  var selected = state.selection, m, start = state.start, end = state.end,
77
- _pre_ = this.pre.replace(/\*/g, "\\*"), _post_ = this.post.replace(/\*/g, "\\*");
77
+ _pre_ = this.pre.replace(/\*/g, '\\*'), _post_ = this.post.replace(/\*/g, '\\*');
78
78
 
79
- m = (new RegExp('(?:^| )('+_pre_+'[^('+_pre_+')]*)$', 'm')).exec(state.before)
79
+ m = (new RegExp('(?:^| )('+_pre_+'[^('+_pre_+')]*)$', 'm')).exec(state.before);
80
80
  if (m) {
81
81
  start -= m[1].length;
82
82
  selected = m[1] + selected;
83
83
  }
84
- m = (new RegExp('^([^('+_post_+')]*?'+_post_+')[^('+_post_+')\w ]*?( |$)', '')).exec(state.after)
84
+ m = (new RegExp('^([^('+_post_+')]*?'+_post_+')[^('+_post_+')\w ]*?( |$)', '')).exec(state.after);
85
85
  if (m) {
86
86
  end += m[1].length;
87
87
  selected += m[1];
88
88
  }
89
89
  // fix condition where half of the pre/post markers are selected
90
+ var sel, i, ii;
90
91
  if ((end - start) > 0) {
91
92
  if (selected.indexOf(this.pre) !== 0) {
92
- var sel;
93
- for (var i = 0, ii = this.pre.length; i < ii; i++) {
93
+ for (i = 0, ii = this.pre.length; i < ii; i++) {
94
94
  sel = state.before.substr(-(i+1)) + selected;
95
95
  if (sel.indexOf(this.pre) === 0) {
96
96
  start -= (i+1);
@@ -100,8 +100,7 @@ Spontaneous.Field.Markdown = (function($, S) {
100
100
  }
101
101
  }
102
102
  if (selected.substr(-this.post.length) !== this.post) {
103
- var sel;
104
- for (var i = 0, ii = this.post.length; i < ii; i++) {
103
+ for (i = 0, ii = this.post.length; i < ii; i++) {
105
104
  sel = selected + state.after.substr(0, (i+1));
106
105
  if (sel.substr(-this.post.length) === this.post) {
107
106
  end += (i+1);
@@ -113,7 +112,7 @@ Spontaneous.Field.Markdown = (function($, S) {
113
112
  } else {
114
113
  // expand selection to current word if selection is empty
115
114
  var exclude = '\\s\\b\\.,';
116
- m = (new RegExp('(?:['+exclude+']|^)([^'+exclude+']+)$', '')).exec(state.before)
115
+ m = (new RegExp('(?:['+exclude+']|^)([^'+exclude+']+)$', '')).exec(state.before);
117
116
  if (m) {
118
117
  start -= m[1].length;
119
118
  selected = m[1] + selected;
@@ -129,7 +128,7 @@ Spontaneous.Field.Markdown = (function($, S) {
129
128
  fix_selection: function() {
130
129
  var state = this.get_state(), change;
131
130
  if (!this.matches_selection(state.selection)) {
132
- change = this.expand_selection(state)
131
+ change = this.expand_selection(state);
133
132
  $.extend(state, change);
134
133
  state = this.update_state(state);
135
134
  }
@@ -179,7 +178,7 @@ Spontaneous.Field.Markdown = (function($, S) {
179
178
  return this.matches_selection(selection);
180
179
  },
181
180
  matches_selection: function(selection) {
182
- return (selection.indexOf(this.pre) === 0 && selection.lastIndexOf(this.post) === (selection.length - this.post.length))
181
+ return (selection.indexOf(this.pre) === 0 && selection.lastIndexOf(this.post) === (selection.length - this.post.length));
183
182
  }
184
183
  });
185
184
 
@@ -188,8 +187,8 @@ Spontaneous.Field.Markdown = (function($, S) {
188
187
  pre: '**',
189
188
  post: '**',
190
189
  key_shortcut: function() {
191
- return "B"; // "b"
192
- },
190
+ return 'B'; // "b"
191
+ }
193
192
  });
194
193
 
195
194
  var Italic = new JS.Class(TextCommand, {
@@ -197,8 +196,8 @@ Spontaneous.Field.Markdown = (function($, S) {
197
196
  pre: '_',
198
197
  post: '_',
199
198
  key_shortcut: function() {
200
- return "I";
201
- },
199
+ return 'I';
200
+ }
202
201
  });
203
202
 
204
203
  var UL = new JS.Class(TextCommand, {
@@ -216,14 +215,14 @@ Spontaneous.Field.Markdown = (function($, S) {
216
215
  lines[i] = this.bullet_for(i) + lines[i].replace(this.strip_bullet, '');
217
216
  }
218
217
  }
219
- return lines.join("\n")
218
+ return lines.join('\n');
220
219
  },
221
220
  remove: function(text) {
222
221
  var lines = text.split(this.br);
223
222
  for (var i = 0, ii = lines.length; i < ii; i++) {
224
223
  lines[i] = lines[i].replace(this.strip_bullet, '');
225
224
  }
226
- return lines.join("\n")
225
+ return lines.join('\n');
227
226
  },
228
227
  expand_selection: function(state) {
229
228
  var selected = (state.selection || ''), m, start = state.start, end = state.end, br = /\r?\n/;
@@ -243,10 +242,10 @@ Spontaneous.Field.Markdown = (function($, S) {
243
242
  return {selection:selected, start:start, end:end};
244
243
  },
245
244
  bullet_for: function(n) {
246
- return "* ";
245
+ return '* ';
247
246
  },
248
247
  matches_selection: function(selection) {
249
- return /^ *\* +/.test(selection)
248
+ return /^ *\* +/.test(selection);
250
249
  }
251
250
 
252
251
  });
@@ -254,44 +253,44 @@ Spontaneous.Field.Markdown = (function($, S) {
254
253
  name: 'OL',
255
254
  is_list_entry:/(?:\r?\n)( *\d+\..+?)$/,
256
255
  bullet_for: function(n) {
257
- return (n+1)+". ";
256
+ return (n+1)+'. ';
258
257
  },
259
258
  matches_selection: function(selection) {
260
- return /^ *\d+\./.test(selection)
259
+ return /^ *\d+\./.test(selection);
261
260
  }
262
261
  });
263
262
 
264
263
  var H1 = new JS.Class(TextCommand, {
265
- name: "H1",
264
+ name: 'H1',
266
265
  pre: '',
267
- post: "=",
266
+ post: '=',
268
267
  scale: 1.0,
269
268
  key_shortcut: function() {
270
- return "1";
269
+ return '1';
271
270
  },
272
271
  surround: function(text) {
273
272
  // remove existing header (which must be different from this version)
274
273
  if (this.matches_removal(text)) { text = this.remove(text); }
275
274
  var line = '', n = Math.floor(this.input.attr('cols')*0.5), newline = /([\r\n]+)$/, newlines = newline.exec(text), undef;
276
- newlines = (!newlines || (newlines === undef) ? "" : newlines[1])
275
+ newlines = (!newlines || (newlines === undef) ? '' : newlines[1]);
277
276
  for (var i = 0; i < n; i++) { line += this.post; }
278
- return text.replace(newline, '') + "\n" + line + newlines;
277
+ return text.replace(newline, '') + '\n' + line + newlines;
279
278
  },
280
279
  // removes either h1 or h2
281
280
  remove: function(text) {
282
- var r = new RegExp('[\r\n][=-]+'), s = text.replace(r, '')
281
+ var r = new RegExp('[\r\n][=-]+'), s = text.replace(r, '');
283
282
  return s.replace(/ +$/, '');
284
283
  },
285
284
  // matches either h1 or h2
286
285
  matches_removal: function(selection) {
287
- return (new RegExp('[\r\n][=\\-]+[\r\n ]*$')).exec(selection)
286
+ return (new RegExp('[\r\n][=\\-]+[\r\n ]*$')).exec(selection);
288
287
  },
289
288
  // matches only the current header class
290
289
  matches_selection: function(selection) {
291
- return (new RegExp('[\r\n]?'+this.post+'+[\r\n ]*$', 'm')).exec(selection)
290
+ return (new RegExp('[\r\n]?'+this.post+'+[\r\n ]*$', 'm')).exec(selection);
292
291
  },
293
292
  expand_selection: function(state) {
294
- var selected = (state.selection || ''), m, start = state.start, end = state.end, br = /\r?\n/, below = false;
293
+ var selected = (state.selection || ''), m, s, l, start = state.start, end = state.end, br = /\r?\n/, below = false;
295
294
  // detect & deal with the cursor being on the line below
296
295
  // (the one with the -'s or ='s)
297
296
  // TODO: deal with the case where the cursor is at the start of the =- line
@@ -300,12 +299,12 @@ Spontaneous.Field.Markdown = (function($, S) {
300
299
  if (m || n) {
301
300
  m = /(?:[\n]|^)(.+[\n]+([=-]+))$/.exec(state.before);
302
301
  if (m) {
303
- var s = m[1];
302
+ s = m[1];
304
303
  start -= s.length;
305
304
  selected = s + selected;
306
305
  }
307
306
  if (n) {
308
- var s = n[1];
307
+ s = n[1];
309
308
  end += s.length;
310
309
  selected += s;
311
310
  }
@@ -316,19 +315,19 @@ Spontaneous.Field.Markdown = (function($, S) {
316
315
  // expand to select current line
317
316
  m = /(.+)$/.exec(state.before);
318
317
  if (m) {
319
- var s = m[1];
318
+ s = m[1];
320
319
  start -= s.length;
321
320
  selected = m[1] + selected;
322
321
  }
323
322
  m = /^(.+)/.exec(state.after);
324
323
  if (m) {
325
- var s = m[1];
324
+ s = m[1];
326
325
  end += s.length;
327
326
  selected += m[1];
328
327
  }
329
328
  var lines = selected.split(br), underline = new RegExp('^[=-]+$'), found = false;
330
329
  for (var i = 0, ii = lines.length; i < ii; i++) {
331
- var l = lines[i];
330
+ l = lines[i];
332
331
  if (underline.test(l)) {
333
332
  found = true;
334
333
  break;
@@ -337,8 +336,8 @@ Spontaneous.Field.Markdown = (function($, S) {
337
336
  if (!found) {
338
337
  // expand selection down by one line
339
338
  lines = state.after.split(br, 2);
340
- for (var i = 0, ii = lines.length; i < ii; i++) {
341
- var l = lines[i];
339
+ for (i = 0, ii = lines.length; i < ii; i++) {
340
+ l = lines[i];
342
341
  if (underline.test(l)) {
343
342
  end += l.length + i;
344
343
  selected += l;
@@ -347,7 +346,8 @@ Spontaneous.Field.Markdown = (function($, S) {
347
346
  }
348
347
  } else {
349
348
  // make sure that we have the whole of the underline included in the selection
350
- var r = new RegExp('^([=-]+)'), m = r.exec(state.after);
349
+ var r = new RegExp('^([=-]+)');
350
+ m = r.exec(state.after);
351
351
  if (m) {
352
352
  var extra = m[1];
353
353
  end += extra.length;
@@ -360,12 +360,12 @@ Spontaneous.Field.Markdown = (function($, S) {
360
360
  });
361
361
 
362
362
  var H2 = new JS.Class(H1, {
363
- name: "H2",
364
- post: "-",
363
+ name: 'H2',
364
+ post: '-',
365
365
  scale: 1.2, // hyphens are narrower than equals and narrower than the average char
366
366
  key_shortcut: function() {
367
- return "2";
368
- },
367
+ return '2';
368
+ }
369
369
  });
370
370
 
371
371
 
@@ -380,7 +380,7 @@ Spontaneous.Field.Markdown = (function($, S) {
380
380
  return 300;
381
381
  },
382
382
  title: function() {
383
- return "Insert Link";
383
+ return 'Insert Link';
384
384
  },
385
385
  // position_from_event: function(event) {
386
386
  // var t = $(event.currentTarget), o = t.offset();
@@ -403,23 +403,24 @@ Spontaneous.Field.Markdown = (function($, S) {
403
403
  }).val(value);
404
404
  l = dom.label().append(dom.span().text(label)).append(i);
405
405
  return l;
406
- }
407
- text_input = input("Text", this.link_text);
408
- url_input = input("URL", this.url, 'textarea');
406
+ };
407
+ text_input = input('Text', this.link_text);
408
+ url_input = input('URL', this.url, 'textarea');
409
409
  url_input.find('textarea').attr('rows', 3);
410
410
 
411
- cancel = dom.a('.button.cancel').text('Clear').click(function() {
411
+ var cancel = dom.a('.button.cancel').text('Clear').click(function() {
412
412
  // this.close();
413
413
  this.insert_link_and_close(text_input, url_input.val(''));
414
414
  return false;
415
- }.bind(this)), insert = dom.a('.button').text('OK').click(function() {
415
+ }.bind(this))
416
+ , insert = dom.a('.button').text('OK').click(function() {
416
417
  this.insert_link_and_close(text_input, url_input);
417
418
  return false;
418
- }.bind(this))
419
+ }.bind(this));
419
420
  w.append(dom.p().append(text_input)).append(dom.p().append(url_input));
420
421
  var buttons = dom.div('.buttons');
421
- url_input = url_input.find(':input')
422
- text_input = text_input.find(':input')
422
+ url_input = url_input.find(':input');
423
+ text_input = text_input.find(':input');
423
424
  this.text_input = text_input;
424
425
  this.url_input = url_input;
425
426
  this.page_browser = new PageSelector(this.url, this);
@@ -454,12 +455,12 @@ Spontaneous.Field.Markdown = (function($, S) {
454
455
  var PageSelector = new JS.Class({
455
456
  initialize: function(location, parent) {
456
457
  this.parent = parent;
457
- this.location = location
458
+ this.location = location;
458
459
  this.browser = new Spontaneous.PageBrowser(this.location);
459
460
  this.browser.set_manager(this);
460
461
  },
461
462
  view: function() {
462
- var w = dom.div();
463
+ var w = dom.div(),
463
464
  text = dom.span().text('Page Browser'),
464
465
  inner = dom.div('.link-page-browser');
465
466
  inner.append(dom.label().append(text)).append(this.browser.view());
@@ -472,7 +473,7 @@ Spontaneous.Field.Markdown = (function($, S) {
472
473
  this.parent.page_selected(page);
473
474
  },
474
475
  next_level: function(page) {
475
- this.location = page
476
+ this.location = page;
476
477
  }
477
478
  });
478
479
 
@@ -500,7 +501,7 @@ Spontaneous.Field.Markdown = (function($, S) {
500
501
  }
501
502
  },
502
503
  expand_selection: function(state) {
503
- state = this.fix_selection_whitespace(state)
504
+ state = this.fix_selection_whitespace(state);
504
505
  var selected = state.selection, m, n, start = state.start, end = state.end;
505
506
 
506
507
  var linkExp = /(\[[^\]]*?\]\([^\ ]*?\))/g;
@@ -515,10 +516,10 @@ Spontaneous.Field.Markdown = (function($, S) {
515
516
  // now we've established where the last whole link lives, and can stop ourselves
516
517
  // including it in the search, we can look backwards
517
518
  // until we find the start of any link that's around the current selection.
518
- while ((cursor >= match) && (text[cursor] !== "[")) { cursor--; }
519
+ while ((cursor >= match) && (text[cursor] !== '[')) { cursor--; }
519
520
 
520
- if (text[cursor] === "[") {
521
- if (m = linkExp.exec(text.substr(cursor))) {
521
+ if (text[cursor] === '[') {
522
+ if ((m = linkExp.exec(text.substr(cursor)))) {
522
523
  start = cursor;
523
524
  end = cursor + m[1].length;
524
525
  selected = m[1];
@@ -546,7 +547,7 @@ Spontaneous.Field.Markdown = (function($, S) {
546
547
  // need a flag saying that the string doesn't look like URL because
547
548
  // this function is used in two places and each one needs to respond
548
549
  // differently to this condition
549
- return false
550
+ return false;
550
551
  }
551
552
  }
552
553
  return url;
@@ -606,11 +607,11 @@ Spontaneous.Field.Markdown = (function($, S) {
606
607
  if (!this.expanded) {
607
608
  var input = this.input(), h = input.innerHeight();
608
609
 
609
- input.data('original-height', h)
610
+ input.data('original-height', h);
610
611
  var text_height = input[0].scrollHeight, max_height = 500, resize_height = Math.min(text_height, max_height);
611
612
  // console.log(resize_height, h)
612
613
  if (Math.abs(resize_height - h) > 20) {
613
- // input.animate({'height':resize_height});
614
+ // input.velocity({'height':resize_height});
614
615
  this.expanded = true;
615
616
  }
616
617
  }
@@ -619,7 +620,7 @@ Spontaneous.Field.Markdown = (function($, S) {
619
620
  on_blur: function() {
620
621
  if (this.expanded) {
621
622
  var input = this.input();
622
- // input.animate({ 'height':input.data('original-height') });
623
+ // input.velocity({ 'height':input.data('original-height') });
623
624
  this.expanded = false;
624
625
  }
625
626
  this.callSuper();
@@ -636,7 +637,7 @@ Spontaneous.Field.Markdown = (function($, S) {
636
637
  var self = this;
637
638
  if (!self._popupToolbar) {
638
639
  var toolbar = dom.div('.md-toolbar');
639
- var arrow = dom.div(".arrow");
640
+ var arrow = dom.div('.arrow');
640
641
  toolbar.append(arrow);
641
642
  self.commands = [];
642
643
  var input = self.input();
@@ -655,7 +656,7 @@ Spontaneous.Field.Markdown = (function($, S) {
655
656
  self.expanded = false;
656
657
  // clear previously assigned bindings
657
658
  input.unbind('select.markdown');
658
- input.bind('select.markdown', self.on_select.bind(self))
659
+ input.bind('select.markdown', self.on_select.bind(self));
659
660
  // input.bind('click.markdown', self.on_select.bind(self))
660
661
  // input.bind('keyup.markdown', self.on_select.bind(self))
661
662
  return input;
@@ -684,10 +685,10 @@ Spontaneous.Field.Markdown = (function($, S) {
684
685
  left: position.left,
685
686
  // 5 is half the height of the arrow
686
687
  // 7 is the padding of the field
687
- top: position.top + 7 - 5 - tools.height
688
+ top: position.top + 7 - 5 - tools.height
688
689
  };
689
690
  var dx = 0;
690
- var arrow = toolbar.find(".arrow"),
691
+ var arrow = toolbar.find('.arrow'),
691
692
  arrowLeft = (position.width / 2) - 5;
692
693
  // if the selection is narrow the arrow can peek over the left
693
694
  // of the toolbar. This shifts everything over and keeps it neat.
@@ -702,7 +703,7 @@ Spontaneous.Field.Markdown = (function($, S) {
702
703
  }
703
704
 
704
705
  arrowLeft = Math.min(toolbar.width() - 30, arrowLeft);
705
- arrow.css("left", dom.px(arrowLeft));
706
+ arrow.css('left', dom.px(arrowLeft));
706
707
  return place;
707
708
  });
708
709
  }
@@ -1,16 +1,16 @@
1
1
 
2
2
  Spontaneous.Field.Select = (function($, S) {
3
- "use strict";
3
+ 'use strict';
4
4
 
5
5
  var dom = S.Dom
6
- , ajax = S.Ajax;
6
+ , ajax = S.Ajax;
7
7
 
8
8
  var SelectField = new JS.Class(Spontaneous.Field.String, {
9
9
  edit: function() {
10
10
  var self = this
11
- , type = this.type
12
- , option_list = type.option_list
13
- , wrapper = dom.div(".select-field-type")
11
+ , type = this.type
12
+ , option_list = type.option_list
13
+ , wrapper = dom.div('.select-field-type')
14
14
  , callback;
15
15
  if (!option_list) {
16
16
  // dynamic, make ajax call
@@ -25,7 +25,7 @@ Spontaneous.Field.Select = (function($, S) {
25
25
  },
26
26
 
27
27
  optionsURL: function() {
28
- return ["/field/options", this.type.schema_id, this.content.id()].join("/");
28
+ return ['/field/options', this.type.schema_id, this.content.id()].join('/');
29
29
  },
30
30
 
31
31
  append_select: function(wrapper, option_list) {
@@ -35,10 +35,10 @@ Spontaneous.Field.Select = (function($, S) {
35
35
  option_list.forEach(function(val) {
36
36
  var value = val[0]
37
37
  , label = val[1]
38
- , option = dom.option({"value": value}).text(label);
38
+ , option = dom.option({'value': value}).text(label);
39
39
  options[value] = label;
40
40
  if (value == selected) { // only == so that strings successfully match ints
41
- option.attr("selected", "selected");
41
+ option.attr('selected', 'selected');
42
42
  }
43
43
  select.append(option);
44
44
  });
@@ -52,7 +52,7 @@ Spontaneous.Field.Select = (function($, S) {
52
52
  },
53
53
 
54
54
  parsedValue: function() {
55
- var value = this.get("value")
55
+ var value = this.get('value');
56
56
  if (!value) { return []; }
57
57
  return JSON.parse(this.get('value'));
58
58
  },