acts_as_page 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module ActsAsPage
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/acts_as_page.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'globalize3'
2
2
  require 'friendly_id'
3
+ require 'models/page_part'
3
4
 
4
5
  module ActsAsPage
5
6
  def self.included(base)
@@ -9,10 +10,12 @@ module ActsAsPage
9
10
  module ClassMethods
10
11
  def acts_as_page
11
12
  extend FriendlyId
13
+ has_many :parts, class_name: 'PagePart'
14
+
12
15
  validates :title, presence: true, uniqueness: true
13
16
 
14
- attr_accessible :title, :body, :home, :meta_keywords, :meta_description
15
- translates :title, :body, :slug, :meta_keywords, :meta_description
17
+ attr_accessible :title, :home, :meta_keywords, :meta_description
18
+ translates :title, :slug, :meta_keywords, :meta_description
16
19
 
17
20
  friendly_id :title, use: [:slugged, :globalize]
18
21
  end
@@ -21,6 +24,27 @@ module ActsAsPage
21
24
  model.class.update_all(home: false)
22
25
  model.update_attribute(:home, true)
23
26
  end
27
+
28
+ #solution take from https://github.com/refinery/refinerycms/blob/2-0-stable/pages/app/models/refinery/page.rb#L149-L159
29
+ def with_globalize(conditions = {})
30
+ conditions = {locale: ::Globalize.locale.to_s}.merge(conditions)
31
+ globalized_conditions = {}
32
+ conditions.keys.each do |key|
33
+ if (translated_attribute_names.map(&:to_s) | %w(locale)).include?(key.to_s)
34
+ globalized_conditions["#{self.translation_class.table_name}.#{key}"] = conditions.delete(key)
35
+ end
36
+ end
37
+ joins(:translations).where(globalized_conditions).where(conditions).readonly(false)
38
+ end
39
+ end
40
+
41
+ def method_missing(name)
42
+ part = parts.with_globalize(title: name.to_s.downcase.underscore).first
43
+ if part
44
+ return part
45
+ else
46
+ super(name)
47
+ end
24
48
  end
25
49
  end
26
50
 
@@ -0,0 +1,7 @@
1
+ class PagePart < ActiveRecord::Base
2
+ validates :title, presence: true
3
+
4
+ attr_accessible :title, :body
5
+
6
+ translates :title, :body
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_page
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-17 00:00:00.000000000 Z
12
+ date: 2013-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -117,6 +117,7 @@ files:
117
117
  - lib/tasks/acts_as_page_tasks.rake
118
118
  - lib/acts_as_page/version.rb
119
119
  - lib/acts_as_page.rb
120
+ - lib/models/page_part.rb
120
121
  - MIT-LICENSE
121
122
  - Rakefile
122
123
  - README.rdoc