Skip to content
This repository has been archived by the owner on Jun 25, 2019. It is now read-only.

Commit

Permalink
Updated parsing to remove the 'Reviewed by' segment of the reviewers.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyf committed Mar 9, 2011
1 parent 6efd2de commit 8d070eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
19 changes: 11 additions & 8 deletions lib/parse_source.rb
Expand Up @@ -2,7 +2,7 @@
require 'hpricot'
require 'yaml'
require 'logger'
log = Logger.new(LOG_FILE, 5, 10*1024)
log = Logger.new(File.join(File.dirname(__FILE__), '../tmp/parse_source.log'), 5, 10*1024)

exceptions = []
log.info "\n"
Expand All @@ -29,19 +29,22 @@
original_html = content.to_original_html.sub("<div id=\"review\">", '')[0..-7]
dictionary['review_id'] = review_id.strip.to_i
[
['catalog_id', 'h1'],
['authors', 'h4'],
['review_title', 'h2'],
['bibliography', 'p.biblio'],
['reviewer', 'p strong'],
].each do |key, selector|
['catalog_id', 'h1', nil],
['authors', 'h4', nil],
['review_title', 'h2', nil],
['bibliography', 'p.biblio', nil],
['reviewer', 'p strong', /\A *Reviewed by(.*)\Z/],
].each do |key, selector, regex|
node = (content/"#{selector}:first-of-type")
dictionary[key] = node[0].inner_html.strip
if key == 'reviewer'
node[0].search("/..p").each { |n| original_html.sub!(n.to_original_html,'') }
else
original_html.sub!(node[0].to_original_html,'')
end
if regex
dictionary[key] = dictionary[key].sub(regex, '\1').strip
end
end
(content/"div#hr:first-of-type").each {|n| original_html.sub!(n.to_original_html, '')}

Expand All @@ -57,7 +60,7 @@
# dictionary['bibliography'] = (content/"p.biblio").first.inner_html.strip
# dictionary['reviewer'] = (content/"p strong").first.inner_html.strip
# review_content = (content/"div#hr").first.following_siblings.collect{|sib| sib.to_original_html}.join("\n")
dictionary['content'] = original_html
dictionary['content'] = original_html.strip
end
File.open(File.join(File.dirname(__FILE__), "../src/yml/review-#{review_id}.yml"), 'w+') do |file|
file.puts YAML.dump(dictionary)
Expand Down
1 change: 0 additions & 1 deletion lib/render.rb
Expand Up @@ -4,7 +4,6 @@
require 'yaml'

Dir.glob(File.join(File.dirname(__FILE__), "../src/yml/*.yml")).each do |filename|
puts "Processing #{filename}"
object = YAML.load_file(filename)
buffer = ERB.new(File.read(File.join(File.dirname(__FILE__), '../src/template.erb.html'))).result(binding)
target_filename = File.join(File.dirname(__FILE__), "../src/output/review-#{object['review_id']}.html")
Expand Down
2 changes: 1 addition & 1 deletion src/template.erb.html
Expand Up @@ -54,7 +54,7 @@ <h4><%= object['authors'] %></h4>
<h2><%= object['review_title'] %></h2>

<p class="biblio"><%= object['bibliography'] %></p>
<p><strong><%= object['reviewer'] %></strong></p>
<p><strong>Reviewed by <%= object['reviewer'] %></strong></p>
<div id="hr"><hr /></div>

<%= object['content'] %>
Expand Down

0 comments on commit 8d070eb

Please sign in to comment.