Sha256: a44dfbd50c67e2abf964899a8a8f226f01c1a9cb8caba7d61f53e0bca81adff7
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
module Iconly class Icon < ApplicationRecord belongs_to :package, class_name: 'Package' has_many :project_icons, dependent: :destroy mount_uploader :svg, SvgUploader extend FriendlyId friendly_id :name, use: [:slugged, :scoped], scope: :package validates :name, :contents, presence: true scope :search, ->(term) { where('iconly_icons.name ILIKE ?', "%#{term}%") } def self.all_packages(user_id, term = nil) with_package = user_id ? Package.shared_or_owned_by(user_id) : Package.shared icons = includes(:package) .joins(:package) .merge(with_package) icons = icons.merge(search(term)) if term.present? icons .order('iconly_packages.name') .group_by(&:package) end def svg_path File.join(Iconly.svg_folder, svg.try(:url) || '') end def markup (contents || '').gsub(']>', '').html_safe end def human_name name.humanize(capitalize: false) end private def should_generate_new_friendly_id? name_changed? end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
iconly-1.0.0 | app/models/iconly/icon.rb |