slugtastic 0.2.0 → 0.2.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.2.1
2
+
3
+ * Added basic transliteration with IConv.
4
+
1
5
  ## v0.2.0
2
6
 
3
7
  * Rebuild of gem using bundler.
@@ -1,6 +1,14 @@
1
1
  module Slugtastic
2
2
  module ModelAdditions
3
3
 
4
+ # To generate a slug from another value, call <tt>has_slug</tt> in any
5
+ # ActiveRecord model and pass in the name of the slug attribute.
6
+ # By default the slug will be generated from the <tt>title</tt> attribute, but
7
+ # you can specify by adding <tt>:from => {attribute}</tt>.
8
+ #
9
+ # class Article < ActiveRecord::Base
10
+ # has_slug :slug, :from => :title
11
+ # end
4
12
  def has_slug name, options = { :from => :title }
5
13
  before_validation do |record|
6
14
  send("#{name}=", Slugtastic.generate_slug(send(options[:from]))) if send(name).nil? or send(name).blank?
@@ -1,3 +1,3 @@
1
1
  module Slugtastic
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/slugtastic.rb CHANGED
@@ -2,8 +2,12 @@ require "slugtastic/version"
2
2
  require "slugtastic/model_additions"
3
3
  require "slugtastic/railtie" if defined? Rails
4
4
 
5
+ # TODO: iconv will be deprecated in the future.
6
+ require 'iconv'
7
+
5
8
  module Slugtastic
6
9
  def self.generate_slug(string)
7
- string.downcase.gsub(/ /, '_').gsub(/[^a-z0-9\-_]/, '') unless string.nil?
10
+ return if string.nil?
11
+ Iconv.iconv("ASCII//TRANSLIT//IGNORE", "UTF-8", string).join.downcase.gsub(/ /, '_').gsub(/[^a-z0-9\-_]/, '')
8
12
  end
9
13
  end
@@ -3,6 +3,10 @@ require 'spec_helper'
3
3
 
4
4
  describe Slugtastic do
5
5
  describe ".generate_slug" do
6
+ it "returns empty if the input string is empty" do
7
+ Slugtastic.generate_slug("").should eq ""
8
+ end
9
+
6
10
  it "generates a slug from a simple string" do
7
11
  Slugtastic.generate_slug("A simple string.").should eq "a_simple_string"
8
12
  end
@@ -14,5 +18,10 @@ describe Slugtastic do
14
18
  it "handles strings with other characters in them" do
15
19
  Slugtastic.generate_slug("A string, with /All sorts!").should eq "a_string_with_all_sorts"
16
20
  end
21
+
22
+ it "handles basic transliteration" do
23
+ Slugtastic.generate_slug("Un été À la maison.").should eq "un_ete_a_la_maison"
24
+ Slugtastic.generate_slug("Ātri brūna lapsa").should eq "atri_bruna_lapsa"
25
+ end
17
26
  end
18
27
  end
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.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: