Skip to content

Commit

Permalink
allow setting authors
Browse files Browse the repository at this point in the history
  • Loading branch information
SohumB committed Mar 29, 2012
1 parent fc1d994 commit c3464ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
13 changes: 7 additions & 6 deletions lw2ebook.rb
Expand Up @@ -90,7 +90,7 @@ def load_interlinks

class Builder
Temp_folder = "lw_temp" + rand(10000).to_s
def initialize(posts, format, title, slug=nil)
def initialize(posts, format, title, author="LessWrong", slug=nil)
@posts = case posts
when Post then [posts]
when Array then posts
Expand All @@ -105,6 +105,7 @@ def initialize(posts, format, title, slug=nil)
slug
end
@format = format.delete('.')
@author = author
end

def write_html
Expand All @@ -123,7 +124,7 @@ def write_html

def convert
puts "Compiling into an ebook..." unless Silenced
`#{Path_to_ebook_convert} #{Temp_folder}/toc.html #{@slug}.#{@format} --title "#{@title}" --authors "LessWrong" --level1-toc "//top_level" --level2-toc "interlink" --toc-filter "^((?!#{Identifier_space}).)*$" --cover "logo.png" --comments "Less Wrong is a community devoted to refining the art of human rationality."`
`#{Path_to_ebook_convert} #{Temp_folder}/toc.html #{@slug}.#{@format} --title "#{@title}" --authors "#{@author}" --level1-toc "//top_level" --level2-toc "interlink" --toc-filter "^((?!#{Identifier_space}).)*$" --cover "logo.png" --comments "Less Wrong is a community devoted to refining the art of human rationality."`
FileUtils.rm_rf Temp_folder #`rm -rf #{Temp_folder}`
end

Expand Down Expand Up @@ -232,13 +233,13 @@ def temp_path(filename)
# Command Line
###
if __FILE__ == $0
unless ARGV.length == 2
puts "Usage: ruby #{__FILE__} [filetype] [url]"
puts "Example: ruby #{__FILE__} epub http://lesswrong.com/lw/34a/goals_for_which_less_wrong_does_and_doesnt_help/\n\n"
unless ARGV.length == 3
puts "Usage: ruby #{__FILE__} [filetype] [url] [author]"
puts "Example: ruby #{__FILE__} epub http://lesswrong.com/lw/34a/goals_for_which_less_wrong_does_and_doesnt_help/ AnnaSalamon\n\n"
exit
end

p = Post.new(ARGV[1].dup, true)
eb = Builder.new(p, ARGV.first.dup, p.title, p.slug)
eb = Builder.new(p, ARGV.first.dup, p.title, ARGV[2].dup, p.slug)
eb.build
end
19 changes: 10 additions & 9 deletions sequence.rb
@@ -1,23 +1,24 @@
require 'rubygems'
require 'open-uri'
require 'nokogiri'
load 'lw2ebook.rb'

class Sequence
def initialize(posts, format, title)
@posts, @format, @title = posts, format, title
def initialize(posts, format, title, author)
@posts, @format, @title, @author = posts, format, title, author
end

def build
b = Builder.new(@posts, @format, @title)
b = Builder.new(@posts, @format, @title, @author)
b.build
puts "Whew. Sequence built."
end

def self.from_urls(urls, format, title)
def self.from_urls(urls, format, title, author)
posts = urls.map do |url|
Post.new(url, true)
end
Sequence.new(posts, format, title)
Sequence.new(posts, format, title, author)
end

# I *think* token is the right word, here...
Expand All @@ -27,9 +28,9 @@ def self.from_tokens(url, begin_token, end_token)
end

if __FILE__ == $0
unless ARGV.length == 2
puts "Usage: ruby #{__FILE__} [filetype] [sequence_name]"
puts "Example: ruby #{__FILE__} epub \"Zombies\"\n\n"
unless ARGV.length == 3
puts "Usage: ruby #{__FILE__} [filetype] [sequence_name] [author]"
puts "Example: ruby #{__FILE__} epub \"Zombies\" \"Eliezer Yudkowsky\"\n\n"
exit
end

Expand All @@ -43,6 +44,6 @@ def self.from_tokens(url, begin_token, end_token)
links
end

s = Sequence.from_urls(urls, ARGV.first.dup, ARGV[1].dup)
s = Sequence.from_urls(urls, ARGV.first.dup, ARGV[1].dup, ARGV[2].dup)
s.build
end

0 comments on commit c3464ff

Please sign in to comment.