Class: TranslationCms::Import::Post
- Inherits:
-
Base
- Object
- Base
- TranslationCms::Import::Post
show all
- Defined in:
- lib/translation_cms/import/post.rb
Instance Attribute Summary
Attributes inherited from Base
#created_count, #filename, #import_record, #updated_count, #xml
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #normalize_xml, #replace_img_urls, start, #start, #unpack
Instance Method Details
#build_params(node) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/translation_cms/import/post.rb', line 35
def build_params(node)
{
slug: node.at('slug').content,
category_slug: node.at('parent').content,
title: node.at('title').content,
description: node.at('description').content,
joined_tags: node.at('tags').content,
content: node.at('content').content,
published_at: node.at('date').content,
tag_title: node.at('meta_title').try(:content),
tag_description: node.at('description').content
}
end
|
#save_category(options) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/translation_cms/import/post.rb', line 15
def save_category(options)
category = ::Category.with_slug(options[:slug]).first || ::Category.new
category.title = options[:title]
category.slug = options[:slug]
category.save
end
|
#save_post(category_slug, options) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/translation_cms/import/post.rb', line 23
def save_post(category_slug, options)
options[:published_at] = options[:published_at].blank? ? Time.zone.now : Time.strptime(options[:published_at], '%s')
post = ::Post.with_slug(options[:slug]).first || ::Post.new
post.attributes = options
post.category_id = ::Category.with_slug(category_slug).first.try(:id)
post = replace_img_urls(post)
col_name = post.new_record? ? :created_count : :updated_count
send("#{col_name}=", send(col_name.to_s) + 1) if post.save
end
|
#track ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/translation_cms/import/post.rb', line 6
def track
@xml.xpath('//item').each do |item|
params = build_params(item.children)
category_slug = params.delete(:category_slug)
category_slug.blank? ? save_category(params) : save_post(category_slug, params)
end
end
|