Class: Epub
- Inherits:
-
Object
- Object
- Epub
- Defined in:
- lib/link2epub.rb
Instance Attribute Summary collapse
-
#articles ⇒ Object
Returns the value of attribute articles.
-
#conf ⇒ Object
Returns the value of attribute conf.
-
#conf_file ⇒ Object
Returns the value of attribute conf_file.
-
#links ⇒ Object
Returns the value of attribute links.
-
#titles ⇒ Object
Returns the value of attribute titles.
Instance Method Summary collapse
- #clean ⇒ Object
- #createFile(tpl, file) ⇒ Object
- #getArticles ⇒ Object
- #getTitles ⇒ Object
-
#initialize(conf_file) ⇒ Epub
constructor
A new instance of Epub.
- #to_epub ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#articles ⇒ Object
Returns the value of attribute articles.
45 46 47 |
# File 'lib/link2epub.rb', line 45 def articles @articles end |
#conf ⇒ Object
Returns the value of attribute conf.
45 46 47 |
# File 'lib/link2epub.rb', line 45 def conf @conf end |
#conf_file ⇒ Object
Returns the value of attribute conf_file.
45 46 47 |
# File 'lib/link2epub.rb', line 45 def conf_file @conf_file end |
#links ⇒ Object
Returns the value of attribute links.
45 46 47 |
# File 'lib/link2epub.rb', line 45 def links @links end |
#titles ⇒ Object
Returns the value of attribute titles.
45 46 47 |
# File 'lib/link2epub.rb', line 45 def titles @titles end |
Instance Method Details
#clean ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/link2epub.rb', line 126 def clean FileUtils.rm('./nav.html') FileUtils.rm('./index.html') @articles.each do |a| FileUtils.rm(a.file) end end |
#createFile(tpl, file) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/link2epub.rb', line 76 def createFile(tpl, file) eruby = Erubis::Eruby.new(File.read(tpl)) File.open(file, 'w') do |f| f.puts eruby.evaluate(self) end end |
#getArticles ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/link2epub.rb', line 55 def getArticles @links.each_with_index do |l, i| art = Article.new(l) art.tpl = "../tpl/article.tpl" art.file = "./file#{i+1}.html" art.content = Nokogiri::HTML(open(art.link)).css('.post .content').to_html art.title = Nokogiri::HTML(open(art.link)).css('.post h2').text art. = Nokogiri::HTML(open(art.link)).css('.post .author').text art.date = Nokogiri::HTML(open(art.link)).css('.post .date').text art.to_file @articles.push(art) end end |
#getTitles ⇒ Object
69 70 71 72 73 74 |
# File 'lib/link2epub.rb', line 69 def getTitles @articles.each do |a| @titles.push(a.title) end @titles end |
#to_epub ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/link2epub.rb', line 90 def to_epub getArticles getTitles createFile('../tpl/nav.tpl', './nav.html') createFile('../tpl/index.tpl', './index.html') conf = @conf articles = @articles builder = GEPUB::Builder.new { language 'zh-cn' unique_identifier conf['link'], 'BookID', 'URL' title conf['title'] subtitle conf['subtitle'] creator conf['author'] date Time.new # contributors '123', '456' resources(:workdir => '.') { nav 'nav.html' # cover_image 'img/image1.jpg' => 'image1.jpg' ordered { file 'index.html' file 'nav.html' articles.each do |a| file a.file heading a.title end } } } builder.generate_epub(@conf['file_name']) clean end |
#to_s ⇒ Object
84 85 86 87 88 |
# File 'lib/link2epub.rb', line 84 def to_s @articles.each do |a| puts a.title end end |