Skip to content

Commit

Permalink
Renamed generator and made it add FriendlyId's Rake task. Tweaked ini…
Browse files Browse the repository at this point in the history
…t and

require statement for slug.rb to make it work in both plugin and Gem contexts.
  • Loading branch information
Norman Clarke committed Dec 16, 2008
1 parent 2981801 commit 5ef48c1
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 22 deletions.
10 changes: 6 additions & 4 deletions Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@ Rakefile
coverage/index.html
coverage/lib-friendly_id-non_sluggable_class_methods_rb.html
coverage/lib-friendly_id-non_sluggable_instance_methods_rb.html
coverage/lib-friendly_id-shoulda_macros_rb.html
coverage/lib-friendly_id-sluggable_class_methods_rb.html
coverage/lib-friendly_id-sluggable_instance_methods_rb.html
coverage/lib-friendly_id-string_helpers_rb.html
coverage/lib-friendly_id_rb.html
coverage/lib-slug_rb.html
coverage/rails-init_rb.html
generators/friendly_id_migration/friendly_id_migration_generator.rb
generators/friendly_id_migration/templates/create_slugs.rb
friendly_id.gemspec
generators/friendly_id/friendly_id_generator.rb
generators/friendly_id/templates/create_slugs.rb
init.rb
lib/friendly_id.rb
lib/friendly_id/non_sluggable_class_methods.rb
lib/friendly_id/non_sluggable_instance_methods.rb
lib/friendly_id/shoulda_macros.rb
lib/friendly_id/slug.rb
lib/friendly_id/sluggable_class_methods.rb
lib/friendly_id/sluggable_instance_methods.rb
lib/friendly_id/version.rb
lib/slug.rb
lib/tasks/friendly_id.rake
lib/tasks/friendly_id.rb
rails/init.rb
test/database.yml
test/fixtures/countries.yml
test/fixtures/country.rb
Expand Down
23 changes: 9 additions & 14 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -197,27 +197,30 @@ discouraged:

== Setting it up

FriendlyId currently works with Rails 2.0.0 and higher.
FriendlyId currently works with Rails 2.0.0 and higher. Here's how to set it up.

Here's how to set it up:
1) Install the Gem:

sudo gem install friendly-id
cd my_app
script/generate friendly_id
rake db:migrate

Now add the following 2 lines to bottom of your Rakefile:
2) Load FriendlyId in your app:

# Rails 2.1 and higher; add this to the gem section of environment.rb:
config.gem "friendly_id"

# Rails 2.0; this goes at the bottom of environment.rb
require 'friendly_id'
require 'tasks/friendly_id'

Now add some code to your models:
3) Add some code to your models:

class Post < ActiveRecord::Base
has_friendly_id :title, :use_slug => true
end

If you are using slugs, you can use a Rake task to generate slugs for your
4) If you are using slugs, you can use a Rake task to generate slugs for your
existing records:

friendly_id:make_slugs MODEL=MyModelName
Expand All @@ -231,14 +234,6 @@ The default is to remove dead slugs older than 45 days, but is configurable:

rake:friendly_id:remove_old_slugs MODEL=MyModelName DAYS=60

Note that having to explicitly add the friendly_id rake tasks to the Rakefile
is a pain in the ass. This is because Rails does not have any provisions for
accessing rake tasks from Gem plugins - even though it can do this for
generators. There is {a ticket sitting waiting on
Lighthouse}[http://rails.lighthouseapp.com/projects/8994/tickets/59] since
April of 2008 asking the Rails team to fix this, but it appears no agreement
can be reached on how to proceed and so we still don't have this functionality
as of December 2008.

== Hacking FriendlyId:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
class FriendlyIdMigrationGenerator < Rails::Generator::Base
class FriendlyIdGenerator < Rails::Generator::Base
def manifest
record do |m|
unless options[:skip_migration]
m.migration_template(
'create_slugs.rb', 'db/migrate', :migration_file_name => 'create_slugs'
)
m.file "/../../../lib/tasks/friendly_id.rake", "lib/tasks/friendly_id.rake"
end
end
end
Expand Down
1 change: 1 addition & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'friendly_id'
1 change: 1 addition & 0 deletions lib/friendly_id.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'unicode'
require 'friendly_id/slug'
require 'friendly_id/shoulda_macros'

# FriendlyId is a comprehensize Rails plugin/gem for slugging and permalinks.
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion rails/init.rb

This file was deleted.

2 changes: 1 addition & 1 deletion test/rails/2.x/config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run
ActiveRecord::Base.colorize_logging = false
require File.dirname(__FILE__) + '/../../../../rails/init.rb'
require File.dirname(__FILE__) + '/../../../../init.rb'
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
require 'active_record/fixtures'
require 'action_controller/test_process'
require 'sqlite3'
require 'slug'
require 'friendly_id/slug'

config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.establish_connection
Expand Down

0 comments on commit 5ef48c1

Please sign in to comment.