rails_wordpress 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26c9cbe468139bdc697a8ed2d623bba973506e06
4
- data.tar.gz: dcd3ea5a124976ad4adfdaac991f990ab77d50c7
3
+ metadata.gz: 6ee0d57a8966d225223ff18869a2e81c735ebc56
4
+ data.tar.gz: f0ecd9be49dc5badfd80ed0525e6413e9bbc03d4
5
5
  SHA512:
6
- metadata.gz: 58ee806b386870cc40ad7b31ffebcc0b7d0fc28c7853cfb1587ccbd48ce2d19f2df554ae8741212e2135497999599c633968d09135dd9f0fcd247f6bf5d8af12
7
- data.tar.gz: 2403cc0d01ef9f1f8d017759426eac329a1383e728cd96265e52b571eeef164aee4045b4a09824465bb2bfb31ad9b3483867c07bdb397bcc7e8827abc165f729
6
+ metadata.gz: a76e4bd8652518071dee77ebc36e367baec5dbe54d59ac6097259a92beac2c95529a14fd164b88a732055c9c0827dc0f34a55850f09691cbb519dcfb44a5c92d
7
+ data.tar.gz: 840b390de30678de537f3221a6f9396ce15f61ec400d187e3d740a7c28345182d7e35551c9fa16205d43bb4e2aa82ea50de3fe3337ab9af0e3f79310b0980da8
@@ -1,5 +1,5 @@
1
1
  module Wordpress
2
- class Attachment < ActiveRecord::Base
2
+ class Attachment < WpPost
3
3
  def default_mime_type
4
4
  'image/png'
5
5
  end
@@ -1,4 +1,5 @@
1
1
  module Wordpress
2
2
  class Post < WpPost
3
+ validates :post_title, presence: true
3
4
  end
4
5
  end
@@ -2,11 +2,11 @@ module Wordpress
2
2
  class WpPost < ActiveRecord::Base
3
3
  self.table_name = 'wp_posts'
4
4
  self.inheritance_column = 'post_type'
5
-
5
+
6
6
  before_create :set_defaults
7
7
  before_save :touch_values
8
8
  after_save :save_relationships
9
-
9
+
10
10
  scope :published, -> { where(post_status: "publish") }
11
11
  scope :descending, -> { order(post_modified: :desc, id: :desc) }
12
12
  scope :recent, -> (count = 10) { descending.limit(count) }
@@ -16,7 +16,8 @@ module Wordpress
16
16
  has_many :relationships, foreign_key: "object_id"
17
17
  has_many :tags, class_name: "PostTag", through: :relationships, source: :taxonomy, :dependent => :destroy
18
18
  has_many :categories, class_name: "Category", through: :relationships, source: :taxonomy, :dependent => :destroy
19
-
19
+ has_many :wp_postmetas, class_name: "WpPostmeta", foreign_key: "post_id"
20
+
20
21
  belongs_to :author, class_name: "User", foreign_key: "post_author"
21
22
 
22
23
  def self.find_sti_class type_name
@@ -55,7 +56,7 @@ module Wordpress
55
56
  result.post_categories = params[:post_categories] if params[:post_categories]
56
57
  result
57
58
  end
58
-
59
+
59
60
  def latest_revision
60
61
  revisions.descending.first || self
61
62
  end
@@ -71,15 +72,15 @@ module Wordpress
71
72
  def excerpt
72
73
  latest_revision.post_excerpt
73
74
  end
74
-
75
+
75
76
  def created_at
76
77
  self.post_date
77
78
  end
78
-
79
+
79
80
  def updated_at
80
81
  latest_revision.post_modified
81
82
  end
82
-
83
+
83
84
  def set_defaults
84
85
  p = self.parent
85
86
  self.author = self.parent.try(:author) || User.first
@@ -93,7 +94,7 @@ module Wordpress
93
94
  content = (self.post_content || self.parent.try(:post_content)).to_s
