mark_it_up 0.0.2

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.
Files changed (52) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +278 -0
  3. data/Rakefile +18 -0
  4. data/VERSION +1 -0
  5. data/lib/generators/miu_controller_generator.rb +27 -0
  6. data/lib/generators/templates/app/controllers/mark_it_up_controller.rb +7 -0
  7. data/lib/generators/templates/app/views/mark_it_up/preview.html.erb +16 -0
  8. data/lib/mark_it_up/view_helpers.rb +51 -0
  9. data/lib/mark_it_up.rb +136 -0
  10. data/lib/public/mark_it_up/icons/bold.png +0 -0
  11. data/lib/public/mark_it_up/icons/book_arrow.png +0 -0
  12. data/lib/public/mark_it_up/icons/button.png +0 -0
  13. data/lib/public/mark_it_up/icons/clean.png +0 -0
  14. data/lib/public/mark_it_up/icons/code.png +0 -0
  15. data/lib/public/mark_it_up/icons/h1.png +0 -0
  16. data/lib/public/mark_it_up/icons/h2.png +0 -0
  17. data/lib/public/mark_it_up/icons/h3.png +0 -0
  18. data/lib/public/mark_it_up/icons/h4.png +0 -0
  19. data/lib/public/mark_it_up/icons/h5.png +0 -0
  20. data/lib/public/mark_it_up/icons/h6.png +0 -0
  21. data/lib/public/mark_it_up/icons/image.png +0 -0
  22. data/lib/public/mark_it_up/icons/italic.png +0 -0
  23. data/lib/public/mark_it_up/icons/link.png +0 -0
  24. data/lib/public/mark_it_up/icons/list-bullet.png +0 -0
  25. data/lib/public/mark_it_up/icons/list-item.png +0 -0
  26. data/lib/public/mark_it_up/icons/list-numeric.png +0 -0
  27. data/lib/public/mark_it_up/icons/paragraph.png +0 -0
  28. data/lib/public/mark_it_up/icons/picture.png +0 -0
  29. data/lib/public/mark_it_up/icons/preview.png +0 -0
  30. data/lib/public/mark_it_up/icons/stroke.png +0 -0
  31. data/lib/public/mark_it_up/jquery.markitup.js +559 -0
  32. data/lib/public/mark_it_up/jquery.markitup.pack.js +9 -0
  33. data/lib/public/mark_it_up/skins/markitup/images/bg-container.png +0 -0
  34. data/lib/public/mark_it_up/skins/markitup/images/bg-editor-bbcode.png +0 -0
  35. data/lib/public/mark_it_up/skins/markitup/images/bg-editor-dotclear.png +0 -0
  36. data/lib/public/mark_it_up/skins/markitup/images/bg-editor-html.png +0 -0
  37. data/lib/public/mark_it_up/skins/markitup/images/bg-editor-json.png +0 -0
  38. data/lib/public/mark_it_up/skins/markitup/images/bg-editor-markdown.png +0 -0
  39. data/lib/public/mark_it_up/skins/markitup/images/bg-editor-textile.png +0 -0
  40. data/lib/public/mark_it_up/skins/markitup/images/bg-editor-wiki.png +0 -0
  41. data/lib/public/mark_it_up/skins/markitup/images/bg-editor-xml.png +0 -0
  42. data/lib/public/mark_it_up/skins/markitup/images/bg-editor.png +0 -0
  43. data/lib/public/mark_it_up/skins/markitup/images/handle.png +0 -0
  44. data/lib/public/mark_it_up/skins/markitup/images/menu.png +0 -0
  45. data/lib/public/mark_it_up/skins/markitup/images/submenu.png +0 -0
  46. data/lib/public/mark_it_up/skins/markitup/style.css +148 -0
  47. data/lib/public/mark_it_up/skins/simple/images/handle.png +0 -0
  48. data/lib/public/mark_it_up/skins/simple/images/menu.png +0 -0
  49. data/lib/public/mark_it_up/skins/simple/images/submenu.png +0 -0
  50. data/lib/public/mark_it_up/skins/simple/style.css +118 -0
  51. data/mark_it_up.gemspec +87 -0
  52. metadata +117 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Baptiste Grenier <baptiste@bapt.name>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,278 @@
