rails_markitup 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/Gemfile +4 -0
  2. data/README.markdown +50 -0
  3. data/Rakefile +1 -0
  4. data/app/helpers/rails_markitup/markitup_helper.rb +14 -0
  5. data/lib/generators/rails_markitup/install_generator.rb +29 -0
  6. data/lib/generators/rails_markitup/media/images/bg-container.png +0 -0
  7. data/lib/generators/rails_markitup/media/images/bg-editor-bbcode.png +0 -0
  8. data/lib/generators/rails_markitup/media/images/bg-editor-dotclear.png +0 -0
  9. data/lib/generators/rails_markitup/media/images/bg-editor-html.png +0 -0
  10. data/lib/generators/rails_markitup/media/images/bg-editor-json.png +0 -0
  11. data/lib/generators/rails_markitup/media/images/bg-editor-markdown.png +0 -0
  12. data/lib/generators/rails_markitup/media/images/bg-editor-textile.png +0 -0
  13. data/lib/generators/rails_markitup/media/images/bg-editor-wiki.png +0 -0
  14. data/lib/generators/rails_markitup/media/images/bg-editor-xml.png +0 -0
  15. data/lib/generators/rails_markitup/media/images/bg-editor.png +0 -0
  16. data/lib/generators/rails_markitup/media/images/bold.png +0 -0
  17. data/lib/generators/rails_markitup/media/images/clean.png +0 -0
  18. data/lib/generators/rails_markitup/media/images/code.png +0 -0
  19. data/lib/generators/rails_markitup/media/images/h1.png +0 -0
  20. data/lib/generators/rails_markitup/media/images/h2.png +0 -0
  21. data/lib/generators/rails_markitup/media/images/h3.png +0 -0
  22. data/lib/generators/rails_markitup/media/images/h4.png +0 -0
  23. data/lib/generators/rails_markitup/media/images/h5.png +0 -0
  24. data/lib/generators/rails_markitup/media/images/h6.png +0 -0
  25. data/lib/generators/rails_markitup/media/images/handle.png +0 -0
  26. data/lib/generators/rails_markitup/media/images/image.png +0 -0
  27. data/lib/generators/rails_markitup/media/images/italic.png +0 -0
  28. data/lib/generators/rails_markitup/media/images/link.png +0 -0
  29. data/lib/generators/rails_markitup/media/images/list-bullet.png +0 -0
  30. data/lib/generators/rails_markitup/media/images/list-numeric.png +0 -0
  31. data/lib/generators/rails_markitup/media/images/menu.png +0 -0
  32. data/lib/generators/rails_markitup/media/images/picture.png +0 -0
  33. data/lib/generators/rails_markitup/media/images/preview.png +0 -0
  34. data/lib/generators/rails_markitup/media/images/quotes.png +0 -0
  35. data/lib/generators/rails_markitup/media/images/stroke.png +0 -0
  36. data/lib/generators/rails_markitup/media/images/submenu.png +0 -0
  37. data/lib/generators/rails_markitup/media/javascripts/jquery.markitup.js +574 -0
  38. data/lib/generators/rails_markitup/media/javascripts/sets/markdown/set.js +47 -0
  39. data/lib/generators/rails_markitup/media/stylesheets/sets/markdown/style.css +54 -0
  40. data/lib/generators/rails_markitup/media/stylesheets/skins/markitup/style.css +147 -0
  41. data/lib/rails_markitup/engine.rb +21 -0
  42. data/lib/rails_markitup/version.rb +3 -0
  43. data/lib/rails_markitup.rb +7 -0
  44. metadata +195 -0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rails_markitup.gemspec
