slugtastic 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ *.swp
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=doc
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## v0.2.0
2
+
3
+ * Rebuild of gem using bundler.
4
+ * Full spec added.
5
+
6
+ ## v0.1.2
7
+
8
+ * Fixed minor bug when the source field is empty.
9
+
10
+ ## v0.1.1
11
+
12
+ * Initial release.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in slugtastic.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ slugtastic (0.2.0.alpha)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activemodel (3.0.17)
10
+ activesupport (= 3.0.17)
11
+ builder (~> 2.1.2)
12
+ i18n (~> 0.5.0)
13
+ activesupport (3.0.17)
14
+ builder (2.1.2)
15
+ diff-lcs (1.1.3)
16
+ i18n (0.5.0)
17
+ rake (0.9.2.2)
18
+ rspec (2.11.0)
19
+ rspec-core (~> 2.11.0)
20
+ rspec-expectations (~> 2.11.0)
21
+ rspec-mocks (~> 2.11.0)
22
+ rspec-core (2.11.1)
23
+ rspec-expectations (2.11.2)
24
+ diff-lcs (~> 1.1.3)
25
+ rspec-mocks (2.11.2)
26
+ supermodel (0.1.6)
27
+ activemodel (~> 3.0.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ rake
34
+ rspec
35
+ slugtastic!
36
+ supermodel
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Dan Barber
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,15 +1,20 @@
1
- Slugtastic
2
- ==========
1
+ # Slugtastic [![Build Status](https://secure.travis-ci.org/danbee/slugtastic.png?branch=master)](http://travis-ci.org/danbee/slugtastic)
3
2
 
4
3
  Simple gem for autogenerating permalink style slugs for your ActiveRecord models.
5
4
 
6
- ## Install
5
+ ## Installation
7
6
 
8
- Add this to your Gemfile:
7
+ Add this line to your application's Gemfile:
9
8
 
10
- gem "slugtastic"
9
+ gem 'slugtastic'
11
10
 
12
- And run `bundle install`
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install slugtastic
13
18
 
14
19
  ## Usage
15
20
 
@@ -19,4 +24,12 @@ Usage is very simple. Just add the following to your model:
19
24
 
20
25
  This will generate a slug string from the title atrribute and store it in the slug attribute unless the slug already contains a string. The slug is generated pre-validation so you can still use `validates_presence_of :slug`.
21
26
 
22
- There are no extra options at present.
27
+ There are no extra options at present.
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,14 +1,7 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'echoe'
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
4
 
5
- Echoe.new('slugtastic', '0.1.2') do |p|
6
- p.description = "A simple slug string generator for ActiveRecord. Will populate a slug attribute from another attribute."
7
- p.url = "http://github.com/danbee/slugtastic"
8
- p.author = "Dan Barber"
9
- p.email = "danbee@gmail.com"
10
- p.ignore_pattern = ["tmp/*", "script/*"]
11
- p.development_dependencies = []
12
- end
5
+ RSpec::Core::RakeTask.new(:spec)
13
6
 
14
- Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
7
+ task default: :spec
@@ -0,0 +1,11 @@
1
+ module Slugtastic
2
+ module ModelAdditions
3
+
4
+ def has_slug name, options = { :from => :title }
5
+ before_validation do |record|
6
+ send("#{name}=", Slugtastic.generate_slug(send(options[:from]))) if send(name).nil? or send(name).blank?
7
+ end
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Slugtastic
2
+ class Railtie < Rails::Railtie
3
+ initializer "slugtastic.model_additions" do
4
+ ActiveSupport.on_load :active_record do
5
+ extend ModelAdditions
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Slugtastic
2
+ VERSION = "0.2.0"
3
+ end
data/lib/slugtastic.rb CHANGED
@@ -1,23 +1,9 @@
1
+ require "slugtastic/version"
2
+ require "slugtastic/model_additions"
3
+ require "slugtastic/railtie" if defined? Rails
4
+
1
5
  module Slugtastic
2
- def self.included(base)
3
- base.extend ClassMethods
4
- end
5
-
6
- def generate_slug(string)
6
+ def self.generate_slug(string)
7
7
  string.downcase.gsub(/ /, '_').gsub(/[^a-z0-9\-_]/, '') unless string.nil?
8
8
  end
9
-
10
- module ClassMethods
11
-
12
- def has_slug(name, options = { :from => :title })
13
- before_validation do |record|
14
- self[name] = generate_slug(self[options[:from]]) if self[name].nil? or self[name].empty?
15
- end
16
- end
17
-
18
- end
19
9
  end
20
-
21
- class ActiveRecord::Base
22
- include Slugtastic
23
- end
data/slugtastic.gemspec CHANGED
@@ -1,29 +1,21 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/slugtastic/version', __FILE__)
2
3
 
3
- Gem::Specification.new do |s|
4
- s.name = %q{slugtastic}
5
- s.version = "0.1.2"
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Dan Barber"]
6
+ gem.email = ["danbee@gmail.com"]
7
+ gem.description = %q{A simple slug string generator for ActiveRecord. Will populate a slug attribute from another attribute.}
8
+ gem.summary = %q{A simple slug string generator for ActiveRecord.}
9
+ gem.homepage = ""
6
10
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = [%q{Dan Barber}]
9
- s.date = %q{2011-10-08}
10
- s.description = %q{A simple slug string generator for ActiveRecord. Will populate a slug attribute from another attribute.}
11
- s.email = %q{danbee@gmail.com}
12
- s.extra_rdoc_files = [%q{README.md}, %q{lib/slugtastic.rb}]
13
- s.files = [%q{Manifest}, %q{README.md}, %q{Rakefile}, %q{lib/slugtastic.rb}, %q{slugtastic.gemspec}]
14
- s.homepage = %q{http://github.com/danbee/slugtastic}
15
- s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Slugtastic}, %q{--main}, %q{README.md}]
16
- s.require_paths = [%q{lib}]
17
- s.rubyforge_project = %q{slugtastic}
18
- s.rubygems_version = %q{1.8.6}
19
- s.summary = %q{A simple slug string generator for ActiveRecord. Will populate a slug attribute from another attribute.}
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "slugtastic"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Slugtastic::VERSION
20
17
 
