Add Coop.all method to return all co-ops for migration

This commit is contained in:
Chris Lowis 2018-11-09 20:56:26 +00:00
parent 5ca9d98343
commit 23251e7ba2
1 changed files with 53 additions and 44 deletions

View File

@ -4,10 +4,16 @@ require 'active_support/inflector'
class Coop
attr_reader :doc
def initialize(html)
def initialize(fn)
html = File.read(fn)
@fn = fn
@doc = Nokogiri::HTML(html)
end
def slug
File.basename(@fn, '.html')
end
def name
doc.xpath('//*[@id="page-banner"]/div/div/h2').text
end
@ -79,9 +85,9 @@ class Coop
def erb_binding
binding
end
end
source_pages = %w(
def self.all
%w(
agile-collective.html
alpha-communication.html
animorph.html
@ -117,15 +123,18 @@ source_pages = %w(
wave.html
we-are-open.html
webarchitects.html
)
).map do |page|
fn = File.join(File.dirname(__FILE__), 'mirror', 'coops.tech.archived.website', 'co-op', page)
new(fn)
end
end
end
require 'erb'
source_pages.each do |page|
fn = File.join(File.dirname(__FILE__), 'mirror', 'coops.tech.archived.website', 'co-op', page)
output_fn = File.join(File.dirname(__FILE__), '..', '_coops', page.gsub('.html','.md'))
coop = Coop.new(File.read(fn))
Coop.all.each do |coop|
output_fn = File.join(File.dirname(__FILE__), '..', '_coops', coop.slug + '.md')
renderer = ERB.new(File.read('coop.erb.md'), nil, '<>')
result = renderer.result(coop.erb_binding)