page_parts 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -5,14 +5,22 @@ Enable page parts in your model
5
5
  == Install
6
6
 
7
7
  gem "page_parts"
8
-
8
+
9
+ ActiveRecord:
10
+
11
+ require 'page_parts/orm/active_record'
12
+
9
13
  rake page_parts_engine:install:migrations
10
14
 
15
+ Mongoid:
16
+
17
+ require 'page_parts/orm/mongoid'
18
+
11
19
  == Usage
12
20
 
13
21
  class Category < ActiveRecord::Base
14
- include PageParts::ActiveRecordExtension
15
-
22
+ include PageParts::Extension
23
+
16
24
  validates_presence_of :title
17
25
 
18
26
  page_parts :content, :sidebar
@@ -33,4 +41,4 @@ Generates main_ru, main_en, main_uk, left_ru ...
33
41
 
34
42
  rake test
35
43
 
36
- Copyright (c) 2011 Aimbulance, released under the MIT license
44
+ Copyright (c) 2012 Fodojo, released under the MIT license
@@ -1,7 +1,7 @@
1
1
  require 'active_support/concern'
2
2
 
3
3
  module PageParts
4
- module ActiveRecordExtension
4
+ module Extension
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
@@ -43,7 +43,6 @@ module PageParts
43
43
  # Find page part by key or build new record
44
44
  def find_or_build_page_part(attr_name)
45
45
  key = normalize_page_part_key(attr_name)
46
- #self.page_parts.where(:key => key).first || self.page_parts.build(:key => key)
47
46
  self.page_parts.detect { |record| record.key.to_s == key } || self.page_parts.build(:key => key)
48
47
  end
49
48
 
@@ -5,4 +5,4 @@ class PagePart < ::ActiveRecord::Base
5
5
  validates_uniqueness_of :key, :scope => [:partable_type, :partable_id]
6
6
 
7
7
  attr_accessible :key, :content
8
- end
8
+ end
@@ -0,0 +1,20 @@
1
+ require 'mongoid'
2
+
3
+ class PagePart
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+
7
+ # Columns
8
+ field :key, :type => String, :null => false
9
+ field :content, :type => String
10
+
11
+ index({:key => 1})
12
+
13
+ # Relations
14
+ belongs_to :partable, :polymorphic => true, :index => true
15
+
16
+ validates_presence_of :key, :partable_type
17
+ validates_uniqueness_of :key, :scope => [:partable_type, :partable_id]
18
+
19
+ attr_accessible :key, :content
20
+ end
@@ -0,0 +1,2 @@
1
+ require 'orm_adapter/adapters/active_record'
2
+ require 'page_parts/models/active_record/page_part'
@@ -0,0 +1,2 @@
1
+ require 'orm_adapter/adapters/mongoid'
2
+ require 'page_parts/models/mongoid/page_part'
@@ -1,3 +1,3 @@
1
1
  module PageParts
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/page_parts.rb CHANGED
@@ -1,5 +1,7 @@
1
+ require 'orm_adapter'
2
+
1
3
  module PageParts
2
- autoload :ActiveRecordExtension, "page_parts/active_record_extension"
4
+ autoload :Extension, "page_parts/extension"
3
5
  end
4
6
 
5
7
  require 'page_parts/engine'
@@ -1,5 +1,5 @@
1
1
  class Category < ActiveRecord::Base
2
- include PageParts::ActiveRecordExtension
2
+ include PageParts::Extension
3
3
 
4
4
  validates_presence_of :title
5
5
 
@@ -1,5 +1,5 @@
1
1
  class Post < ActiveRecord::Base
2
- include PageParts::ActiveRecordExtension
2
+ include PageParts::Extension
3
3
 
4
4
  page_parts :title, :content, :suffix => [:ru, :en, :uk]
5
5
  end
@@ -1,25 +1,3 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3
3
- #
4
- # Ensure the SQLite 3 gem is defined in your Gemfile
5
- # gem 'sqlite3'
6
- development:
7
- adapter: sqlite3
8
- database: db/development.sqlite3
9
- pool: 5
10
- timeout: 5000
11
-
12
- # Warning: The database defined as "test" will be erased and
13
- # re-generated from your development database when you run "rake".
14
- # Do not set this db to the same as development or production.
15
1
  test:
16
2
  adapter: sqlite3
17
- database: db/test.sqlite3
18
- pool: 5
19
- timeout: 5000
20
-
21
- production:
22
- adapter: sqlite3
23
- database: db/production.sqlite3
24
- pool: 5
25
- timeout: 5000
3
+ database: db/page_parts_test.db
@@ -0,0 +1,2 @@
1
+ # Load ORM
2
+ require 'page_parts/orm/active_record'
Binary file