21
- if s.respond_to? :specification_version then
22
- s.specification_version = 3
23
-
24
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
- else
26
- end
27
- else
28
- end
18
+ gem.add_development_dependency "rake"
19
+ gem.add_development_dependency "rspec"
20
+ gem.add_development_dependency "supermodel"
29
21
  end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ class Model < SuperModel::Base
5
+ include ActiveModel::Validations::Callbacks
6
+ extend Slugtastic::ModelAdditions
7
+ attr_accessor :slug, :title
8
+ has_slug :slug, from: :title
9
+ end
10
+
11
+ describe Slugtastic::ModelAdditions do
12
+ it "generates a slug from the title" do
13
+ Model.create!(:title => "A Simple Title").slug.should eq "a_simple_title"
14
+ end
15
+
16
+ it "doesn't regenerate the slug if it already exists" do
17
+ model = Model.create!(:title => "A Simple Title")
18
+ model.slug.should eq "a_simple_title"
19
+
20
+ model.title = "A new title"
21
+ model.save
22
+ model.slug.should eq "a_simple_title"
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Slugtastic do
5
+ describe ".generate_slug" do
6
+ it "generates a slug from a simple string" do
7
+ Slugtastic.generate_slug("A simple string.").should eq "a_simple_string"
8
+ end
9
+
10
+ it "handles strings with hypens in them" do
11
+ Slugtastic.generate_slug("A string - with Hyphens").should eq "a_string_-_with_hyphens"
12
+ end
13
+
14
+ it "handles strings with other characters in them" do
15
+ Slugtastic.generate_slug("A string, with /All sorts!").should eq "a_string_with_all_sorts"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,2 @@
1
+ require "slugtastic"
2
+ require "supermodel"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slugtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,32 +9,85 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-08 00:00:00.000000000Z
13
- dependencies: []
12
+ date: 2012-08-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: supermodel
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
14
62
  description: A simple slug string generator for ActiveRecord. Will populate a slug
15
63
  attribute from another attribute.
16
- email: danbee@gmail.com
64
+ email:
65
+ - danbee@gmail.com
17
66
  executables: []
18
67
  extensions: []
19
- extra_rdoc_files:
20
- - README.md
21
- - lib/slugtastic.rb
68
+ extra_rdoc_files: []
22
69
  files:
23
- - Manifest
70
+ - .gitignore
71
+ - .rspec
72
+ - .travis.yml
73
+ - CHANGELOG.md
74
+ - Gemfile
75
+ - Gemfile.lock
76
+ - LICENSE
24
77
  - README.md
25
78
  - Rakefile
26
79
  - lib/slugtastic.rb
80
+ - lib/slugtastic/model_additions.rb
81
+ - lib/slugtastic/railtie.rb
82
+ - lib/slugtastic/version.rb
27
83
  - slugtastic.gemspec
28
- homepage: http://github.com/danbee/slugtastic
84
+ - spec/slugtastic/model_additions_spec.rb
85
+ - spec/slugtastic_spec.rb
86
+ - spec/spec_helper.rb
87
+ homepage: ''
29
88
  licenses: []
30
89
  post_install_message:
31
- rdoc_options:
32
- - --line-numbers
33
- - --inline-source
34
- - --title
35
- - Slugtastic
36
- - --main
37
- - README.md
90
+ rdoc_options: []
38
91
  require_paths:
39
92
  - lib
40
93
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -48,12 +101,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
101
  requirements:
49
102
  - - ! '>='
50
103
  - !ruby/object:Gem::Version
51
- version: '1.2'
104
+ version: '0'
52
105
  requirements: []
53
- rubyforge_project: slugtastic
54
- rubygems_version: 1.8.6
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.23
55
108
  signing_key:
56
109
  specification_version: 3
57
- summary: A simple slug string generator for ActiveRecord. Will populate a slug attribute
58
- from another attribute.
59
- test_files: []
110
+ summary: A simple slug string generator for ActiveRecord.
111
+ test_files:
112
+ - spec/slugtastic/model_additions_spec.rb
113
+ - spec/slugtastic_spec.rb
114
+ - spec/spec_helper.rb
data/Manifest DELETED
@@ -1,5 +0,0 @@
1
- Manifest
2
- README.md
3
- Rakefile
4
- lib/slugtastic.rb
5
- slugtastic.gemspec