Module: MarkItUp
- Defined in:
- lib/mark_it_up.rb,
lib/mark_it_up/view_helpers.rb
Overview
end
Defined Under Namespace
Modules: ViewHelpers
Constant Summary collapse
- DEFAULT_ROOT =
"mark_it_up"- ICONS_EXTENSIONS_REGEXP =
/\.(png|jpg|jpeg|gif)$/i- @@settings =
nil- @@root =
nilnil- @@skin =
"markitup"- @@default_icon =
"button"
Class Method Summary collapse
- .buttons ⇒ Object
- .buttons=(buttons) ⇒ Object
- .default_buttons ⇒ Object
- .default_icon ⇒ Object
- .default_icon=(icon) ⇒ Object
- .default_settings ⇒ Object
- .delete_button(position_or_name) ⇒ Object
- .format_settings(settings) ⇒ Object
- .insert_button(*args) ⇒ Object
- .markup_set ⇒ Object
- .replace_button(position, new_button) ⇒ Object
- .root ⇒ Object
- .root=(path) ⇒ Object
- .settings ⇒ Object
- .settings=(settings) ⇒ Object
- .skin ⇒ Object
- .skin=(name) ⇒ Object
Class Method Details
.buttons ⇒ Object
47 48 49 |
# File 'lib/mark_it_up.rb', line 47 def @@buttons || end |
.buttons=(buttons) ⇒ Object
51 52 53 |
# File 'lib/mark_it_up.rb', line 51 def () @@buttons = end |
.default_buttons ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/mark_it_up.rb', line 100 def [ { :name => 'Heading 1', :icon => 'h1', :key => '1', :openWith => '<h1(!( class="[![Class]!]")!)>', :closeWith => '</h1>', :placeHolder => 'Your title here...' }, { :name => 'Heading 2', :icon => 'h2', :key => '2', :openWith => '<h2(!( class="[![Class]!]")!)>', :closeWith => '</h2>', :placeHolder => 'Your title here...' }, { :name => 'Heading 3', :icon => 'h3', :key => '3', :openWith => '<h3(!( class="[![Class]!]")!)>', :closeWith => '</h3>', :placeHolder => 'Your title here...' }, { :name => 'Heading 4', :icon => 'h4', :key => '4', :openWith => '<h4(!( class="[![Class]!]")!)>', :closeWith => '</h4>', :placeHolder => 'Your title here...' }, { :name => 'Heading 5', :icon => 'h5', :key => '5', :openWith => '<h5(!( class="[![Class]!]")!)>', :closeWith => '</h5>', :placeHolder => 'Your title here...' }, { :name => 'Heading 6', :icon => 'h6', :key => '6', :openWith => '<h6(!( class="[![Class]!]")!)>', :closeWith => '</h6>', :placeHolder => 'Your title here...' }, { :name => 'Paragraph', :icon => 'paragraph', :openWith => '<p(!( class="[![Class]!]")!)>', :closeWith => '</p>' }, { :separator => '---------------' }, { :name => 'Bold', :icon => 'bold', :key => 'B', :openWith => '(!(<strong>|!|<b>)!)', :closeWith => '(!(</strong>|!|</b>)!)' }, { :name => 'Italic', :icon => 'italic', :key => 'I', :openWith => '(!(<em>|!|<i>)!)', :closeWith => '(!(<em>|!|<i>)!)' }, { :name => 'Stroke through', :icon => 'stroke', :key => 'S', :openWith => '<del>', :closeWith => '</del>' }, { :separator => '---------------' }, { :name => 'Link', :icon => 'link', :openWith => '<a href="[![Link:!:http://]!]"(!( title="[![Title]!]")!)>', :closeWith => '</a>', :placeHolder => 'Your text to link...' }, { :name => 'Picture', :icon => 'picture', :replaceWith => '<img src="[![Source:!:http://]!]" alt="[![Alternative text]!]" />' }, { :separator => '---------------' }, # Got to think of something for replaceWith to work with functions. Use :call => "myFunctionName" till then # { :name => 'Clean', :icon => 'clean', :replaceWith => "function(markitup) { return markitup.selection.replace(/<(.*?)>/g, '') }" }, { :name => 'Preview', :icon => 'preview', :call => 'preview' } ] end |
.default_icon ⇒ Object
63 64 65 |
# File 'lib/mark_it_up.rb', line 63 def default_icon @@default_icon end |
.default_icon=(icon) ⇒ Object
67 68 69 |
# File 'lib/mark_it_up.rb', line 67 def default_icon=(icon) @@default_icon = icon end |
.default_settings ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/mark_it_up.rb', line 33 def default_settings { :onShiftEnter => { :keepDefault => false, :replaceWith => "<br />\n" }, :onCtrlEnter => { :keepDefault => false, :openWith => "\n<p>", :closeWith => "</p>"}, :onTab => { :keepDefault => false, :replaceWith => ' ' }, :previewParserPath => "/mark_it_up/preview", :markupSet => markup_set }.with_indifferent_access end |
.delete_button(position_or_name) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/mark_it_up.rb', line 90 def (position_or_name) btns = self. if position_or_name.is_a?(String) btns.delete_if { |btn| btn[:name] == position_or_name } else btns.delete_at(position_or_name - 1) end self. = btns end |
.format_settings(settings) ⇒ Object
43 44 45 |
# File 'lib/mark_it_up.rb', line 43 def format_settings(settings) settings.to_json end |
.insert_button(*args) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mark_it_up.rb', line 71 def (*args) btns = self. if args.size == 1 # Adds image to the end btns << args.first self. = btns elsif args.size == 2 and args[1].is_a?(Hash) # Adds image at specific position index = args[0] - 1 btns.insert(index, args[1]) self. = btns end end |
.markup_set ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/mark_it_up.rb', line 123 def markup_set .collect do |btn| if btn[:className].blank? and !btn[:separator] icon = btn[:icon].blank? ? self.default_icon : btn[:icon] class_name = icon.gsub(self::ICONS_EXTENSIONS_REGEXP, '') btn[:className] = "miu_#{class_name}" end btn end end |
.replace_button(position, new_button) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/mark_it_up.rb', line 83 def (position, ) btns = self. index = position - 1 btns[index] = self. = btns end |
.root ⇒ Object
17 18 19 |
# File 'lib/mark_it_up.rb', line 17 def root @@root || DEFAULT_ROOT end |
.root=(path) ⇒ Object
21 22 23 |
# File 'lib/mark_it_up.rb', line 21 def root=(path) @@root = path end |
.settings ⇒ Object
25 26 27 |
# File 'lib/mark_it_up.rb', line 25 def settings @@settings || default_settings end |
.settings=(settings) ⇒ Object
29 30 31 |
# File 'lib/mark_it_up.rb', line 29 def settings=(settings) @@settings = settings end |
.skin ⇒ Object
55 56 57 |
# File 'lib/mark_it_up.rb', line 55 def skin @@skin end |
.skin=(name) ⇒ Object
59 60 61 |
# File 'lib/mark_it_up.rb', line 59 def skin=(name) @@skin = name end |