Sha256: efc213fe4b59e8039748800bf161d05d5edac1cdfb005e144bd59e4c3daac7fc

Contents?: true

Size: 646 Bytes

Versions: 15

Compression:

Stored size: 646 Bytes

Contents

module Locomotive
  module Extensions
    module Shared
      module Slug
        extend ActiveSupport::Concern

        module ClassMethods

          def slugify_from(field)
            class_eval <<-EOV
              before_validation { |object| object.send(:normalize_slug, :#{field.to_s}) }
            EOV
          end
        end

        protected

        def normalize_slug(field)
          value = self.send(field)

          if self.slug.blank? && value.present?
            self.slug = value.clone
          end

          if self.slug.present?
            self.slug.permalink!
          end
        end

      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
locomotive_cms-2.5.7 app/models/locomotive/extensions/shared/slug.rb
locomotive_cms-2.5.6 app/models/locomotive/extensions/shared/slug.rb
locomotive_cms-2.5.6.rc2 app/models/locomotive/extensions/shared/slug.rb
locomotive_cms-2.5.6.rc1 app/models/locomotive/extensions/shared/slug.rb
locomotive_cms-2.5.5 app/models/locomotive/extensions/shared/slug.rb
locomotive_cms-2.5.4 app/models/locomotive/extensions/shared/slug.rb
locomotive_cms-2.5.3 app/models/locomotive/extensions/shared/slug.rb
locomotive_cms-2.5.2 app/models/locomotive/extensions/shared/slug.rb
locomotive_cms-2.5.1 app/models/locomotive/extensions/shared/slug.rb
locomotive_cms-2.5.0 app/models/locomotive/extensions/shared/slug.rb
locomotive_cms-2.5.0.rc3 app/models/locomotive/extensions/shared/slug.rb
locomotive_cms-2.5.0.rc2 app/models/locomotive/extensions/shared/slug.rb
locomotive_cms-2.5.0.rc1 app/models/locomotive/extensions/shared/slug.rb
locomotive_cms-2.4.1 app/models/locomotive/extensions/shared/slug.rb
locomotive_cms-2.4.0 app/models/locomotive/extensions/shared/slug.rb