make_permalink 0.0.1 → 0.0.2

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/README.textile ADDED
@@ -0,0 +1,81 @@
1
+ h1. Simple make_permalink Gem
2
+
3
+ *make_permalink* is a simple gem that allows you to easily create permalinks (url-friendly-output) for methods in your objects. You don't need any database storage to make it work which is just awesome!
4
+
5
+ h1. Example
6
+
7
+ <pre>
8
+ class Post
9
+ make_permalink :title
10
+ end
11
+
12
+ p = Post.create(:title => "Hello World!")
13
+ p.permalink # => "1-hello-world"
14
+ </pre>
15
+
16
+ If you're using _rails_ and you want your url's to have the permalink and not only the id, just add the *to_param* method to your model
17
+
18
+ <pre>
19
+ class Post < ActiveRecord::Base
20
+ make_permalink :title
21
+
22
+ def to_param
23
+ permalink
24
+ end
25
+ end
26
+ </pre>
27
+
28
+ h1. Install
29
+
30
+ It's really simple to install this magnificent gem. Just run a small @gem install make_permalink@ and you've got it!
31
+
32
+ Well, not quite, you may have the gem installed in your system, but when you share the beautiful code you've created, people won't actually know that. So, that's when @Bundler@ appears.
33
+
34
+ Add @gem 'make_permalink'@ to your Gemfile and then run @bundle install@. Well, and remember to check your Gemfile in your repo.
35
+
36
+ h1. Options
37
+
38
+ h3. Non ascii characters
39
+
40
+ You can have a permalink that won't change non-ascii.
41
+
42
+ <tt> :replace_non_ascii </tt>: If set to false non-ascii chars won't be replaced. Default is true
43
+
44
+ <pre>
45
+ class Post
46
+ make_permalink :title, :replace_non_ascii => false
47
+ end
48
+
49
+ p = Post.create(:title => "Let's rock & roll")
50
+ p.permalink # => "1-let-s-rock-roll"
51
+ </pre>
52
+
53
+ Notice that if you don't replace non-ascii chars the permalik would be way cooler (thanks to the "stringex":https://github.com/svenfuchs/stringex gem)
54
+
55
+ <pre>
56
+ # You will get this with the default behavior
57
+ p.permalink # => "1-lets-rock-and-roll"
58
+ </pre>
59
+
60
+ h3. Remove id from permalink
61
+
62
+ I don't really like to have the ID of the object on the permalink, so I just added an option to remove it. Just call the method with *_:include_id => false_* and you're done!
63
+
64
+ <tt> :include_id </tt> is true by default but just change it to remove the id from the permalink.
65
+
66
+ Internally the gem will look for the *_create_permalink_prefix(boolean)_* method so if you want to change the prefix, just override that method and you'll be good to go in no time!
67
+
68
+ h1. Bugs/Contact
69
+
70
+ If you need to contact me about a bug or anythig, please open an issue "here":https://github.com/nhocki/make_permalink/issues
71
+
72
+ Also, feel free to patch it as needed, every fix/refactoring/extension is more than welcome!
73
+
74
+ h1. Contributors
75
+
76
+ Nicolás Hock ("nhocki":http://github.com/nhocki)
77
+ Federico Builes ("febuiles":http://github.com/febuiles)
78
+ Sven Fuchs ("svenfuchs":http://github.com/svenfuchs) for the Stringex gem
79
+
80
+
81
+ Copyright (c) 2011 Nicolás Hock Isaza, released under the MIT license
@@ -28,6 +28,22 @@ module MakePermalink
28
28
  }
29
29
  end
30
30
 
31
+
32
+ # Creates a permalink for a given object based on the method passed as
33
+ # parameter:
34
+ #
35
+ # You can modify the default behavior with this two options
36
+ #
37
+ # <tt>:include_id</tt>: This will include the objects id method. Default true.
38
+ # <tt>:replace_non_ascii</tt>: This will replace non-ascii-chars (like & and $) for their english words (and - dollars). Default true
39
+ #
40
+ # class Post < ActiveRecord::Base
41
+ # make_permalink :title
42
+ # end
43
+ #
44
+ # p = Post.create(:title => "Rock & Roll!")
45
+ # p.permalink # => "1-rock-and-roll"
46
+
31
47
  def make_permalink(method, options = {})
32
48
  define_method "permalink" do
33
49
  options = self.class.default_options.merge!(options)
@@ -1,3 +1,3 @@
1
1
  module MakePermalink
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: make_permalink
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Nicol\xC3\xA1s Hock Isaza"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-15 00:00:00 -05:00
13
+ date: 2011-02-16 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -47,6 +47,7 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - .gitignore
49
49
  - Gemfile
50
+ - README.textile
50
51
  - Rakefile
51
52
  - lib/make_permalink.rb
52
53
  - lib/make_permalink/base.rb
@@ -78,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
79
  requirements: []
79
80
 
80
81
  rubyforge_project: make_permalink
81
- rubygems_version: 1.5.2
82
+ rubygems_version: 1.5.0
82
83
  signing_key:
83
84
  specification_version: 3
84
85
  summary: Create dynamic permalinks from an attribute