padrino-contrib 0.0.1 → 0.0.2

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/README.rdoc CHANGED
@@ -8,6 +8,8 @@ This package includes a variety of add-on components for Padrino Framework:
8
8
  * orm_ar_translate - Translate for you your ActiveRecord columns
9
9
  * auto_locale - Switch for you automatically the I18n.locale
10
10
  * flash_session - Middleware that help you in passing your session in the URI, when it should be in the cookie.
11
+ * orm_mm_permalink - Generate permalink for a specified column on MongoMapper
12
+ * orm_mm_search - Full text search in MongoMapper in specified columns
11
13
 
12
14
  === Use
13
15
 
@@ -11,8 +11,8 @@
11
11
  # set :exceptions_page, :errors # => views/errors.haml/erb
12
12
  # set :redmine, :project => "My Bugs", :tracker => "Bugs", :priority => "High"
13
13
  # # Uncomment this for test in development
14
- # # disable :raise_errors
15
- # # disable :show_exceptions
14
+ # # disable :raise_errors
15
+ # # disable :show_exceptions
16
16
  # end
17
17
  #
18
18
  module Padrino
@@ -0,0 +1,50 @@
1
+ module Padrino
2
+ module Contrib
3
+ module Orm
4
+ module Mm
5
+ ##
6
+ # This module extend ActiveRecord.
7
+ #
8
+ # You need to to your model a column called +:permalink+
9
+ #
10
+ # then use +has_permalink :title like:
11
+ #
12
+ # class Page < ActiveRecord::Base
13
+ # has_permalink :page
14
+ # end
15
+ #
16
+ module Permalink
17
+ module ClassMethods
18
+ def has_permalink(field)
19
+ include InstanceMethods
20
+ class_inheritable_accessor :permalink_field
21
+ write_inheritable_attribute :permalink_field, field
22
+ before_save :generate_permalink
23
+ validates_uniqueness_of field
24
+ key :permalink, String
25
+ end
26
+
27
+ def permalink_for(name)
28
+ name.downcase.gsub(/\W/, '-').
29
+ gsub(/-+/, '-').
30
+ gsub(/-$/, '').
31
+ gsub(/^-/, '')
32
+ end
33
+ end
34
+
35
+ module InstanceMethods
36
+ def to_param
37
+ permalink
38
+ end
39
+
40
+ protected
41
+ def generate_permalink
42
+ self.permalink = self.class.permalink_for(self[permalink_field])
43
+ end
44
+ end # InstanceMethods
45
+ end # Permalink
46
+ end # Mm
47
+ end # Orm
48
+ end # Contrib
49
+ end # Padrino
50
+ MongoMapper::Document.append_extensions(Padrino::Contrib::Orm::Mm::Permalink::ClassMethods)
@@ -0,0 +1,38 @@
1
+ module Padrino
2
+ module Contrib
3
+ module Orm
4
+ module Mm
5
+ module Search
6
+ ##
7
+ # This module provides full text search in specified fileds with pagination support.
8
+ #
9
+ # == Examples
10
+ #
11
+ # # model.rb
12
+ # has_search :title, :body
13
+ #
14
+ # # controller.rb
15
+ # Model.search("some thing")
16
+ # Model.search("some thing", :order => "position", :page => (params[:page] || 1), :draft => false, :paginate => true)
17
+ #
18
+ module ClassMethods
19
+ def has_search(*fields)
20
+ class_inheritable_accessor :search_fields
21
+ write_inheritable_attribute :search_fields, fields
22
+ end
23
+
24
+ def search(text, options={})
25
+ if text
26
+ re = Regexp.new(Regexp.escape(text), 'i').to_json
27
+ where = search_fields.map { |field| "this.#{field}.match(#{re})" }.join(" || ")
28
+ options.merge!("$where" => where)
29
+ end
30
+ options.delete(:paginate) ? paginate(options) : all(options)
31
+ end
32
+ end
33
+ end # Permalink
34
+ end # Mm
35
+ end # Orm
36
+ end # Contrib
37
+ end # Padrino
38
+ MongoMapper::Document.append_extensions(Padrino::Contrib::Orm::Mm::Search::ClassMethods)
@@ -6,7 +6,7 @@
6
6
  #
7
7
  module Padrino
8
8
  module Contrib
9
- VERSION = '0.0.1' unless defined?(Padrino::Contrib::VERSION)
9
+ VERSION = '0.0.2' unless defined?(Padrino::Contrib::VERSION)
10
10
  ##
11
11
  # Return the current Padrino version
12
12
  #
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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Padrino Team
@@ -42,6 +42,8 @@ files:
42
42
  - lib/padrino-contrib/orm/ar/permalink_i18n.rb
43
43
  - lib/padrino-contrib/orm/ar/textile.rb
44
44
  - lib/padrino-contrib/orm/ar/translate.rb
45
+ - lib/padrino-contrib/orm/mm/permalink.rb
46
+ - lib/padrino-contrib/orm/mm/search.rb
45
47
  - lib/padrino-contrib/version.rb
46
48
  has_rdoc: true
47
49
  homepage: http://www.padrinorb.com