nijie: convert commentary to dtext.
This commit is contained in:
@@ -44,6 +44,28 @@ module Sources
|
||||
|
||||
protected
|
||||
|
||||
# XXX: duplicated from strategies/deviant_art.rb.
|
||||
def self.to_dtext(text)
|
||||
html = Nokogiri::HTML.fragment(text)
|
||||
|
||||
dtext = html.children.map do |element|
|
||||
case element.name
|
||||
when "text"
|
||||
element.content
|
||||
when "strong"
|
||||
"[b]#{to_dtext(element.inner_html)}[/b]" if element.inner_html.present?
|
||||
when "i"
|
||||
"[i]#{to_dtext(element.inner_html)}[/i]" if element.inner_html.present?
|
||||
when "s"
|
||||
"[s]#{to_dtext(element.inner_html)}[/s]" if element.inner_html.present?
|
||||
else
|
||||
to_dtext(element.inner_html)
|
||||
end
|
||||
end.join
|
||||
|
||||
dtext
|
||||
end
|
||||
|
||||
def get_commentary_from_page(page)
|
||||
title = page.search("h2.illust_title").text
|
||||
desc = page.search('meta[property="og:description"]').attr("content").value
|
||||
|
||||
@@ -70,5 +70,22 @@ module Sources
|
||||
assert_equal("莚", @site.artist_name)
|
||||
end
|
||||
end
|
||||
|
||||
context "The source site for a nijie gallery" do
|
||||
setup do
|
||||
@site = Sources::Site.new("http://nijie.info/view.php?id=218856")
|
||||
@site.get
|
||||
end
|
||||
|
||||
should "get the dtext-ified commentary" do
|
||||
desc = <<-EOS.strip_heredoc.chomp
|
||||
foo [b]bold[/b] [i]italics[/i] [s]strike[/s] red\r
|
||||
\r
|
||||
http://nijie.info/view.php?id=218944
|
||||
EOS
|
||||
|
||||
assert_equal(desc, @site.dtext_artist_commentary_desc)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user