Sha256: b6df03169a5794bb91097f04acbbc22421084026e0c152e27e849c29e725e0a3

Contents?: true

Size: 793 Bytes

Versions: 151

Compression:

Stored size: 793 Bytes

Contents

require 'stringex'
require 'digest/md5'

class String
  def filename_to_slug
    s = self.to_url
    if s.blank?
      return Digest::MD5.hexdigest(self)
    end
    s
  end
end

module FilenameToSlug
  extend ActiveSupport::Concern
  included do
    before_post_process :filename_to_slug
  end

  def filename_to_slug
    if self.class.attachment_definitions
      self.class.attachment_definitions.each do |k,v|
        if self.send(k).file?
          full_file_name = self.send("#{k}_file_name")
          extension = File.extname(full_file_name)[1..-1]
          file_name = full_file_name[0..full_file_name.size-extension.size-1]
          self.send("#{k}").instance_write(:file_name, "#{file_name.filename_to_slug}.#{extension.filename_to_slug}")
        end
      end
    end
  end
end

Version data entries

151 entries across 151 versions & 1 rubygems

Version Path
rocket_cms-0.5.3 lib/filename_to_slug.rb
rocket_cms-0.5.2 lib/filename_to_slug.rb
rocket_cms-0.5.1 lib/filename_to_slug.rb
rocket_cms-0.5.0 lib/filename_to_slug.rb
rocket_cms-0.5.0.rc.5 lib/filename_to_slug.rb
rocket_cms-0.5.0.rc.4 lib/filename_to_slug.rb
rocket_cms-0.4.2 lib/filename_to_slug.rb
rocket_cms-0.3.2 lib/filename_to_slug.rb
rocket_cms-0.2.12 lib/filename_to_slug.rb
rocket_cms-0.2.10 lib/filename_to_slug.rb
rocket_cms-0.1.13 lib/filename_to_slug.rb