41 lines
1.5 KiB
Ruby
41 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Model Dictionary
|
|
class Dictionary < ApplicationRecord
|
|
# == Constants ============================================================
|
|
|
|
# == Attributes ===========================================================
|
|
|
|
# == Extensions ===========================================================
|
|
|
|
# == Relationships ========================================================
|
|
|
|
# == Validations ==========================================================
|
|
validates :name, presence: true, length: { maximum: 255 }
|
|
validates :shortcut, presence: true, length: { maximum: 50 }
|
|
validates :description, presence: true, length: { maximum: 1000 }
|
|
# == Scopes ===============================================================
|
|
scope :by_short, ->(val) { where(shortcut: val) }
|
|
# == Callbacks ============================================================
|
|
|
|
# == Class Methods ========================================================
|
|
def self.ret_all_to_tinymce
|
|
ret = ''
|
|
Dictionary.all.each do |dict|
|
|
ret += dict.ret_a_tinymce_element
|
|
end
|
|
ret.chomp
|
|
end
|
|
|
|
# == Instance Methods =====================================================
|
|
def ret_a_tag
|
|
"<a tabindex='0' data-toggle='popover' data-trigger='hover' title='#{name}"\
|
|
"' data-content='#{description}' class='dictionary-word'>#{name}</a>"
|
|
end
|
|
|
|
def ret_a_tinymce_element
|
|
"{type: 'menuitem',text: '#{name}',onAction: function ()"\
|
|
" {editor.insertContent(' #{shortcut}');}},"
|
|
end
|
|
end
|