Class: MakeBook::Formats::HTML
- Inherits:
-
Object
- Object
- MakeBook::Formats::HTML
- Defined in:
- lib/makebook/formats/html.rb
Overview
HTML output format rubocop:disable Metrics/ClassLength
Defined Under Namespace
Classes: Asset, Range, Section, Stylesheet
Instance Attribute Summary collapse
-
#book ⇒ Object
readonly
Returns the value of attribute book.
-
#build ⇒ Object
readonly
Returns the value of attribute build.
Instance Method Summary collapse
- #build_dir ⇒ Object
- #build_file ⇒ Object
- #build_name ⇒ Object
-
#initialize(book, build, options = {}) ⇒ HTML
constructor
A new instance of HTML.
-
#make ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
- #sections ⇒ Object
- #stale? ⇒ Boolean
Constructor Details
#initialize(book, build, options = {}) ⇒ HTML
Returns a new instance of HTML.
10 11 12 13 14 |
# File 'lib/makebook/formats/html.rb', line 10 def initialize(book, build, = {}) @book = book @build = build @options = end |
Instance Attribute Details
#book ⇒ Object (readonly)
Returns the value of attribute book.
8 9 10 |
# File 'lib/makebook/formats/html.rb', line 8 def book @book end |
#build ⇒ Object (readonly)
Returns the value of attribute build.
8 9 10 |
# File 'lib/makebook/formats/html.rb', line 8 def build @build end |
Instance Method Details
#build_dir ⇒ Object
291 292 293 |
# File 'lib/makebook/formats/html.rb', line 291 def build_dir build_name end |
#build_file ⇒ Object
287 288 289 |
# File 'lib/makebook/formats/html.rb', line 287 def build_file Pathname("#{build_name}.html") end |
#build_name ⇒ Object
283 284 285 |
# File 'lib/makebook/formats/html.rb', line 283 def build_name build.root + book.root + book.name end |
#make ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/makebook/formats/html.rb', line 186 def make build_dir.mkpath head << <<-HTML <title>#{book.title}</title> HTML book.styles.each do |stylesheet| stylesheet.assets.reverse_each do |asset, range| range.value = asset.build_name FileUtils.cp(asset.source, build_dir + asset.build_name) end File.open(build_dir + stylesheet.build_name, 'wb') do |f| f.write(stylesheet.to_css) end head << <<-HTML <link rel="stylesheet" href="#{build_dir.basename + stylesheet.build_name}" /> HTML end header << book.title sections.each do |section| nav << section.toc(book.toc).to_s if book.toc? section.images.each do |asset, img| img['src'] = build_dir.basename + asset.build_name FileUtils.cp(asset.source, build_dir + asset.build_name) end main << section.to_html end open { |io| assemble(io) } end |
#sections ⇒ Object
181 182 183 |
# File 'lib/makebook/formats/html.rb', line 181 def sections @sections ||= book.chapters.map { |c| Section.new(c.source) } end |
#stale? ⇒ Boolean
295 296 297 298 299 |
# File 'lib/makebook/formats/html.rb', line 295 def stale? book.source.mtime > build_file.mtime rescue Errno::ENOENT true end |