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

View File

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