padrino-contrib 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of padrino-contrib might be problematic. Click here for more details.
- data/Rakefile +1 -1
- data/lib/padrino-contrib/orm/active_record/permalink.rb +8 -8
- data/lib/padrino-contrib/orm/active_record/permalink_i18n.rb +13 -6
- data/lib/padrino-contrib/orm/active_record/textile.rb +13 -6
- data/lib/padrino-contrib/orm/mongo_mapper/permalink.rb +7 -4
- data/lib/padrino-contrib/orm/mongo_mapper/search.rb +3 -4
- data/lib/padrino-contrib/version.rb +1 -1
- metadata +4 -4
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ end
|
|
10
10
|
|
11
11
|
desc "Bump version on github"
|
12
12
|
task :bump do
|
13
|
-
if `git status -s`.chomp
|
13
|
+
if `git status -s`.chomp != ""
|
14
14
|
version = Bundler.load_gemspec(Dir[File.expand_path('../*.gemspec', __FILE__)].first).version
|
15
15
|
sh "git add .; git commit -a -m \"Bump to version #{version}\""
|
16
16
|
else
|
@@ -17,10 +17,13 @@ module Padrino
|
|
17
17
|
module ClassMethods
|
18
18
|
def has_permalink(field)
|
19
19
|
include InstanceMethods
|
20
|
-
|
21
|
-
write_inheritable_attribute :permalink_field, field
|
20
|
+
@_permalink_field = field
|
22
21
|
before_save :generate_permalink
|
23
22
|
end
|
23
|
+
|
24
|
+
def permalink_field
|
25
|
+
@_permalink_field
|
26
|
+
end
|
24
27
|
end # ClassMethods
|
25
28
|
|
26
29
|
module InstanceMethods
|
@@ -30,11 +33,8 @@ module Padrino
|
|
30
33
|
|
31
34
|
protected
|
32
35
|
def generate_permalink
|
33
|
-
self.permalink = read_attribute(permalink_field).downcase.
|
34
|
-
|
35
|
-
gsub(/-+/, '-').
|
36
|
-
gsub(/-$/, '').
|
37
|
-
gsub(/^-/, '')
|
36
|
+
self.permalink = read_attribute(self.class.permalink_field).downcase.
|
37
|
+
gsub(/\W/, '-').gsub(/-+/, '-').gsub(/-$/, '').gsub(/^-/, '')
|
38
38
|
end
|
39
39
|
end # InstanceMethods
|
40
40
|
end # Permalink
|
@@ -42,4 +42,4 @@ module Padrino
|
|
42
42
|
end # Orm
|
43
43
|
end # Contrib
|
44
44
|
end # Padrino
|
45
|
-
::ActiveRecord::Base.extend(Padrino::Contrib::Orm::ActiveRecord::Permalink::ClassMethods)
|
45
|
+
::ActiveRecord::Base.extend(Padrino::Contrib::Orm::ActiveRecord::Permalink::ClassMethods)
|
@@ -17,9 +17,8 @@ module Padrino
|
|
17
17
|
module ClassMethods
|
18
18
|
def has_permalink(field, options={})
|
19
19
|
include InstanceMethods
|
20
|
-
|
21
|
-
|
22
|
-
write_inheritable_attribute :permalink_langs, options.delete(:langs)
|
20
|
+
@_permalink_field = field
|
21
|
+
@_permalink_langs = options.delete(:langs)
|
23
22
|
before_save :generate_permalinks
|
24
23
|
permalink_langs.each do |lang|
|
25
24
|
validates_uniqueness_of :"#{field}_#{lang}", options
|
@@ -34,6 +33,14 @@ module Padrino
|
|
34
33
|
name.gsub!(/\s+/, '-') # all spaces to dashes
|
35
34
|
name
|
36
35
|
end
|
36
|
+
|
37
|
+
def permalink_field
|
38
|
+
@_permalink_field
|
39
|
+
end
|
40
|
+
|
41
|
+
def permalink_langs
|
42
|
+
@_permalink_langs
|
43
|
+
end
|
37
44
|
end
|
38
45
|
|
39
46
|
module InstanceMethods
|
@@ -43,8 +50,8 @@ module Padrino
|
|
43
50
|
|
44
51
|
protected
|
45
52
|
def generate_permalinks
|
46
|
-
permalink_langs.each do |lang|
|
47
|
-
self.send(:"permalink_#{lang}=", self.class.permalink_for(read_attribute(:"#{permalink_field}_#{lang}")))
|
53
|
+
self.class.permalink_langs.each do |lang|
|
54
|
+
self.send(:"permalink_#{lang}=", self.class.permalink_for(read_attribute(:"#{self.class.permalink_field}_#{lang}")))
|
48
55
|
end
|
49
56
|
end
|
50
57
|
end # InstanceMethods
|
@@ -53,4 +60,4 @@ module Padrino
|
|
53
60
|
end # Orm
|
54
61
|
end # Contrib
|
55
62
|
end # Padrino
|
56
|
-
::ActiveRecord::Base.extend(Padrino::Contrib::Orm::ActiveRecord::PermalinkI18n::ClassMethods)
|
63
|
+
::ActiveRecord::Base.extend(Padrino::Contrib::Orm::ActiveRecord::PermalinkI18n::ClassMethods)
|
@@ -21,24 +21,31 @@ module Padrino
|
|
21
21
|
include InstanceMethods
|
22
22
|
options = fields.extract_options!
|
23
23
|
options.reverse_merge!(:internal_links => :blog)
|
24
|
-
|
25
|
-
|
26
|
-
write_inheritable_attribute :textile_options, options
|
24
|
+
@_textile_fields = fields
|
25
|
+
@_textile_options = options
|
27
26
|
before_save :generate_textile
|
28
27
|
end
|
28
|
+
|
29
|
+
def textile_fields
|
30
|
+
@_textile_fields
|
31
|
+
end
|
32
|
+
|
33
|
+
def textile_options
|
34
|
+
@_textile_options
|
35
|
+
end
|
29
36
|
end
|
30
37
|
|
31
38
|
module InstanceMethods
|
32
39
|
protected
|
33
40
|
def generate_textile
|
34
|
-
textile_fields.each do |textile_field|
|
41
|
+
self.class.textile_fields.each do |textile_field|
|
35
42
|
next if read_attribute(textile_field).blank?
|
36
43
|
html = RedCloth.new(read_attribute(textile_field)).to_html
|
37
44
|
# Parse internal links
|
38
45
|
html.gsub!(/\[\[([^\]]+)\]\]/) do
|
39
46
|
page, name = *$1.split("|") # this allow to rename link ex: [[Page Name|link me]]
|
40
47
|
name ||= page
|
41
|
-
"<a href=\"/#{
|
48
|
+
"<a href=\"/#{@_textile_options[:internal_links]}/#{Post.permalink_for(page.strip)}\">#{name.strip}</a>"
|
42
49
|
end
|
43
50
|
# Write content
|
44
51
|
self.send("#{textile_field}_html=", html)
|
@@ -50,4 +57,4 @@ module Padrino
|
|
50
57
|
end # Orm
|
51
58
|
end # Contrib
|
52
59
|
end # Padrino
|
53
|
-
::ActiveRecord::Base.extend(Padrino::Contrib::Orm::ActiveRecord::Textile::ClassMethods)
|
60
|
+
::ActiveRecord::Base.extend(Padrino::Contrib::Orm::ActiveRecord::Textile::ClassMethods)
|
@@ -18,8 +18,7 @@ module Padrino
|
|
18
18
|
|
19
19
|
module ClassMethods
|
20
20
|
def has_permalink(field)
|
21
|
-
|
22
|
-
write_inheritable_attribute :permalink_field, field
|
21
|
+
@_permalink_field = field
|
23
22
|
before_save :generate_permalink
|
24
23
|
validates_uniqueness_of field
|
25
24
|
key :permalink, String
|
@@ -31,6 +30,10 @@ module Padrino
|
|
31
30
|
gsub(/-$/, '').
|
32
31
|
gsub(/^-/, '')
|
33
32
|
end
|
33
|
+
|
34
|
+
def permalink_field
|
35
|
+
@_permalink_field
|
36
|
+
end
|
34
37
|
end
|
35
38
|
|
36
39
|
module InstanceMethods
|
@@ -40,7 +43,7 @@ module Padrino
|
|
40
43
|
|
41
44
|
protected
|
42
45
|
def generate_permalink
|
43
|
-
self.permalink = self.class.permalink_for(self[permalink_field])
|
46
|
+
self.permalink = self.class.permalink_for(self[self.class.permalink_field])
|
44
47
|
end
|
45
48
|
end # InstanceMethods
|
46
49
|
end # Permalink
|
@@ -48,4 +51,4 @@ module Padrino
|
|
48
51
|
end # Orm
|
49
52
|
end # Contrib
|
50
53
|
end # Padrino
|
51
|
-
::MongoMapper::Document.send(:include, Padrino::Contrib::Orm::MongoMapper::Permalink)
|
54
|
+
::MongoMapper::Document.send(:include, Padrino::Contrib::Orm::MongoMapper::Permalink)
|
@@ -19,14 +19,13 @@ module Padrino
|
|
19
19
|
|
20
20
|
module ClassMethods
|
21
21
|
def has_search(*fields)
|
22
|
-
|
23
|
-
write_inheritable_attribute :search_fields, fields
|
22
|
+
@_search_fields = fields
|
24
23
|
end
|
25
24
|
|
26
25
|
def search(text, options={})
|
27
26
|
if text
|
28
27
|
re = Regexp.new(Regexp.escape(text), 'i')
|
29
|
-
where =
|
28
|
+
where = @_search_fields.map { |field| "this.#{field}.match(#{re.inspect})" }.join(" || ")
|
30
29
|
options.merge!("$where" => where)
|
31
30
|
end
|
32
31
|
options.delete(:paginate) ? paginate(options) : all(options)
|
@@ -37,4 +36,4 @@ module Padrino
|
|
37
36
|
end # Orm
|
38
37
|
end # Contrib
|
39
38
|
end # Padrino
|
40
|
-
::MongoMapper::Document.send(:include, Padrino::Contrib::Orm::MongoMapper::Search)
|
39
|
+
::MongoMapper::Document.send(:include, Padrino::Contrib::Orm::MongoMapper::Search)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Davide D'Agostino
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-
|
20
|
+
date: 2011-08-31 00:00:00 +02:00
|
21
21
|
default_executable:
|
22
22
|
dependencies: []
|
23
23
|
|