acts_more_seo 0.1.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/CHANGELOG.rdoc ADDED
@@ -0,0 +1,2 @@
1
+ = Version 0.1.0
2
+ * Gem existence started
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Maciej Mensfeld
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,11 @@
1
+ CHANGELOG.rdoc
2
+ Gemfile
3
+ MIT-LICENSE
4
+ README.md
5
+ Rakefile
6
+ init.rb
7
+ lib/acts_more_seo.rb
8
+ lib/string_ext.rb
9
+ spec/acts_more_seo_spec.rb
10
+ spec/spec_helper.rb
11
+ Manifest
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Acts more SEO
2
+
3
+ ## Install
4
+
5
+ gem install acts_more_seo
6
+
7
+ and in your Gemfile:
8
+
9
+ gem 'acts_more_seo'
10
+
11
+ ## About
12
+
13
+ Gem makes your ActiveRecord models more SEO friendly. Changes URLs to look way better. You need to include `acts_more_seo` in your class declaration and you're ready to go. No other changes required.
14
+
15
+ ## Example
16
+
17
+ class CoolElement < ActiveRecord::Base
18
+ acts_more_seo :title
19
+ end
20
+
21
+ mod = CoolElement.create(:title => 'cool stuuf :)')
22
+ cool_element_path(mod) ===> cool_elements/12345-cool-stuff
23
+
24
+ ## Note on Patches/Pull Requests
25
+
26
+ * Fork the project.
27
+ * Make your feature addition or bug fix.
28
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
29
+ * Commit, do not mess with Rakefile, version, or history.
30
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
31
+ * Send me a pull request. Bonus points for topic branches.
32
+
33
+ ## Copyright
34
+
35
+ Copyright (c) 2011 Maciej Mensfeld. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('acts_more_seo', '0.1.0') do |p|
6
+ p.description = "Gem makes your ActiveRecord models more SEO friendly. Changes URL to look way better"
7
+ p.url = "https://github.com/mensfeld/acts_more_seo"
8
+ p.author = "Maciej Mensfeld"
9
+ p.email = "maciej@mensfeld.pl"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = ["rspec >=2.0.0", "active_record"]
12
+ end
13
+
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{acts_more_seo}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Maciej Mensfeld"]
9
+ s.cert_chain = ["/home/mencio/.cert_keys/gem-public_cert.pem"]
10
+ s.date = %q{2011-04-09}
11
+ s.description = %q{Gem makes your ActiveRecord models more SEO friendly. Changes URL to look way better}
12
+ s.email = %q{maciej@mensfeld.pl}
13
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.md", "lib/acts_more_seo.rb", "lib/string_ext.rb"]
14
+ s.files = ["CHANGELOG.rdoc", "Gemfile", "MIT-LICENSE", "README.md", "Rakefile", "init.rb", "lib/acts_more_seo.rb", "lib/string_ext.rb", "spec/acts_more_seo_spec.rb", "spec/spec_helper.rb", "Manifest", "acts_more_seo.gemspec"]
15
+ s.homepage = %q{https://github.com/mensfeld/acts_more_seo}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Acts_more_seo", "--main", "README.md"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{acts_more_seo}
19
+ s.rubygems_version = %q{1.5.2}
20
+ s.signing_key = %q{/home/mencio/.cert_keys/gem-private_key.pem}
21
+ s.summary = %q{Gem makes your ActiveRecord models more SEO friendly. Changes URL to look way better}
22
+
23
+ if s.respond_to? :specification_version then
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
28
+ s.add_development_dependency(%q<active_record>, [">= 0"])
29
+ else
30
+ s.add_dependency(%q<rspec>, [">= 2.0.0"])
31
+ s.add_dependency(%q<active_record>, [">= 0"])
32
+ end
33
+ else
34
+ s.add_dependency(%q<rspec>, [">= 2.0.0"])
35
+ s.add_dependency(%q<active_record>, [">= 0"])
36
+ end
37
+ end
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'acts_more_seo'
2
+
@@ -0,0 +1,40 @@
1
+ require "string_ext"
2
+
3
+ module Acts
4
+ module MoreSeo
5
+
6
+ def self.included(base)
7
+ base.extend AddActsAsMethod
8
+ end
9
+
10
+ module AddActsAsMethod
11
+ def acts_more_seo(seo_column = :name)
12
+ cattr_accessor :seo_column
13
+ self.seo_column = seo_column
14
+ class_eval <<-END
15
+ include Acts::MoreSeo::InstanceMethods
16
+ END
17
+ end
18
+ end
19
+
20
+ # Istance methods
21
+ module InstanceMethods
22
+
23
+ # Overwrite default to_param - should return nice url
24
+ def to_param
25
+ self.url
26
+ end
27
+
28
+ # Lets return nice and smooth url
29
+ def url
30
+ seo = self.send(self.class.seo_column)
31
+ seo ? "#{self.id}-#{seo.to_url}" : self.id
32
+ end
33
+
34
+ module ClassMethods
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ ActiveRecord::Base.send(:include, Acts::MoreSeo)
data/lib/string_ext.rb ADDED
@@ -0,0 +1,57 @@
1
+ # coding: utf-8
2
+
3
+ # Required string extensions
4
+
5
+ class String
6
+ # Removes any "not url friendly" stuff and returns "pure" url
7
+ def to_url
8
+ temp = self.downcase
9
+ temp
10
+ temp.gsub!(/[âäàãáäå�?ăąǎǟǡǻ�?ȃȧẵặ]/,'a')
11
+ temp.gsub!(/[ëêéèẽēĕėẻȅȇẹȩęḙḛ�?ếễểḕḗệ�?]/,'e')
12
+ temp.gsub!(/[�?iìíîĩīĭïỉ�?ịįȉȋḭɨḯ]/,'i')
13
+ temp.gsub!(/[òóôõ�?�?ȯö�?őǒ�?�?ơǫ�?ɵøồốỗổȱȫȭ�?�?ṑṓ�?ớỡởợǭộǿ]/,'o')
14
+ temp.gsub!(/[ùúûũūŭüủůűǔȕȗưụṳųṷṵṹṻǖǜǘǖǚừứữửự]/,'u')
15
+ temp.gsub!(/[ỳýŷỹȳ�?ÿỷẙƴỵ]/,'y')
16
+ temp.gsub!(/[ñǹń]/,'n')
17
+ temp.gsub!(/[çć]/,'c')
18
+ temp.gsub!(/[ß]/,'ss')
19
+ temp.gsub!(/[œ]/,'oe')
20
+ temp.gsub!(/[ij]/,'ij')
21
+ temp.gsub!(/[�?ł]/,'l')
22
+ temp.gsub!(/[ś]/,'s')
23
+ temp.gsub!(/[źż]/,'z')
24
+ temp.gsub!(/[^a-zA-Z 0-9]/, "")
25
+ temp.gsub!(/\s/,'-')
26
+ temp.gsub!(/\-+$/,'')
27
+ temp.gsub!(/^\-+/,'')
28
+ temp
29
+ end
30
+
31
+ def to_url!
32
+ self.replace self.to_url
33
+ end
34
+
35
+ # Change new line to html <br/>
36
+ def nl2br
37
+ self.gsub("\n\r","<br>").gsub("\r", "").gsub("\n", "<br />")
38
+ end
39
+
40
+ def nl2br!
41
+ self.replace self.nl2br
42
+ end
43
+
44
+ # Trim string to required length
45
+ def trim(length = 20, end_str = '...')
46
+ if self.length > length
47
+ return "#{self[0, length-end_str.length]}#{end_str}"
48
+ end
49
+ self
50
+ end
51
+
52
+ def trim!(length = 20, end_str = '...')
53
+ self.replace self.trim(length, end_str)
54
+ self
55
+ end
56
+
57
+ end
@@ -0,0 +1,62 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ ROOT = File.expand_path(File.dirname(__FILE__))
5
+
6
+ class CoolElement < ActiveRecord::Base
7
+ acts_more_seo
8
+ end
9
+
10
+ class CoolerElement < ActiveRecord::Base
11
+ acts_more_seo :title
12
+ end
13
+
14
+ describe CoolElement do
15
+ subject { CoolElement }
16
+
17
+ context "when there is no name" do
18
+ it "should return only id" do
19
+ a = subject.create
20
+ a.to_param.should eql(a.id)
21
+ end
22
+ end
23
+
24
+ context "when there is no name" do
25
+ it "should return nice url" do
26
+ a = subject.create(:name => 'bla bla bla')
27
+ a.to_param.should eql("#{a.id}-bla-bla-bla")
28
+ end
29
+
30
+ context "and there are some url-not-friendly letters" do
31
+ it "should remove them and return nice url" do
32
+ a = subject.create(:name => 'ą')
33
+ a.to_param.should eql("#{a.id}-aa")
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ describe CoolerElement do
40
+ subject { CoolerElement }
41
+
42
+ context "when there is no name" do
43
+ it "should return only id" do
44
+ a = subject.create
45
+ a.to_param.should eql(a.id)
46
+ end
47
+ end
48
+
49
+ context "when there is no name" do
50
+ it "should return nice url" do
51
+ a = subject.create(:title => 'bla bla bla')
52
+ a.to_param.should eql("#{a.id}-bla-bla-bla")
53
+ end
54
+
55
+ context "and there are some url-not-friendly letters" do
56
+ it "should remove them and return nice url" do
57
+ a = subject.create(:title => 'ą')
58
+ a.to_param.should eql("#{a.id}-aa")
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
5
+ require 'sqlite3'
6
+ require 'active_record'
7
+ require 'acts_more_seo'
8
+
9
+ ActiveRecord::Base.establish_connection(
10
+ :adapter => "sqlite3",
11
+ :database => ":memory:",
12
+ :encoding => 'utf8',
13
+ :collation => 'utf8_general_ci'
14
+ )
15
+
16
+ ActiveRecord::Schema.define do
17
+ create_table :cool_elements do |table|
18
+ table.string :name
19
+ end
20
+
21
+ create_table :cooler_elements do |table|
22
+ table.string :title
23
+ end
24
+ end
25
+
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ ��oq6 ��n�o�5��8R�ܲs�ƿ���?d�!+c. Y����5s����Iw��/=~X����>+��,^[���T�� `S<K������3��7f�8�z,QPBߔ2t���,��tt��̿�"�C�wi�)�Q�&9�e`�,�K$��q���(*卶����G�it�����
2
+ ���hR8��\y��˭L���I�/�1���I��S_�jUǿ²��q��:;��C�&��$9\��ȿ.�L�
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_more_seo
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Maciej Mensfeld
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - |
13
+ -----BEGIN CERTIFICATE-----
14
+ MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MQ8wDQYDVQQDDAZtYWNp
15
+ ZWoxGDAWBg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CP9lhQRT1KL7sxfznJlF7Y
31
+ BH3YFsdk
32
+ -----END CERTIFICATE-----
33
+
34
+ date: 2011-04-09 00:00:00 +02:00
35
+ default_executable:
36
+ dependencies:
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id001 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.0.0
46
+ type: :development
47
+ version_requirements: *id001
48
+ - !ruby/object:Gem::Dependency
49
+ name: active_record
50
+ prerelease: false
51
+ requirement: &id002 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :development
58
+ version_requirements: *id002
59
+ description: Gem makes your ActiveRecord models more SEO friendly. Changes URL to look way better
60
+ email: maciej@mensfeld.pl
61
+ executables: []
62
+
63
+ extensions: []
64
+
65
+ extra_rdoc_files:
66
+ - CHANGELOG.rdoc
67
+ - README.md
68
+ - lib/acts_more_seo.rb
69
+ - lib/string_ext.rb
70
+ files:
71
+ - CHANGELOG.rdoc
72
+ - Gemfile
73
+ - MIT-LICENSE
74
+ - README.md
75
+ - Rakefile
76
+ - init.rb
77
+ - lib/acts_more_seo.rb
78
+ - lib/string_ext.rb
79
+ - spec/acts_more_seo_spec.rb
80
+ - spec/spec_helper.rb
81
+ - Manifest
82
+ - acts_more_seo.gemspec
83
+ has_rdoc: true
84
+ homepage: https://github.com/mensfeld/acts_more_seo
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options:
89
+ - --line-numbers
90
+ - --inline-source
91
+ - --title
92
+ - Acts_more_seo
93
+ - --main
94
+ - README.md
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: "1.2"
109
+ requirements: []
110
+
111
+ rubyforge_project: acts_more_seo
112
+ rubygems_version: 1.5.2
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Gem makes your ActiveRecord models more SEO friendly. Changes URL to look way better
116
+ test_files: []
117
+
metadata.gz.sig ADDED
Binary file