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 =
nil
@@buttons =
nil
@@skin =
"markitup"
@@default_icon =
"button"

Class Method Summary collapse

Class Method Details

.buttonsObject



47
48
49
# File 'lib/mark_it_up.rb', line 47

def buttons
  @@buttons || default_buttons
end

.buttons=(buttons) ⇒ Object



51
52
53
# File 'lib/mark_it_up.rb', line 51

def buttons=(buttons)
  @@buttons = buttons
end

.default_buttonsObject



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 default_buttons
  [
    { :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_iconObject



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_settingsObject



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 delete_button(position_or_name)
  btns = self.buttons
  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.buttons = 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 insert_button(*args)
  btns = self.buttons
  if args.size == 1 # Adds image to the end
    btns << args.first
    self.buttons = 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.buttons = btns
  end
end

.markup_setObject



123
124
125
126
127
128
129
130
131
132
# File 'lib/mark_it_up.rb', line 123

def markup_set
  buttons.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 replace_button(position, new_button)
  btns = self.buttons
  index = position - 1
  btns[index] = new_button
  self.buttons = btns
end

.rootObject



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

.settingsObject



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

.skinObject



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