Started on cms page import

* created rake tasks
* still needed: cleanups, more tests and docs
This commit is contained in:
Marc Remolt
2011-06-03 18:50:27 +02:00
parent dacd503d8f
commit e1c60163e4
4 changed files with 73 additions and 9 deletions

View File

@@ -19,10 +19,13 @@ module Refinery
end
end
def pages
doc.xpath("//item[wp:post_type = 'page']").collect do |page|
def pages(only_published=false)
pages = doc.xpath("//item[wp:post_type = 'page']").collect do |page|
Page.new(page)
end
pages = pages.select(&:published?) if only_published
pages
end
def posts(only_published=false)

View File

@@ -36,7 +36,6 @@ module Refinery
# [ruby]p "Hello World"[/ruby]
# -> <pre class="brush: ruby">p "Hello world"</pre>
formatted.gsub!(/\[(\w+)\](.+?)\[\/\1\]/m, '<pre class="brush: \1">\2</pre>')
#formatted.gsub!(/\[\/\w+\]/, '</pre>')
# remove all tags inside <pre> that simple_format created
# TODO: replace simple_format with a method, that ignores pre-tags
@@ -60,7 +59,8 @@ module Refinery
end
def parent_id
node.xpath("wp:post_parent").text.to_i
dump_id = node.xpath("wp:post_parent").text.to_i
dump_id == 0 ? nil : dump_id
end
def status
@@ -80,8 +80,8 @@ module Refinery
end
def to_refinery
page = ::Page.create!(:title => title, :created_at => post_date,
:draft => draft?, :parent_id => parent_id)
page = ::Page.create!(:id => post_id, :title => title,
:created_at => post_date, :draft => draft?)
page.parts.create(:title => 'Body', :body => content_formatted)
page
@@ -95,7 +95,6 @@ module Refinery
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
#text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
text.insert 0, start_tag
text.html_safe.safe_concat("</p>")

View File

@@ -61,6 +61,25 @@ module Refinery
post
end
def self.create_blog_page_if_necessary
# refinerycms wants a page at /blog, so let's make sure there is one
# taken from the original db seeds from refinery-blog
unless ::Page.where("link_url = ?", '/blog').exists?
page = ::Page.create(
:title => "Blog",
:link_url => "/blog",
:deletable => false,
:position => ((::Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
:menu_match => "^/blogs?(\/|\/.+?|)$"
)
::Page.default_parts.each do |default_page_part|
page.parts.create(:title => default_page_part, :body => nil)
end
end
end
end
end
end