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.24 lib/filename_to_slug.rb
rocket_cms-0.5.23 lib/filename_to_slug.rb
rocket_cms-0.5.22 lib/filename_to_slug.rb
rocket_cms-0.5.21 lib/filename_to_slug.rb
rocket_cms-0.5.20 lib/filename_to_slug.rb
rocket_cms-0.5.19 lib/filename_to_slug.rb
rocket_cms-0.5.18 lib/filename_to_slug.rb
rocket_cms-0.5.17 lib/filename_to_slug.rb
rocket_cms-0.5.16 lib/filename_to_slug.rb
rocket_cms-0.5.15 lib/filename_to_slug.rb
rocket_cms-0.5.14 lib/filename_to_slug.rb
rocket_cms-0.5.12 lib/filename_to_slug.rb
rocket_cms-0.5.11 lib/filename_to_slug.rb
rocket_cms-0.5.10 lib/filename_to_slug.rb
rocket_cms-0.5.9 lib/filename_to_slug.rb
rocket_cms-0.5.8 lib/filename_to_slug.rb
rocket_cms-0.5.7 lib/filename_to_slug.rb
rocket_cms-0.5.6 lib/filename_to_slug.rb
rocket_cms-0.5.5 lib/filename_to_slug.rb
rocket_cms-0.5.4 lib/filename_to_slug.rb