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 +12 -4
- data/lib/page_parts/{active_record_extension.rb → extension.rb} +1 -2
- data/{app/models → lib/page_parts/models/active_record}/page_part.rb +1 -1
- data/lib/page_parts/models/mongoid/page_part.rb +20 -0
- data/lib/page_parts/orm/active_record.rb +2 -0
- data/lib/page_parts/orm/mongoid.rb +2 -0
- data/lib/page_parts/version.rb +1 -1
- data/lib/page_parts.rb +3 -1
- data/test/dummy/app/models/category.rb +1 -1
- data/test/dummy/app/models/post.rb +1 -1
- data/test/dummy/config/database.yml +1 -23
- data/test/dummy/config/initializers/page_parts.rb +2 -0
- data/test/dummy/db/page_parts_test.db +0 -0
- data/test/dummy/log/test.log +67 -836
- metadata +106 -59
- data/test/dummy/log/development.log +0 -0
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::
|
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)
|
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
|
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
|
|
@@ -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
|
data/lib/page_parts/version.rb
CHANGED
data/lib/page_parts.rb
CHANGED
@@ -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/
|
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
|
Binary file
|