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.8.13 lib/filename_to_slug.rb
rocket_cms-0.8.12 lib/filename_to_slug.rb
rocket_cms-0.8.11 lib/filename_to_slug.rb
rocket_cms-0.8.10 lib/filename_to_slug.rb
rocket_cms-0.8.9 lib/filename_to_slug.rb
rocket_cms-0.8.8 lib/filename_to_slug.rb
rocket_cms-0.8.7 lib/filename_to_slug.rb
rocket_cms-0.8.6 lib/filename_to_slug.rb
rocket_cms-0.8.5 lib/filename_to_slug.rb
rocket_cms-0.8.4 lib/filename_to_slug.rb
rocket_cms-0.8.3 lib/filename_to_slug.rb
rocket_cms-0.8.1 lib/filename_to_slug.rb
rocket_cms-0.8.0 lib/filename_to_slug.rb
rocket_cms-0.8.0.pre.6 lib/filename_to_slug.rb
rocket_cms-0.8.0.pre.5 lib/filename_to_slug.rb
rocket_cms-0.8.0.pre.4 lib/filename_to_slug.rb
rocket_cms-0.8.0.pre.3 lib/filename_to_slug.rb
rocket_cms-0.8.0.pre.2 lib/filename_to_slug.rb
rocket_cms-0.8.0.pre.1 lib/filename_to_slug.rb
rocket_cms-0.7.1 lib/filename_to_slug.rb