1
+ = MarkItUp
2
+
3
+ MarkItUp is Rails plugin that helps you turn any textarea into a markup editor. It is based on excellent {markItUp jQuery plugin}[http://markitup.jaysalvat.com/].
4
+
5
+ == Installation
6
+
7
+ script/plugin install git://github.com/cingel/mark_it_up.git
8
+
9
+ With Rails 3 you have to use:
10
+
11
+ rails plugin install git://github.com/cingel/mark_it_up.git
12
+
13
+ During install all assets will be copied to [Rails.root]/public/mark_it_up
14
+
15
+ You can optionally generate MarkItUpController to be able to use default preview parser.
16
+
17
+ script/generate miu_controller
18
+
19
+ With Rails 3 you have to use:
20
+
21
+ rails generate miu_controller
22
+
23
+ Also you will have to download jQuery[http://jquery.com] and make it {play nicely with Prototype}[http://docs.jquery.com/Using_jQuery_with_Other_Libraries] if you are using prototype
24
+
25
+ == Examples
26
+
27
+ *DEMO*: You can see all examples in action on http://markitup.cingel.hr
28
+
29
+ === The most simple usage with preset defaults
30
+
31
+ <html>
32
+ <head>
33
+ <%= javascript_include_tag "path/to/jquery" %>
34
+ <%= mark_it_up '#miu_test' %>
35
+ </head>
36
+ <body>
37
+ <% form_tag do %>
38
+ <%= text_area_tag "miu_test" %>
39
+ <% end %>
40
+ </body>
41
+ </html>
42
+
43
+ === Define custom buttons
44
+
45
+ <html>
46
+ <head>
47
+ <%= javascript_include_tag "jquery" %>
48
+ <%
49
+ MarkItUp.buttons = [
50
+ { :name => 'Bold', :icon => 'bold', :key => 'B', :openWith => '(!(<strong>|!|<b>)!)', :closeWith => '(!(</strong>|!|</b>)!)' },
51
+ { :name => 'Italic', :icon => 'italic', :key => 'I', :openWith => '(!(<em>|!|<i>)!)', :closeWith => '(!(<em>|!|<i>)!)' },
52
+ { :name => 'Stroke through', :icon => 'stroke', :key => 'S', :openWith => '<del>', :closeWith => '</del>' }
53
+ ]
54
+ %>
55
+ <%= mark_it_up '#miu_test' %>
56
+ </head>
57
+ <body>
58
+ <% form_tag do %>
59
+ <%= text_area_tag "miu_test" %>
60
+ <% end %>
61
+ </body>
62
+ </html>
63
+
64
+ === Insert, Replace, Delete buttons
65
+
66
+ Here is the syntax
67
+
68
+ MarkItUp.replace_button(position, new_button) # replaces button at exact position
69
+ MarkItUp.insert_button(new_button) # inserts button at the end
70
+ MarkItUp.insert_button(position, new_button) # inserts button at exact position (buttons after position are moved up)
71
+ MarkItUp.delete_button(position) # deletes button at exact position
72
+ MarkItUp.delete_button(name) # deletes button which matches name
73
+
74
+ and here is example
75
+
76
+ <html>
77
+ <head>
78
+ <%= javascript_include_tag "jquery" %>
79
+ <%
80
+ MarkItUp.buttons = MarkItUp.default_buttons
81
+ MarkItUp.replace_button(14, { :name => 'Image', :icon => "image", :key => 'P', :replaceWith => '<img src="/path" alt="" />' })
82
+ MarkItUp.insert_button(16, { :name => 'Some button', :icon => 'some_icon', :key => 'X', :replaceWith => 'something' }) # insert new button at specific position
83
+ MarkItUp.insert_button(17, { :separator => '---------------' })
84
+ MarkItUp.insert_button({ :name => 'Some other button', :icon => 'some_other_icon', :key => 'Y', :replaceWith => 'something else' }) # insert new button to the end
85
+ MarkItUp.delete_button(3)
86
+ MarkItUp.delete_button("Bold")
87
+ %>
88
+ <%= mark_it_up '#miu_test' %>
89
+ </head>
90
+ <body>
91
+ <% form_tag do %>
92
+ <%= text_area_tag "miu_test" %>
93
+ <% end %>
94
+ </body>
95
+ </html>
96
+
97
+ === Custom settings
98
+
99
+ See http://markitup.jaysalvat.com/documentation/ for the complete list of available settings
100
+
101
+ <html>
102
+ <head>
103
+ <%= javascript_include_tag "jquery" %>
104
+ <%
105
+ miu_settings = MarkItUp.settings
106
+ miu_settings[:previewParserPath] = "/my/preview/path?layout=home"
107
+ %>
108
+ <%= mark_it_up '#miu_test', miu_settings %>
109
+ </head>
110
+ <body>
111
+ <% form_tag do %>
112
+ <%= text_area_tag "miu_test" %>
113
+ <% end %>
114
+ </body>
115
+ </html>
116
+
117
+ === Call your custom function
118
+
119
+ <html>
120
+ <head>
121
+ <script type="text/javascript">
122
+ MyNamespace = {
123
+ someFunction: function() {
124
+ jQuery.markItUp({ target: '#miu_test', replaceWith: 'text from some function' });
125
+ },
126
+ someOtherFunction: function() {
127
+ jQuery.markItUp({ target: '#miu_test', replaceWith: 'text from some other function' });
128
+ }
129
+ }
130
+ </script>
131
+ <%= javascript_include_tag "jquery" %>
132
+ <%
133
+ MarkItUp.buttons = MarkItUp.default_buttons
134
+ MarkItUp.insert_button({ :name => 'Some button', :key => 'S', :call => 'MyNamespace.someFunction' })
135
+ MarkItUp.insert_button({ :name => 'Some other button', :key => 'O', :call => 'MyNamespace.someOtherFunction' })
136
+ %>
137
+ <%= mark_it_up '#miu_test' %>
138
+ </head>
139
+ <body>
140
+ <% form_tag do %>
141
+ <%= text_area_tag "miu_test" %>
142
+ <% end %>
143
+ </body>
144
+ </html>
145
+
146
+ === Real complex usage
147
+
148
+ Here is the example how you can change preview depending which layout you select.
149
+
150
+ <html>
151
+ <head>
152
+ <!-- First we include prototype.js and jquery.js -->
153
+ <%= javascript_include_tag "prototype" %>
154
+ <%= javascript_include_tag "jquery" %>
155
+ <!-- Then we must make jQuery and Prototype live together -->
156
+ <script type="text/javascript" >
157
+ var $j = jQuery.noConflict();
158
+ </script>
159
+ <!-- We define some custom function. We will use MyNamespace.reloadMarkItUp() in our layout select box observer. -->
160
+ <script type="text/javascript">
161
+ MyNamespace = {
162
+ someFunction: function() {
163
+ $j.markItUp({ target: '#miu_test', replaceWith: 'text from some function' });
164
+ },
165
+ someOtherFunction: function() {
166
+ $j.markItUp({ target: '#miu_test', replaceWith: 'text from some other function' });
167
+ },
168
+ reloadMarkItUp: function() {
169
+ $j('#miu_test').markItUpRemove();
170
+ $j("#miu_test").markItUp(miuSettings);
171
+ }
172
+ }
173
+ </script>
174
+ <!-- We load markItUp assets. See vendor/plugins/mark_it_up/lib/mark_it_up/view_helpers.rb -->
175
+ <%= include_mark_it_up_javascripts %>
176
+ <%= include_mark_it_up_stylesheets %>
177
+ <!-- We insert few buttons and chnage preview parser -->
178
+ <%
179
+ MarkItUp.buttons = MarkItUp.default_buttons
180
+ MarkItUp.insert_button({ :name => 'Some button', :key => 'S', :call => 'MyNamespace.someFunction' })
181
+ MarkItUp.insert_button({ :name => 'Some other button', :key => 'O', :call => 'MyNamespace.someOtherFunction' })
182
+ miu_settings = MarkItUp.settings
183
+ miu_settings[:previewParserPath] = "/my/preview/path?layout=home;"
184
+ %>
185
+ <!-- Settings are assigned to miuSettings so we can access them later in layout observer later -->
186
+ <script type="text/javascript">
187
+ miuSettings = <%= MarkItUp.format_settings(miu_settings) %>;
188
+ $j(document).ready(function() {
189
+ $j("#miu_test").markItUp(miuSettings);
190
+ });
191
+ </script>
192
+ </head>
193
+ <body>
194
+ <% form_tag do %>
195
+ <%= select_tag "layout", options_for_select(%w(home admin default)) %>
196
+ <!-- We observe layout select box and so we our preview can use right layout -->
197
+ <%= observe_field :layout, :function => "miuSettings.previewParserPath='/my/preview/path?layout='+value;MyNamespace.reloadMarkItUp()" %>
198
+ <%= text_area_tag "miu_test" %>
199
+ <% end %>
200
+ </body>
201
+ </html>
202
+
203
+ == Global settings
204
+
205
+ === Root
206
+
207
+ Root relative to [Rails.root]/public ("mark_it_up" by default)
208
+
209
+ MarkItUp.root = "/path/to/mark_it_up"
210
+
211
+ === Skin
212
+
213
+ See available or place your skin in public/markitup/skins ("markitup" by default)
214
+
215
+ MarkItUp.skin = "my_skin"
216
+
217
+ === Default icon
218
+
219
+ Icon that will be used for button if neither :icon => "icon_name" or :className => "class_name" isn't provided ('button' by default)
220
+
221
+ MarkItUp.default_icon = "my_icon"
222
+
223
+ === Settings
224
+
225
+ To get the list of default settings call
226
+
227
+ MarkItUp.default_settings
228
+
229
+ See the list of all available settings at http://markitup.jaysalvat.com/documentation
230
+
231
+ MarkItUp.setting = mySettingsHash
232
+
233
+ === Buttons
234
+
235
+ To get the list of default buttons call
236
+
237
+ MarkItUp.default_buttons
238
+
239
+ To add your custom list of buttons
240
+
241
+ MarkItUp.buttons = [
242
+ { :name => 'Bold', :icon => 'bold', :key => 'B', :openWith => '(!(<strong>|!|<b>)!)', :closeWith => '(!(</strong>|!|</b>)!)' },
243
+ { :name => 'Italic', :icon => 'italic', :key => 'I', :openWith => '(!(<em>|!|<i>)!)', :closeWith => '(!(<em>|!|<i>)!)' },
244
+ { :name => 'Stroke through', :icon => 'stroke', :key => 'S', :openWith => '<del>', :closeWith => '</del>' }
245
+ ]
246
+
247
+ To insert, replace or delete buttons use <tt>MarkItUp.inser_button</tt>, <tt>MarkItUp.replace_button</tt> or <tt>MarkItUp.delete_button</tt> (see examples)
248
+
249
+ == Drawbacks
250
+
251
+ Still have to find a way to provide function assignment to replaceWith
252
+
253
+ replaceWith: function() { return "something from function" }
254
+
255
+ Till then use :call => "MyNamespace.myFunction"
256
+
257
+ == Fork's reason
258
+
259
+ This fork is an attempt of creating a gem for the plugin that would work for both
260
+ Rails 2 and 3.
261
+ The original plugin was not completely integrated wwith Rails 3, hence this
262
+ fork.
263
+
264
+ For now only Rails 3 has been tested.
265
+
266
+ If eveything goes well t will eventually be merged to the main mark_it_up project.
267
+
268
+ == Credits
269
+
270
+ {jQuery Team}[http://jquery.com/] for jQuery
271
+
272
+ {Jay Salvat}[http://jaysalvat.com] for markItUp! plugin
273
+
274
+ {Cingel}[http://github.com/cingel/mark_it_up] for the mark_it_up Rails plugin
275
+
276
+ Copyright (c) 2010 Vlado Cingel, released under the MIT license
277
+
278
+ Copyright (c) 2010 Baptiste Grenier, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require "rake"
2
+
3
+ begin
4
+ require "jeweler"
5
+ Jeweler::Tasks.new do |gem|
6
+ gem.name = "mark_it_up"
7
+ gem.summary = "Mark It Up integration for rails"
8
+ gem.description = "Mark It Up editor integration for rails 3, all the real work is done by the code from http://github.com/cingel/mark_it_up"
9
+ gem.email = "baptiste@bapt.name"
10
+ gem.homepage = "http://github.com/gwarf/mark_it_up"
11
+ gem.authors = ["Baptiste Grenier"]
12
+ gem.files = Dir["*", "{lib}/**/*"]
13
+ end
14
+
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,27 @@
1
+ class MiuControllerGenerator < Rails::Generators::Base
2
+ source_root File.expand_path("../templates", __FILE__)
3
+
4
+ desc "This generator creates the mark it up controller, view and route"
5
+
6
+ def create_miucontroller
7
+ copy_file 'app/controllers/mark_it_up_controller.rb', 'app/controllers/mark_it_up_controller.rb'
8
+ copy_file 'app/views/mark_it_up/preview.html.erb', 'app/views/mark_it_up/preview.html.erb'
9
+ add_route
10
+ copy_assets
11
+ end
12
+
13
+ private
14
+ def add_route
15
+ preview_route = %{match "mark_it_up/preview" => "mark_it_up#preview"}
16
+ route(preview_route)
17
+ end
18
+
19
+ def copy_assets
20
+ src = File.expand_path("../../public/mark_it_up", __FILE__)
21
+ dest = "#{Rails.root}/public/mark_it_up"
22
+ puts "* Copying assets to #{dest}"
23
+ FileUtils.cp_r(src, dest)
24
+ puts "* Run 'script/generate miu_controller' to generate MarkItUpController and to be able to use default preview parser"
25
+ end
26
+
27
+ end
@@ -0,0 +1,7 @@
1
+ class MarkItUpController < ApplicationController
2
+
3
+ def preview
4
+ render :action => "preview", :layout => false
5
+ end
6
+
7
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <title>markItUp! preview template</title>
6
+ <style type="text/css" media="screen">
7
+ body {
8
+ background-color:#EFEFEF;
9
+ font:70% Verdana, Arial, Helvetica, sans-serif;
10
+ }
11
+ </style>
12
+ </head>
13
+ <body>
14
+ <%= params[:data] %>
15
+ </body>
16
+ </html>
@@ -0,0 +1,51 @@
1
+ module MarkItUp
2
+ module ViewHelpers
3
+ include ActionView::Helpers::AssetTagHelper
4
+
5
+ def mark_it_up(selector, options = nil, dependencies = true)
6
+ settings = options || MarkItUp.settings
7
+ html = ""
8
+ if dependencies
9
+ html << include_mark_it_up_javascripts
10
+ html << include_mark_it_up_stylesheets
11
+ end
12
+ html << %{
13
+ <script type="text/javascript">
14
+ jQuery(document).ready(function() {
15
+ jQuery('#{selector}').markItUp(#{MarkItUp.format_settings(settings)})
16
+ });
17
+ </script>
18
+ }
19
+ return_html_considering_rails_version(html)
20
+ end
21
+
22
+ def include_mark_it_up_javascripts
23
+ js_file_name = Rails.env.production? ? "jquery.markitup.pack" : "jquery.markitup"
24
+ return_html_considering_rails_version(javascript_include_tag("/#{MarkItUp.root}/#{js_file_name}.js"))
25
+ end
26
+
27
+ def include_mark_it_up_stylesheets
28
+ css = %{\n<link href="/#{MarkItUp.root}/skins/#{MarkItUp.skin}/style.css" media="all" rel="stylesheet" type="text/css" />}
29
+ inline_css = MarkItUp.markup_set.inject("") do |x,btn|
30
+ icon = btn[:icon].blank? ? MarkItUp.default_icon : btn[:icon]
31
+ icon.concat(".png") unless icon.match(MarkItUp::ICONS_EXTENSIONS_REGEXP)
32
+ x.concat(btn[:className].blank? ? "" : ".markItUp .#{btn[:className]} a {background-image:url(/#{MarkItUp.root}/icons/#{icon})}\n")
33
+ end
34
+ css << %{
35
+ <style type="text/css" media="all">
36
+ #{inline_css}
37
+ </style>
38
+ }
39
+ return_html_considering_rails_version(css)
40
+ end
41
+
42
+ private
43
+
44
+ def return_html_considering_rails_version(html)
45
+ (Rails::VERSION::MAJOR == 3) ? html.html_safe : html
46
+ end
47
+
48
+ end
49
+ end
50
+
51
+ ActionView::Base.send :include, MarkItUp::ViewHelpers
data/lib/mark_it_up.rb ADDED
@@ -0,0 +1,136 @@
1
+ require 'mark_it_up/view_helpers'
2
+ #if Rails::VERSION::MAJOR == 2
3
+ #else
4
+ #end
5
+ module MarkItUp
6
+ DEFAULT_ROOT = "mark_it_up"
7
+ ICONS_EXTENSIONS_REGEXP = /\.(png|jpg|jpeg|gif)$/i
8
+
9
+ @@settings = nil
10
+ @@root = nil
11
+ @@buttons = nil
12
+ @@skin = "markitup"
13
+ @@default_icon = "button"
14
+
15
+ class << self
16
+
17
+ def root
18
+ @@root || DEFAULT_ROOT
19
+ end
20
+
21
+ def root=(path)
22
+ @@root = path
23
+ end
24
+
25
+ def settings
26
+ @@settings || default_settings
27
+ end
28
+
29
+ def settings=(settings)
30
+ @@settings = settings
31
+ end
32
+
33
+ def default_settings
34
+ {
35
+ :onShiftEnter => { :keepDefault => false, :replaceWith => "<br />\n" },
36
+ :onCtrlEnter => { :keepDefault => false, :openWith => "\n<p>", :closeWith => "</p>"},
37
+ :onTab => { :keepDefault => false, :replaceWith => ' ' },
38
+ :previewParserPath => "/mark_it_up/preview",
39
+ :markupSet => markup_set
40
+ }.with_indifferent_access
41
+ end
42
+
43
+ def format_settings(settings)
44
+ settings.to_json
45
+ end
46
+
47
+ def buttons
48
+ @@buttons || default_buttons
49
+ end
50
+
51
+ def buttons=(buttons)
52
+ @@buttons = buttons
53
+ end
54
+
55
+ def skin
56
+ @@skin
57
+ end
58
+
59
+ def skin=(name)
60
+ @@skin = name
61
+ end
62
+
63
+ def default_icon
64
+ @@default_icon
65
+ end
66
+
67
+ def default_icon=(icon)
68
+ @@default_icon = icon
69
+ end
70
+
71
+ def insert_button(*args)
72
+ btns = self.buttons
73
+ if args.size == 1 # Adds image to the end
74
+ btns << args.first
75
+ self.buttons = btns
76
+ elsif args.size == 2 and args[1].is_a?(Hash) # Adds image at specific position
77
+ index = args[0] - 1
78
+ btns.insert(index, args[1])
79
+ self.buttons = btns
80
+ end
81
+ end
82
+
83
+ def replace_button(position, new_button)
84
+ btns = self.buttons
85
+ index = position - 1
86
+ btns[index] = new_button
87
+ self.buttons = btns
88
+ end
89
+
90
+ def delete_button(position_or_name)
91
+ btns = self.buttons
92
+ if position_or_name.is_a?(String)
93
+ btns.delete_if { |btn| btn[:name] == position_or_name }
94
+ else
95
+ btns.delete_at(position_or_name - 1)
96
+ end
97
+ self.buttons = btns
98
+ end
99
+
100
+ def default_buttons
101
+ [
102
+ { :name => 'Heading 1', :icon => 'h1', :key => '1', :openWith => '<h1(!( class="[![Class]!]")!)>', :closeWith => '</h1>', :placeHolder => 'Your title here...' },
103
+ { :name => 'Heading 2', :icon => 'h2', :key => '2', :openWith => '<h2(!( class="[![Class]!]")!)>', :closeWith => '</h2>', :placeHolder => 'Your title here...' },
104
+ { :name => 'Heading 3', :icon => 'h3', :key => '3', :openWith => '<h3(!( class="[![Class]!]")!)>', :closeWith => '</h3>', :placeHolder => 'Your title here...' },
105
+ { :name => 'Heading 4', :icon => 'h4', :key => '4', :openWith => '<h4(!( class="[![Class]!]")!)>', :closeWith => '</h4>', :placeHolder => 'Your title here...' },
106
+ { :name => 'Heading 5', :icon => 'h5', :key => '5', :openWith => '<h5(!( class="[![Class]!]")!)>', :closeWith => '</h5>', :placeHolder => 'Your title here...' },
107
+ { :name => 'Heading 6', :icon => 'h6', :key => '6', :openWith => '<h6(!( class="[![Class]!]")!)>', :closeWith => '</h6>', :placeHolder => 'Your title here...' },
108
+ { :name => 'Paragraph', :icon => 'paragraph', :openWith => '<p(!( class="[![Class]!]")!)>', :closeWith => '</p>' },
109
+ { :separator => '---------------' },
110
+ { :name => 'Bold', :icon => 'bold', :key => 'B', :openWith => '(!(<strong>|!|<b>)!)', :closeWith => '(!(</strong>|!|</b>)!)' },
111
+ { :name => 'Italic', :icon => 'italic', :key => 'I', :openWith => '(!(<em>|!|<i>)!)', :closeWith => '(!(<em>|!|<i>)!)' },
112
+ { :name => 'Stroke through', :icon => 'stroke', :key => 'S', :openWith => '<del>', :closeWith => '</del>' },
113
+ { :separator => '---------------' },
114
+ { :name => 'Link', :icon => 'link', :openWith => '<a href="[![Link:!:http://]!]"(!( title="[![Title]!]")!)>', :closeWith => '</a>', :placeHolder => 'Your text to link...' },
115
+ { :name => 'Picture', :icon => 'picture', :replaceWith => '<img src="[![Source:!:http://]!]" alt="[![Alternative text]!]" />' },
116
+ { :separator => '---------------' },
117
+ # Got to think of something for replaceWith to work with functions. Use :call => "myFunctionName" till then
118
+ # { :name => 'Clean', :icon => 'clean', :replaceWith => "function(markitup) { return markitup.selection.replace(/<(.*?)>/g, '') }" },
119
+ { :name => 'Preview', :icon => 'preview', :call => 'preview' }
120
+ ]
121
+ end
122
+
123
+ def markup_set
124
+ buttons.collect do |btn|
125
+ if btn[:className].blank? and !btn[:separator]
126
+ icon = btn[:icon].blank? ? self.default_icon : btn[:icon]
127
+ class_name = icon.gsub(self::ICONS_EXTENSIONS_REGEXP, '')
128
+ btn[:className] = "miu_#{class_name}"
129
+ end
130
+ btn
131
+ end
132
+ end
133
+
134
+ end
135
+
136
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file