4
+ gemspec
data/README.markdown ADDED
@@ -0,0 +1,50 @@
1
+ A MarkDown TextEditor with jQuery and Markitup! and redcarpet for Rails 3
2
+ =========================================================================
3
+
4
+ __use: [Markitup](http://markitup.jaysalvat.com/ "Markitup")__
5
+
6
+ __[Demo](http://markitup.jaysalvat.com/downloads/demo.php?id=markupsets/markdown)__
7
+
8
+ Support Env:
9
+ ------------
10
+ Rails3.0.8+/Ruby1.8.7+
11
+
12
+ Usage:
13
+ ------
14
+
15
+ 1. **In you Gemfile:**
16
+
17
+ >gem "redcarpet"
18
+
19
+ >gem "albino"
20
+
21
+ >gem "nokogiri"
22
+
23
+ >gem 'rails_markitup'
24
+
25
+ 2. run :
26
+
27
+ > rails g rails_markitup:install
28
+
29
+ 3. in layout:
30
+
31
+ > = stylesheet_link_tag :markitup
32
+
33
+ > = javascript_include_tag :markitup
34
+
35
+ 4. in your textarea , simple\_form\_for exapmle:
36
+
37
+ > = form.input :content, :as => :text, :input_html => {:id => 'markdown'}
38
+
39
+ 5. in your application.js:
40
+
41
+ >$(document).ready(function(){
42
+ >
43
+ > $('#markdown').markItUp(myMarkdownSettings);
44
+ >
45
+ >});
46
+
47
+ 5. in your show page:
48
+
49
+ > = markdown(@topic.content)
50
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,14 @@
1
+ module MarkitupHelper
2
+ def markdown(text)
3
+ options = [:hard_wrap, :filter_html, :autolink, :no_intraemphasis, :fenced_code, :gh_blockcode]
4
+ syntax_highlighter(Redcarpet.new(text, *options).to_html).html_safe
5
+ end
6
+
7
+ def syntax_highlighter(html)
8
+ doc = Nokogiri::HTML(html)
9
+ doc.search("//pre[@lang]").each do |pre|
10
+ pre.replace Albino.colorize(pre.text.rstrip, pre[:lang])
11
+ end
12
+ doc.to_s
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ require 'rake'
2
+ require 'rails/generators'
3
+
4
+ # ==================================
5
+ # = rails g rails_markitup:install =
6
+ # ==================================
7
+
8
+ module RailsMarkitup
9
+ module Generators
10
+
11
+ class InstallGenerator < Rails::Generators::Base
12
+
13
+ source_root File.expand_path('../media', __FILE__)
14
+ desc "Copies media files to main project"
15
+ def copy_media_files
16
+ path = File.expand_path('../media', __FILE__)
17
+ @images = FileList["#{path}/images/*"]
18
+ @images.each do |image|
19
+ copy_file "#{image}", "public/stylesheets/markitup/image/#{image.split('/').last}"
20
+ end
21
+ copy_file "../media/javascripts/jquery.markitup.js", "public/javascripts/markitup/jquery.markitup.js"
22
+ copy_file "../media/javascripts/sets/markdown/set.js", "public/javascripts/markitup/sets/markdown/set.js"
23
+ copy_file "../media/stylesheets/sets/markdown/style.css", "public/stylesheets/markitup/sets/markdown/style.css"
24
+ copy_file "../media/stylesheets/skins/markitup/style.css", "public/stylesheets/markitup/skins/markdown/style.css"
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,574 @@
1
+ // ----------------------------------------------------------------------------
2
+ // markItUp! Universal MarkUp Engine, JQuery plugin
3
+ // v 1.1.x
4
+ // Dual licensed under the MIT and GPL licenses.
5
+ // ----------------------------------------------------------------------------
6
+ // Copyright (C) 2007-2010 Jay Salvat
7
+ // http://markitup.jaysalvat.com/
8
+ // ----------------------------------------------------------------------------
9
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ // of this software and associated documentation files (the "Software"), to deal
11
+ // in the Software without restriction, including without limitation the rights
12
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ // copies of the Software, and to permit persons to whom the Software is
14
+ // furnished to do so, subject to the following conditions:
15
+ //
16
+ // The above copyright notice and this permission notice shall be included in
17
+ // all copies or substantial portions of the Software.
18
+ //
19
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ // THE SOFTWARE.
26
+ // ----------------------------------------------------------------------------
27
+ (function($) {
28
+ $.fn.markItUp = function(settings, extraSettings) {
29
+ var options, ctrlKey, shiftKey, altKey;
30
+ ctrlKey = shiftKey = altKey = false;
31
+
32
+ options = { id: '',
33
+ nameSpace: '',
34
+ root: '',
35
+ previewInWindow: '', // 'width=800, height=600, resizable=yes, scrollbars=yes'
36
+ previewAutoRefresh: true,
37
+ previewPosition: 'after',
38
+ previewTemplatePath: '~/templates/preview.html',
39
+ previewParserPath: '',
40
+ previewParserVar: 'data',
41
+ resizeHandle: true,
42
+ beforeInsert: '',
43
+ afterInsert: '',
44
+ onEnter: {},
45
+ onShiftEnter: {},
46
+ onCtrlEnter: {},
47
+ onTab: {},
48
+ markupSet: [ { /* set */ } ]
49
+ };
50
+ $.extend(options, settings, extraSettings);
51
+
52
+ // compute markItUp! path
53
+ if (!options.root) {
54
+ $('script').each(function(a, tag) {
55
+ miuScript = $(tag).get(0).src.match(/(.*)jquery\.markitup(\.pack)?\.js$/);
56
+ if (miuScript !== null) {
57
+ options.root = miuScript[1];
58
+ }
59
+ });
60
+ }
61
+
62
+ return this.each(function() {
63
+ var $$, textarea, levels, scrollPosition, caretPosition, caretOffset,
64
+ clicked, hash, header, footer, previewWindow, template, iFrame, abort;
65
+ $$ = $(this);
66
+ textarea = this;
67
+ levels = [];
68
+ abort = false;
69
+ scrollPosition = caretPosition = 0;
70
+ caretOffset = -1;
71
+
72
+ options.previewParserPath = localize(options.previewParserPath);
73
+ options.previewTemplatePath = localize(options.previewTemplatePath);
74
+
75
+ // apply the computed path to ~/
76
+ function localize(data, inText) {
77
+ if (inText) {
78
+ return data.replace(/("|')~\//g, "$1"+options.root);
79
+ }
80
+ return data.replace(/^~\//, options.root);
81
+ }
82
+
83
+ // init and build editor
84
+ function init() {
85
+ id = ''; nameSpace = '';
86
+ if (options.id) {
87
+ id = 'id="'+options.id+'"';
88
+ } else if ($$.attr("id")) {
89
+ id = 'id="markItUp'+($$.attr("id").substr(0, 1).toUpperCase())+($$.attr("id").substr(1))+'"';
90
+
91
+ }
92
+ if (options.nameSpace) {
93
+ nameSpace = 'class="'+options.nameSpace+'"';
94
+ }
95
+ $$.wrap('<div '+nameSpace+'></div>');
96
+ $$.wrap('<div '+id+' class="markItUp"></div>');
97
+ $$.wrap('<div class="markItUpContainer"></div>');
98
+ $$.addClass("markItUpEditor");
99
+
100
+ // add the header before the textarea
101
+ header = $('<div class="markItUpHeader"></div>').insertBefore($$);
102
+ $(dropMenus(options.markupSet)).appendTo(header);
103
+
104
+ // add the footer after the textarea
105
+ footer = $('<div class="markItUpFooter"></div>').insertAfter($$);
106
+
107
+ // add the resize handle after textarea
108
+ if (options.resizeHandle === true && $.browser.safari !== true) {
109
+ resizeHandle = $('<div class="markItUpResizeHandle"></div>')
110
+ .insertAfter($$)
111
+ .bind("mousedown", function(e) {
112
+ var h = $$.height(), y = e.clientY, mouseMove, mouseUp;
113
+ mouseMove = function(e) {
114
+ $$.css("height", Math.max(20, e.clientY+h-y)+"px");
115
+ return false;
116
+ };
117
+ mouseUp = function(e) {
118
+ $("html").unbind("mousemove", mouseMove).unbind("mouseup", mouseUp);
119
+ return false;
120
+ };
121
+ $("html").bind("mousemove", mouseMove).bind("mouseup", mouseUp);
122
+ });
123
+ footer.append(resizeHandle);
124
+ }
125
+
126
+ // listen key events
127
+ $$.keydown(keyPressed).keyup(keyPressed);
128
+
129
+ // bind an event to catch external calls
130
+ $$.bind("insertion", function(e, settings) {
131
+ if (settings.target !== false) {
132
+ get();
133
+ }
134
+ if (textarea === $.markItUp.focused) {
135
+ markup(settings);
136
+ }
137
+ });
138
+
139
+ // remember the last focus
140
+ $$.focus(function() {
141
+ $.markItUp.focused = this;
142
+ });
143
+ }
144
+
145
+ // recursively build header with dropMenus from markupset
146
+ function dropMenus(markupSet) {
147
+ var ul = $('<ul></ul>'), i = 0;
148
+ $('li:hover > ul', ul).css('display', 'block');
149
+ $.each(markupSet, function() {
150
+ var button = this, t = '', title, li, j;
151
+ title = (button.key) ? (button.name||'')+' [Ctrl+'+button.key+']' : (button.name||'');
152
+ key = (button.key) ? 'accesskey="'+button.key+'"' : '';
153
+ if (button.separator) {
154
+ li = $('<li class="markItUpSeparator">'+(button.separator||'')+'</li>').appendTo(ul);
155
+ } else {
156
+ i++;
157
+ for (j = levels.length -1; j >= 0; j--) {
158
+ t += levels[j]+"-";
159
+ }
160
+ li = $('<li class="markItUpButton markItUpButton'+t+(i)+' '+(button.className||'')+'"><a href="" '+key+' title="'+title+'">'+(button.name||'')+'</a></li>')
161
+ .bind("contextmenu", function() { // prevent contextmenu on mac and allow ctrl+click
162
+ return false;
163
+ }).click(function() {
164
+ return false;
165
+ }).bind("focusin", function(){
166
+ $$.focus();
167
+ }).mousedown(function() {
168
+ if (button.call) {
169
+ eval(button.call)();
170
+ }
171
+ setTimeout(function() { markup(button) },1);
172
+ return false;
173
+ }).hover(function() {
174
+ $('> ul', this).show();
175
+ $(document).one('click', function() { // close dropmenu if click outside
176
+ $('ul ul', header).hide();
177
+ }
178
+ );
179
+ }, function() {
180
+ $('> ul', this).hide();
181
+ }
182
+ ).appendTo(ul);
183
+ if (button.dropMenu) {
184
+ levels.push(i);
185
+ $(li).addClass('markItUpDropMenu').append(dropMenus(button.dropMenu));
186
+ }
187
+ }
188
+ });
189
+ levels.pop();
190
+ return ul;
191
+ }
192
+
193
+ // markItUp! markups
194
+ function magicMarkups(string) {
195
+ if (string) {
196
+ string = string.toString();
197
+ string = string.replace(/\(\!\(([\s\S]*?)\)\!\)/g,
198
+ function(x, a) {
199
+ var b = a.split('|!|');
200
+ if (altKey === true) {
201
+ return (b[1] !== undefined) ? b[1] : b[0];
202
+ } else {
203
+ return (b[1] === undefined) ? "" : b[0];
204
+ }
205
+ }
206
+ );
207
+ // [![prompt]!], [![prompt:!:value]!]
208
+ string = string.replace(/\[\!\[([\s\S]*?)\]\!\]/g,
209
+ function(x, a) {
210
+ var b = a.split(':!:');
211
+ if (abort === true) {
212
+ return false;
213
+ }
214
+ value = prompt(b[0], (b[1]) ? b[1] : '');
215
+ if (value === null) {
216
+ abort = true;
217
+ }
218
+ return value;
219
+ }
220
+ );
221
+ return string;
222
+ }
223
+ return "";
224
+ }
225
+
226
+ // prepare action
227
+ function prepare(action) {
228
+ if ($.isFunction(action)) {
229
+ action = action(hash);
230
+ }
231
+ return magicMarkups(action);
232
+ }
233
+
234
+ // build block to insert
235
+ function build(string) {
236
+ var openWith = prepare(clicked.openWith);
237
+ var placeHolder = prepare(clicked.placeHolder);
238
+ var replaceWith = prepare(clicked.replaceWith);
239
+ var closeWith = prepare(clicked.closeWith);
240
+ if (replaceWith !== "") {
241
+ block = openWith + replaceWith + closeWith;
242
+ } else if (selection === '' && placeHolder !== '') {
243
+ block = openWith + placeHolder + closeWith;
244
+ } else {
245
+ string = string || selection;
246
+ if (string.match(/ $/)) {
247
+ block = openWith + string.replace(/ $/, '') + closeWith + ' ';
248
+ } else {
249
+ block = openWith + string + closeWith;
250
+ }
251
+ }
252
+ return { block:block,
253
+ openWith:openWith,
254
+ replaceWith:replaceWith,
255
+ placeHolder:placeHolder,
256
+ closeWith:closeWith
257
+ };
258
+ }
259
+
260
+ // define markup to insert
261
+ function markup(button) {
262
+ var len, j, n, i;
263
+ hash = clicked = button;
264
+ get();
265
+
266
+ $.extend(hash, { line:"",
267
+ root:options.root,
268
+ textarea:textarea,
269
+ selection:(selection||''),
270
+ caretPosition:caretPosition,
271
+ ctrlKey:ctrlKey,
272
+ shiftKey:shiftKey,
273
+ altKey:altKey
274
+ }
275
+ );
276
+ // callbacks before insertion
277
+ prepare(options.beforeInsert);
278
+ prepare(clicked.beforeInsert);
279
+ if (ctrlKey === true && shiftKey === true) {
280
+ prepare(clicked.beforeMultiInsert);
281
+ }
282
+ $.extend(hash, { line:1 });
283
+
284
+ if (ctrlKey === true && shiftKey === true) {
285
+ lines = selection.split(/\r?\n/);
286
+ for (j = 0, n = lines.length, i = 0; i < n; i++) {
287
+ if ($.trim(lines[i]) !== '') {
288
+ $.extend(hash, { line:++j, selection:lines[i] } );
289
+ lines[i] = build(lines[i]).block;
290
+ } else {
291
+ lines[i] = "";
292
+ }
293
+ }
294
+ string = { block:lines.join('\n')};
295
+ start = caretPosition;
296
+ len = string.block.length + (($.browser.opera) ? n-1 : 0);
297
+ } else if (ctrlKey === true) {
298
+ string = build(selection);
299
+ start = caretPosition + string.openWith.length;
300
+ len = string.block.length - string.openWith.length - string.closeWith.length;
301
+ len = len - (string.block.match(/ $/) ? 1 : 0);
302
+ len -= fixIeBug(string.block);
303
+ } else if (shiftKey === true) {
304
+ string = build(selection);
305
+ start = caretPosition;
306
+ len = string.block.length;
307
+ len -= fixIeBug(string.block);
308
+ } else {
309
+ string = build(selection);
310
+ start = caretPosition + string.block.length ;
311
+ len = 0;
312
+ start -= fixIeBug(string.block);
313
+ }
314
+ if ((selection === '' && string.replaceWith === '')) {
315
+ caretOffset += fixOperaBug(string.block);
316
+
317
+ start = caretPosition + string.openWith.length;
318
+ len = string.block.length - string.openWith.length - string.closeWith.length;
319
+
320
+ caretOffset = $$.val().substring(caretPosition, $$.val().length).length;
321
+ caretOffset -= fixOperaBug($$.val().substring(0, caretPosition));
322
+ }
323
+ $.extend(hash, { caretPosition:caretPosition, scrollPosition:scrollPosition } );
324
+
325
+ if (string.block !== selection && abort === false) {
326
+ insert(string.block);
327
+ set(start, len);
328
+ } else {
329
+ caretOffset = -1;
330
+ }
331
+ get();
332
+
333
+ $.extend(hash, { line:'', selection:selection });
334
+
335
+ // callbacks after insertion
336
+ if (ctrlKey === true && shiftKey === true) {
337
+ prepare(clicked.afterMultiInsert);
338
+ }
339
+ prepare(clicked.afterInsert);
340
+ prepare(options.afterInsert);
341
+
342
+ // refresh preview if opened
343
+ if (previewWindow && options.previewAutoRefresh) {
344
+ refreshPreview();
345
+ }
346
+
347
+ // reinit keyevent
348
+ shiftKey = altKey = ctrlKey = abort = false;
349
+ }
350
+
351
+ // Substract linefeed in Opera
352
+ function fixOperaBug(string) {
353
+ if ($.browser.opera) {
354
+ return string.length - string.replace(/\n*/g, '').length;
355
+ }
356
+ return 0;
357
+ }
358
+ // Substract linefeed in IE
359
+ function fixIeBug(string) {
360
+ if ($.browser.msie) {
361
+ return string.length - string.replace(/\r/g, '').length;
362
+ }
363
+ return 0;
364
+ }
365
+
366
+ // add markup
367
+ function insert(block) {
368
+ if (document.selection) {
369
+ var newSelection = document.selection.createRange();
370
+ newSelection.text = block;
371
+ } else {
372
+ textarea.value = textarea.value.substring(0, caretPosition) + block + textarea.value.substring(caretPosition + selection.length, textarea.value.length);
373
+ }
374
+ }
375
+
376
+ // set a selection
377
+ function set(start, len) {
378
+ if (textarea.createTextRange){
379
+ // quick fix to make it work on Opera 9.5
380
+ if ($.browser.opera && $.browser.version >= 9.5 && len == 0) {
381
+ return false;
382
+ }
383
+ range = textarea.createTextRange();
384
+ range.collapse(true);
385
+ range.moveStart('character', start);
386
+ range.moveEnd('character', len);
387
+ range.select();
388
+ } else if (textarea.setSelectionRange ){
389
+ textarea.setSelectionRange(start, start + len);
390
+ }
391
+ textarea.scrollTop = scrollPosition;
392
+ textarea.focus();
393
+ }
394
+
395
+ // get the selection
396
+ function get() {
397
+ textarea.focus();
398
+
399
+ scrollPosition = textarea.scrollTop;
400
+ if (document.selection) {
401
+ selection = document.selection;
402
+ if ($.browser.msie) { // ie
403
+ var range = selection.createRange();
404
+ var stored_range = range.duplicate();
405
+ stored_range.moveToElementText(textarea);
406
+ stored_range.setEndPoint('EndToEnd', range);
407
+ var s = stored_range.text.length - range.text.length;
408
+
409
+ caretPosition = s - (textarea.value.substr(0, s).length - textarea.value.substr(0, s).replace(/\r/g, '').length);
410
+ selection = range.text;
411
+ } else { // opera
412
+ caretPosition = textarea.selectionStart;
413
+ }
414
+ } else { // gecko & webkit
415
+ caretPosition = textarea.selectionStart;
416
+ selection = textarea.value.substring(caretPosition, textarea.selectionEnd);
417
+ }
418
+ return selection;
419
+ }
420
+
421
+ // open preview window
422
+ function preview() {
423
+ if (!previewWindow || previewWindow.closed) {
424
+ if (options.previewInWindow) {
425
+ previewWindow = window.open('', 'preview', options.previewInWindow);
426
+ $(window).unload(function() {
427
+ previewWindow.close();
428
+ });
429
+ } else {
430
+ iFrame = $('<iframe class="markItUpPreviewFrame"></iframe>');
431
+ if (options.previewPosition == 'after') {
432
+ iFrame.insertAfter(footer);
433
+ } else {
434
+ iFrame.insertBefore(header);
435
+ }
436
+ previewWindow = iFrame[iFrame.length - 1].contentWindow || frame[iFrame.length - 1];
437
+ }
438
+ } else if (altKey === true) {
439
+ if (iFrame) {
440
+ iFrame.remove();
441
+ } else {
442
+ previewWindow.close();
443
+ }
444
+ previewWindow = iFrame = false;
445
+ }
446
+ if (!options.previewAutoRefresh) {
447
+ refreshPreview();
448
+ }
449
+ if (options.previewInWindow) {
450
+ previewWindow.focus();
451
+ }
452
+ }
453
+
454
+ // refresh Preview window
455
+ function refreshPreview() {
456
+ renderPreview();
457
+ }
458
+
459
+ function renderPreview() {
460
+ var phtml;
461
+ if (options.previewParserPath !== '') {
462
+ $.ajax({
463
+ type: 'POST',
464
+ dataType: 'text',
465
+ global: false,
466
+ url: options.previewParserPath,
467
+ data: options.previewParserVar+'='+encodeURIComponent($$.val()),
468
+ success: function(data) {
469
+ writeInPreview( localize(data, 1) );
470
+ }
471
+ });
472
+ } else {
473
+ if (!template) {
474
+ $.ajax({
475
+ url: options.previewTemplatePath,
476
+ dataType: 'text',
477
+ global: false,
478
+ success: function(data) {
479
+ writeInPreview( localize(data, 1).replace(/<!-- content -->/g, $$.val()) );
480
+ }
481
+ });
482
+ }
483
+ }
484
+ return false;
485
+ }
486
+
487
+ function writeInPreview(data) {
488
+ if (previewWindow.document) {
489
+ try {
490
+ sp = previewWindow.document.documentElement.scrollTop
491
+ } catch(e) {
492
+ sp = 0;
493
+ }
494
+ previewWindow.document.open();
495
+ previewWindow.document.write(data);
496
+ previewWindow.document.close();
497
+ previewWindow.document.documentElement.scrollTop = sp;
498
+ }
499
+ }
500
+
501
+ // set keys pressed
502
+ function keyPressed(e) {
503
+ shiftKey = e.shiftKey;
504
+ altKey = e.altKey;
505
+ ctrlKey = (!(e.altKey && e.ctrlKey)) ? e.ctrlKey : false;
506
+
507
+ if (e.type === 'keydown') {
508
+ if (ctrlKey === true) {
509
+ li = $("a[accesskey="+String.fromCharCode(e.keyCode)+"]", header).parent('li');
510
+ if (li.length !== 0) {
511
+ ctrlKey = false;
512
+ setTimeout(function() {
513
+ li.triggerHandler('mousedown');
514
+ },1);
515
+ return false;
516
+ }
517
+ }
518
+ if (e.keyCode === 13 || e.keyCode === 10) { // Enter key
519
+ if (ctrlKey === true) { // Enter + Ctrl
520
+ ctrlKey = false;
521
+ markup(options.onCtrlEnter);
522
+ return options.onCtrlEnter.keepDefault;
523
+ } else if (shiftKey === true) { // Enter + Shift
524
+ shiftKey = false;
525
+ markup(options.onShiftEnter);
526
+ return options.onShiftEnter.keepDefault;
527
+ } else { // only Enter
528
+ markup(options.onEnter);
529
+ return options.onEnter.keepDefault;
530
+ }
531
+ }
532
+ if (e.keyCode === 9) { // Tab key
533
+ if (shiftKey == true || ctrlKey == true || altKey == true) {
534
+ return false;
535
+ }
536
+ if (caretOffset !== -1) {
537
+ get();
538
+ caretOffset = $$.val().length - caretOffset;
539
+ set(caretOffset, 0);
540
+ caretOffset = -1;
541
+ return false;
542
+ } else {
543
+ markup(options.onTab);
544
+ return options.onTab.keepDefault;
545
+ }
546
+ }
547
+ }
548
+ }
549
+
550
+ init();
551
+ });
552
+ };
553
+
554
+ $.fn.markItUpRemove = function() {
555
+ return this.each(function() {
556
+ var $$ = $(this).unbind().removeClass('markItUpEditor');
557
+ $$.parent('div').parent('div.markItUp').parent('div').replaceWith($$);
558
+ }
559
+ );
560
+ };
561
+
562
+ $.markItUp = function(settings) {
563
+ var options = { target:false };
564
+ $.extend(options, settings);
565
+ if (options.target) {
566
+ return $(options.target).each(function() {
567
+ $(this).focus();
568
+ $(this).trigger('insertion', [options]);
569
+ });
570
+ } else {
571
+ $('textarea').trigger('insertion', [options]);
572
+ }
573
+ };
574
+ })(jQuery);
@@ -0,0 +1,47 @@
1
+ // ----------------------------------------------------------------------------
2
+ // markItUp!
3
+ // ----------------------------------------------------------------------------
4
+ // Copyright (C) 2008 Jay Salvat
5
+ // http://markitup.jaysalvat.com/
6
+ // ----------------------------------------------------------------------------
7
+ myMarkdownSettings = {
8
+ nameSpace: 'markdown', // Useful to prevent multi-instances CSS conflict
9
+ previewParserPath: '~/sets/markdown/preview.php',
10
+ onShiftEnter: {keepDefault:false, openWith:'\n\n'},
11
+ markupSet: [
12
+ {name:'First Level Heading', key:"1", placeHolder:'Your title here...', closeWith:function(markItUp) { return miu.markdownTitle(markItUp, '=') } },
13
+ {name:'Second Level Heading', key:"2", placeHolder:'Your title here...', closeWith:function(markItUp) { return miu.markdownTitle(markItUp, '-') } },
14
+ {name:'Heading 3', key:"3", openWith:'### ', placeHolder:'Your title here...' },
15
+ {name:'Heading 4', key:"4", openWith:'#### ', placeHolder:'Your title here...' },
16
+ {name:'Heading 5', key:"5", openWith:'##### ', placeHolder:'Your title here...' },
17
+ {name:'Heading 6', key:"6", openWith:'###### ', placeHolder:'Your title here...' },
18
+ {separator:'---------------' },
19
+ {name:'Bold', key:"B", openWith:'**', closeWith:'**'},
20
+ {name:'Italic', key:"I", openWith:'_', closeWith:'_'},
21
+ {separator:'---------------' },
22
+ {name:'Bulleted List', openWith:'- ' },
23
+ {name:'Numeric List', openWith:function(markItUp) {
24
+ return markItUp.line+'. ';
25
+ }},
26
+ {separator:'---------------' },
27
+ {name:'Picture', key:"P", replaceWith:'![[![Alternative text]!]]([![Url:!:http://]!] "[![Title]!]")'},
28
+ {name:'Link', key:"L", openWith:'[', closeWith:']([![Url:!:http://]!] "[![Title]!]")', placeHolder:'Your text to link here...' },
29
+ {separator:'---------------'},
30
+ {name:'Quotes', openWith:'> '},
31
+ {name:'Code Block / Code', openWith:'(!(\t|!|`)!)', closeWith:'(!(`)!)'},
32
+ {separator:'---------------'},
33
+ {name:'Preview', call:'preview', className:"preview"}
34
+ ]
35
+ }
36
+
37
+ // mIu nameSpace to avoid conflict.
38
+ miu = {
39
+ markdownTitle: function(markItUp, char) {
40
+ heading = '';
41
+ n = $.trim(markItUp.selection||markItUp.placeHolder).length;
42
+ for(i = 0; i < n; i++) {
43
+ heading += char;
44
+ }
45
+ return '\n'+heading+'\n';
46
+ }
47
+ }
@@ -0,0 +1,54 @@
1
+ /* -------------------------------------------------------------------
2
+ // markItUp!
3
+ // By Jay Salvat - http://markitup.jaysalvat.com/
4
+ // ------------------------------------------------------------------*/
5
+ .markItUp .markItUpButton1 a {
6
+ background-image:url(../../image/h1.png);
7
+ }
8
+ .markItUp .markItUpButton2 a {
9
+ background-image:url(../../image/h2.png);
10
+ }
11
+ .markItUp .markItUpButton3 a {
12
+ background-image:url(../../image/h3.png);
13
+ }
14
+ .markItUp .markItUpButton4 a {
15
+ background-image:url(../../image/h4.png);
16
+ }
17
+ .markItUp .markItUpButton5 a {
18
+ background-image:url(../../image/h5.png);
19
+ }
20
+ .markItUp .markItUpButton6 a {
21
+ background-image:url(../../image/h6.png);
22
+ }
23
+
24
+ .markItUp .markItUpButton7 a {
25
+ background-image:url(../../image/bold.png);
26
+ }
27
+ .markItUp .markItUpButton8 a {
28
+ background-image:url(../../image/italic.png);
29
+ }
30
+
31
+ .markItUp .markItUpButton9 a {
32
+ background-image:url(../../image/list-bullet.png);
33
+ }
34
+ .markItUp .markItUpButton10 a {
35
+ background-image:url(../../image/list-numeric.png);
36
+ }
37
+
38
+ .markItUp .markItUpButton11 a {
39
+ background-image:url(../../image/picture.png);
40
+ }
41
+ .markItUp .markItUpButton12 a {
42
+ background-image:url(../../image/link.png);
43
+ }
44
+
45
+ .markItUp .markItUpButton13 a {
46
+ background-image:url(../../image/quotes.png);
47
+ }
48
+ .markItUp .markItUpButton14 a {
49
+ background-image:url(../../image/code.png);
50
+ }
51
+
52
+ .markItUp .preview a {
53
+ background-image:url(../../image/preview.png);
54
+ }
@@ -0,0 +1,147 @@
1
+ /* -------------------------------------------------------------------
2
+ // markItUp! Universal MarkUp Engine, JQuery plugin
3
+ // By Jay Salvat - http://markitup.jaysalvat.com/
4
+ // ------------------------------------------------------------------*/
5
+ .markItUp * {
6
+ margin:0px; padding:0px;
7
+ outline:none;
8
+ }
9
+ .markItUp a:link,
10
+ .markItUp a:visited {
11
+ color:#000;
12
+ text-decoration:none;
13
+ }
14
+ .markItUp {
15
+ width:700px;
16
+ margin:5px 0 5px 0;
17
+ border:5px solid #F5F5F5;
18
+ }
19
+ .markItUpContainer {
20
+ border:1px solid #3C769D;
21
+ background:#FFF url(../../image/bg-container.png) repeat-x top left;
22
+ padding:5px 5px 2px 5px;
23
+ font:11px Verdana, Arial, Helvetica, sans-serif;
24
+ }
25
+ .markItUpEditor {
26
+ font:12px 'Courier New', Courier, monospace;
27
+ padding:5px 5px 5px 35px;
28
+ border:3px solid #3C769D;
29
+ width:643px;
30
+ height:320px;
31
+ background:#FFF url(../../image/bg-editor.png) no-repeat;
32
+ clear:both;
33
+ line-height:18px;
34
+ overflow:auto;
35
+ }
36
+ .markItUpPreviewFrame {
37
+ overflow:auto;
38
+ background-color:#FFFFFF;
39
+ border:1px solid #3C769D;
40
+ width:99.9%;
41
+ height:300px;
42
+ margin:5px 0;
43
+ }
44
+ .markItUpFooter {
45
+ width:100%;
46
+ cursor:n-resize;
47
+ }
48
+ .markItUpResizeHandle {
49
+ overflow:hidden;
50
+ width:22px; height:5px;
51
+ margin-left:auto;
52
+ margin-right:auto;
53
+ background-image:url(../../image/handle.png);
54
+ cursor:n-resize;
55
+ }
56
+ /***************************************************************************************/
57
+ /* first row of buttons */
58
+ .markItUpHeader ul li {
59
+ list-style:none;
60
+ float:left;
61
+ position:relative;
62
+ }
63
+ .markItUpHeader ul li ul{
64
+ display:none;
65
+ }
66
+ .markItUpHeader ul li:hover > ul{
67
+ display:block;
68
+ }
69
+ .markItUpHeader ul .markItUpDropMenu {
70
+ background:transparent url(../../image/menu.png) no-repeat 115% 50%;
71
+ margin-right:5px;
72
+ }
73
+ .markItUpHeader ul .markItUpDropMenu li {
74
+ margin-right:0px;
75
+ }
76
+ .markItUpHeader ul .markItUpSeparator {
77
+ margin:0 10px;
78
+ width:1px;
79
+ height:16px;
80
+ overflow:hidden;
81
+ background-color:#CCC;
82
+ }
83
+ .markItUpHeader ul ul .markItUpSeparator {
84
+ width:auto; height:1px;
85
+ margin:0px;
86
+ }
87
+ /* next rows of buttons */
88
+ .markItUpHeader ul ul {
89
+ display:none;
90
+ position:absolute;
91
+ top:18px; left:0px;
92
+ background:#F5F5F5;
93
+ border:1px solid #3C769D;
94
+ height:inherit;
95
+ }
96
+ .markItUpHeader ul ul li {
97
+ float:none;
98
+ border-bottom:1px solid #3C769D;
99
+ }
100
+ .markItUpHeader ul ul .markItUpDropMenu {
101
+ background:#F5F5F5 url(../../image/submenu.png) no-repeat 100% 50%;
102
+ }
103
+ /* next rows of buttons */
104
+ .markItUpHeader ul ul ul {
105
+ position:absolute;
106
+ top:-1px; left:150px;
107
+ }
108
+ .markItUpHeader ul ul ul li {
109
+ float:none;
110
+ }
111
+ .markItUpHeader ul a {
112
+ display:block;
113
+ width:16px; height:16px;
114
+ text-indent:-10000px;
115
+ background-repeat:no-repeat;
116
+ padding:3px;
117
+ margin:0px;
118
+ }
119
+ .markItUpHeader ul ul a {
120
+ display:block;
121
+ padding-left:0px;
122
+ text-indent:0;
123
+ width:120px;
124
+ padding:5px 5px 5px 25px;
125
+ background-position:2px 50%;
126
+ }
127
+ .markItUpHeader ul ul a:hover {
128
+ color:#FFF;
129
+ background-color:#3C769D;
130
+ }
131
+ /***************************************************************************************/
132
+ .html .markItUpEditor {
133
+ background-image:url(../../image/bg-editor-html.png);
134
+ }
135
+ .markdown .markItUpEditor {
136
+ background-image:url(../../image/bg-editor-markdown.png);
137
+ }
138
+ .textile .markItUpEditor {
139
+ background-image:url(../../image/bg-editor-textile.png);
140
+ }
141
+ .bbcode .markItUpEditor {
142
+ background-image:url(../../image/bg-editor-bbcode.png);
143
+ }
144
+ .wiki .markItUpEditor,
145
+ .dotclear .markItUpEditor {
146
+ background-image:url(../../image/bg-editor-wiki.png);
147
+ }
@@ -0,0 +1,21 @@
1
+ require 'rails'
2
+ require File.dirname(__FILE__) + "/../../app/helpers/rails_markitup/markitup_helper"
3
+
4
+ module RailsMarkitup
5
+ class Engine < Rails::Engine
6
+
7
+ config.to_prepare do
8
+ ApplicationController.helper(MarkitupHelper)
9
+ end
10
+
11
+ # =====================================
12
+ # = = javascript_include_tag :markitup =
13
+ # = = stylesheet_link_tag :markitup =
14
+ # =====================================
15
+ config.before_initialize do
16
+ config.action_view.javascript_expansions[:markitup] = %w(markitup/jquery.markitup.js markitup/sets/markdown/set.js)
17
+ config.action_view.stylesheet_expansions[:markitup] = %w(markitup/sets/markdown/style.css markitup/skins/markdown/style.css)
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module RailsMarkitup
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails'
2
+ require "rails_markitup/version"
3
+ require "rails_markitup/engine"
4
+
5
+ module RailsMarkitup
6
+ # Your code goes here...
7
+ end
metadata ADDED
@@ -0,0 +1,195 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_markitup
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - AlexZhang
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-28 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 8
34
+ version: 3.0.8
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: redcarpet
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: albino
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: nokogiri
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :runtime
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: rspec
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ type: :development
92
+ version_requirements: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ name: rspec-rails
95
+ prerelease: false
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ type: :development
106
+ version_requirements: *id006
107
+ description: A MarkDown TextEditor with jQuery and Markitup! and redcarpet
108
+ email:
109
+ - blackanger.z@gmail.com
110
+ executables: []
111
+
112
+ extensions: []
113
+
114
+ extra_rdoc_files:
115
+ - README.markdown
116
+ files:
117
+ - Gemfile
118
+ - Rakefile
119
+ - README.markdown
120
+ - app/helpers/rails_markitup/markitup_helper.rb
121
+ - lib/generators/rails_markitup/install_generator.rb
122
+ - lib/generators/rails_markitup/media/images/bg-container.png
123
+ - lib/generators/rails_markitup/media/images/bg-editor-bbcode.png
124
+ - lib/generators/rails_markitup/media/images/bg-editor-dotclear.png
125
+ - lib/generators/rails_markitup/media/images/bg-editor-html.png
126
+ - lib/generators/rails_markitup/media/images/bg-editor-json.png
127
+ - lib/generators/rails_markitup/media/images/bg-editor-markdown.png
128
+ - lib/generators/rails_markitup/media/images/bg-editor-textile.png
129
+ - lib/generators/rails_markitup/media/images/bg-editor-wiki.png
130
+ - lib/generators/rails_markitup/media/images/bg-editor-xml.png
131
+ - lib/generators/rails_markitup/media/images/bg-editor.png
132
+ - lib/generators/rails_markitup/media/images/bold.png
133
+ - lib/generators/rails_markitup/media/images/clean.png
134
+ - lib/generators/rails_markitup/media/images/code.png
135
+ - lib/generators/rails_markitup/media/images/h1.png
136
+ - lib/generators/rails_markitup/media/images/h2.png
137
+ - lib/generators/rails_markitup/media/images/h3.png
138
+ - lib/generators/rails_markitup/media/images/h4.png
139
+ - lib/generators/rails_markitup/media/images/h5.png
140
+ - lib/generators/rails_markitup/media/images/h6.png
141
+ - lib/generators/rails_markitup/media/images/handle.png
142
+ - lib/generators/rails_markitup/media/images/image.png
143
+ - lib/generators/rails_markitup/media/images/italic.png
144
+ - lib/generators/rails_markitup/media/images/link.png
145
+ - lib/generators/rails_markitup/media/images/list-bullet.png
146
+ - lib/generators/rails_markitup/media/images/list-numeric.png
147
+ - lib/generators/rails_markitup/media/images/menu.png
148
+ - lib/generators/rails_markitup/media/images/picture.png
149
+ - lib/generators/rails_markitup/media/images/preview.png
150
+ - lib/generators/rails_markitup/media/images/quotes.png
151
+ - lib/generators/rails_markitup/media/images/stroke.png
152
+ - lib/generators/rails_markitup/media/images/submenu.png
153
+ - lib/generators/rails_markitup/media/javascripts/jquery.markitup.js
154
+ - lib/generators/rails_markitup/media/javascripts/sets/markdown/set.js
155
+ - lib/generators/rails_markitup/media/stylesheets/sets/markdown/style.css
156
+ - lib/generators/rails_markitup/media/stylesheets/skins/markitup/style.css
157
+ - lib/rails_markitup/engine.rb
158
+ - lib/rails_markitup/version.rb
159
+ - lib/rails_markitup.rb
160
+ has_rdoc: true
161
+ homepage: ""
162
+ licenses: []
163
+
164
+ post_install_message:
165
+ rdoc_options: []
166
+
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ hash: 3
175
+ segments:
176
+ - 0
177
+ version: "0"
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ none: false
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ hash: 3
184
+ segments:
185
+ - 0
186
+ version: "0"
187
+ requirements: []
188
+
189
+ rubyforge_project: rails_markitup
190
+ rubygems_version: 1.6.2
191
+ signing_key:
192
+ specification_version: 3
193
+ summary: A MarkDown TextEditor
194
+ test_files: []
195
+