module SimpleFormWysihtml

Constants

VERSION

Public Instance Methods

action_tag(action, label) click to toggle source

@param [String] action @param [String] label @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 292
def action_tag action, label
  template.content_tag :a, 'data-wysihtml5-dialog-action' => action, class: 'button' do
    label
  end.html_safe
end
bold(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 87
def bold options={}
  label = options[:label] || 'Bold'

  command_tag 'bold', label
end
command_group(group) click to toggle source

@param [Array] group @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 61
def command_group group
  template.content_tag :li, class: 'command_group' do
    group.map do |command, options|
      self.send(command, options || {})
    end.join.html_safe
  end.html_safe
end
command_tag(command, label, value=nil) click to toggle source

Generates link for specified command

@param [String] command @param [String] label @param [String] value @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 264
def command_tag command, label, value=nil
  options = { 'data-wysihtml5-command' => command }
  options.merge!({ 'data-wysihtml5-command-value' => value }) if value.present?
  options.merge!({ class: 'command button' })

  template.content_tag :a, options do
    label
  end.html_safe
end
commands() click to toggle source

@return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 51
def commands
  template.content_tag :ul, class: 'commands' do
    command_list.collect do |group|
      command_group(group)
    end.join.html_safe
  end
end
dialog_field_tag(att, value=nil) click to toggle source

@param [String] att @param [String] value @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 301
def dialog_field_tag att, value=nil
  "<input data-wysihtml5-dialog-field='#{att}' value='#{value}'>".html_safe
end
dialog_tag(command, label, dialog_field) click to toggle source

@param [String] command @param [String] label @param [String] dialog_field @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 278
def dialog_tag command, label, dialog_field
  options = { 'data-wysihtml5-dialog' => command, style: 'display: none' }
  options.merge!({ class: 'dialog' })

  template.content_tag :div, options do
    template.content_tag(:label, (label + dialog_field).html_safe).html_safe +
      action_tag('save', 'OK') +
      action_tag('cancel', 'Cancel')
  end.html_safe
end
dialogs() click to toggle source

@param [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 70
def dialogs
  flattened_command_list = command_list.inject({}){ |res, i| res.merge!(i) }
  command_list_with_dialog = flattened_command_list.select{ |k,v| %w(createLink insertImage).include?(k.to_s) }

  return unless command_list_with_dialog.present?

  template.content_tag :div, class: 'dialogs' do
    command_list_with_dialog.map do |command, options|
      self.send("#{command}_dialog", options || {})
    end.join.html_safe
  end
end
fontSize(options={}) click to toggle source

@param [Hash] options @retun [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 114
def fontSize options={}
  label = options[:label] || 'Size'
  value = options[:value] || 'small'

  command_tag 'fontSize', label, value
end
foreColor(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 123
def foreColor options={}
  label = options[:label] || 'Color'
  value = options[:label] || 'red'

  command_tag 'foreColor', label, value
end
formatBlock(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 132
def formatBlock options={}
  label = options[:label] || 'Block'
  value = options[:value] || 'h1'

  command_tag 'formatBlock', label, value
end
formatInline(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 141
def formatInline options={}
  label = options[:label] || 'Inline'
  value = options[:value] || 'span'

  command_tag 'formatInline', label, value
end
insertHTML(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 150
def insertHTML options={}
  label = options[:label] || 'HTML'
  value = options[:value] || '<blockquote>foobar</blockquote>'

  command_tag 'insertHTML', label, value
end
insertImage(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 159
def insertImage options={}
  label = options[:label] || 'Image'
  value = options[:value] || 'http://'

  command_tag('insertImage', label)
end
insertImage_dialog(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 168
def insertImage_dialog options={}
  dialog_label = options[:dialog_label] || 'Image:'
  value = options[:value] || 'http://'
  dialog_field = dialog_field_tag('src', value)

  dialog_tag('createLink', dialog_label, dialog_field)
end
insertLineBreak(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 178
def insertLineBreak options={}
  label = options[:label] || 'Line Break'

  command_tag 'insertLineBreak', label
end
insertOrderedList(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 186
def insertOrderedList options={}
  label = options[:label] || 'OL'

  command_tag 'insertOrderedList', label
end
insertUnorderedList(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 194
def insertUnorderedList options={}
  label = options[:label] || 'UL'

  command_tag 'insertUnorderedList', label
end
italic(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 202
def italic options={}
  label = options[:label] || 'Italic'

  command_tag 'italic', label
end
justifyCenter(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 210
def justifyCenter options={}
  label = options[:label] || 'Center'

  command_tag 'justifyCenter', label
end
justifyLeft(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 218
def justifyLeft options={}
  label = options[:label] || 'Left'

  command_tag 'justifyLeft', label
end
justifyRight(options) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 226
def justifyRight options
  label = options[:label] || 'Right'

  command_tag 'justifyRight', label
end
redo(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 234
def redo options={}
  label = options[:label] || 'Redo'

  command_tag 'redo', label
end
text_area() click to toggle source

@return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 39
def text_area
  @builder.text_area(attribute_name, input_html_options).html_safe
end
toolbar() click to toggle source

@return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 44
def toolbar
  template.content_tag :div, class: 'toolbar' do
    commands + dialogs
  end.html_safe
end
underline(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 242
def underline options={}
  label = options[:label] || 'Underline'

  command_tag 'underline', label
end
undo(options={}) click to toggle source

@param [Hash] options @return [String]

# File lib/simple_form_wysihtml/simple_form_wysihtml.rb, line 250
def undo options={}
  label = options[:label] || 'Undo'

  command_tag 'undo', label
end