94
95
  self.post_excerpt = content.length >= 512 ? "#{content.slice(0, 512)}..." : content \
95
96
  unless self.post_content_changed?
96
-
97
+
97
98
  self.to_ping = '' unless self.to_ping_changed?
98
99
  self.pinged = '' unless self.pinged_changed?
99
100
  self.post_content_filtered = '' unless self.post_content_filtered_changed?
@@ -102,7 +103,7 @@ module Wordpress
102
103
  def first_revision
103
104
  self.parent || self
104
105
  end
105
-
106
+
106
107
  def touch_values
107
108
  self.post_modified = Time.now unless self.post_modified_changed?
108
109
  self.post_modified_gmt = self.post_modified.utc unless self.post_modified_gmt_changed?
@@ -113,9 +114,9 @@ module Wordpress
113
114
  return if self.first_revision == self
114
115
  self.first_revision.tags.each{|item| item.destroy if item.marked_for_destruction? }
115
116
  self.first_revision.categories.each{|item| item.destroy if item.marked_for_destruction? }
116
- self.first_revision.save
117
+ self.first_revision.save
117
118
  end
118
-
119
+
119
120
  def tag_names
120
121
  first_revision.tags.map(&:name)
121
122
  end
@@ -127,11 +128,11 @@ module Wordpress
127
128
  def category_names
128
129
  first_revision.categories.map(&:name)
129
130
  end
130
-
131
+
131
132
  def category_slugs
132
133
  first_revision.categories.map(&:slug)
133
134
  end
134
-
135
+
135
136
  def created_at
136
137
  first_revision.post_date
137
138
  end
@@ -143,7 +144,7 @@ module Wordpress
143
144
  first_revision.categories.include? category
144
145
  end
145
146
  end
146
-
147
+
147
148
  def post_tags
148
149
  first_revision.tags.map(&:name).join(",")
149
150
  end
@@ -152,10 +153,10 @@ module Wordpress
152
153
  tag_names = tag_names.split(",").map{ |name| name.strip } unless tag_names.is_a?(Array)
153
154
  tags_to_assign = tag_names.map{ |tag_name| PostTag.find_or_create(tag_name) }
154
155
  new_tags = tags_to_assign.reject{ |tag| first_revision.tags.include?(tag) }
155
-
156
+
156
157
  first_revision.tags.each{ |tag| tag.mark_for_destruction unless tags_to_assign.include?(tag) }
157
158
  new_tags.each{ |tag| first_revision.relationships.build(taxonomy: tag) }
158
- end
159
+ end
159
160
 
160
161
  def post_categories
161
162
  first_revision.categories.map(&:name).join(",")
@@ -170,18 +171,18 @@ module Wordpress
170
171
  first_revision.relationships.build(taxonomy: category)
171
172
  end
172
173
  end
173
-
174
+
174
175
  def assign_category_names category_names
175
176
  category_ids = category_names.map{ |name| Category.find_or_create(name).id }.compact
176
177
  assign_category_ids category_ids
177
178
  end
178
-
179
+
179
180
  def post_categories= category_list
180
181
  # turn into an array of items unless already so
181
182
  unless category_list.is_a?(Array)
182
183
  category_list = category_list.to_s.split(",")
183
184
  .map{ |name| name.strip }
184
- .reject{|r| r.blank?}
185
+ .reject{|r| r.blank?}
185
186
  end
186
187
 
187
188
  # its an array of ids when #to_i => #to_s yields the same
@@ -190,6 +191,6 @@ module Wordpress
190
191
  else
191
192
  assign_category_names category_list
192
193
  end
193
- end
194
+ end
194
195
  end
195
196
  end
@@ -0,0 +1,8 @@
1
+ module Wordpress
2
+ class WpPostmeta < ActiveRecord::Base
3
+ self.table_name = 'wp_postmeta'
4
+
5
+ belongs_to :post
6
+
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Wordpress
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end