Class: BookWriter
- Inherits:
-
Object
- Object
- BookWriter
- Defined in:
- lib/jekyll-books/book_writer.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
Instance Method Summary collapse
- #book_folder ⇒ Object
- #content ⇒ Object
- #create_index ⇒ Object
- #create_summary ⇒ Object
- #default_year ⇒ Object
- #img_url ⇒ Object
- #index_file ⇒ Object
-
#initialize(name, root, params) ⇒ BookWriter
constructor
A new instance of BookWriter.
- #mkdir ⇒ Object
- #run ⇒ Object
- #summary_file ⇒ Object
Constructor Details
#initialize(name, root, params) ⇒ BookWriter
Returns a new instance of BookWriter.
6 7 8 9 10 11 |
# File 'lib/jekyll-books/book_writer.rb', line 6 def initialize(name, root, params) @name = name @root = root @params = params @summary = Summary.new(book_folder) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/jekyll-books/book_writer.rb', line 5 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/jekyll-books/book_writer.rb', line 5 def params @params end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
5 6 7 |
# File 'lib/jekyll-books/book_writer.rb', line 5 def root @root end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
5 6 7 |
# File 'lib/jekyll-books/book_writer.rb', line 5 def summary @summary end |
Instance Method Details
#book_folder ⇒ Object
19 20 21 |
# File 'lib/jekyll-books/book_writer.rb', line 19 def book_folder File.join(root, name) end |
#content ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/jekyll-books/book_writer.rb', line 50 def content front_matter = YAML.dump( Util.cover_default({ "title" => name.capitalize, "start" => default_year, "end" => default_year, "img" => img_url }, params) ) front_matter + "---\n" end |
#create_index ⇒ Object
37 38 39 40 41 42 |
# File 'lib/jekyll-books/book_writer.rb', line 37 def create_index return if File.file?(index_file) f = File.new(index_file, "w+") f.write(content) end |
#create_summary ⇒ Object
44 45 46 47 48 |
# File 'lib/jekyll-books/book_writer.rb', line 44 def create_summary return if File.file?(summary_file) && !params["forced"] summary.write(true) end |
#default_year ⇒ Object
63 64 65 |
# File 'lib/jekyll-books/book_writer.rb', line 63 def default_year Date.today.year end |
#img_url ⇒ Object
67 68 69 |
# File 'lib/jekyll-books/book_writer.rb', line 67 def img_url "/img/home/#{name}.jpg" end |
#index_file ⇒ Object
27 28 29 |
# File 'lib/jekyll-books/book_writer.rb', line 27 def index_file summary.index_path end |
#mkdir ⇒ Object
31 32 33 34 35 |
# File 'lib/jekyll-books/book_writer.rb', line 31 def mkdir unless File.directory?(book_folder) FileUtils.mkdir_p(book_folder) end end |
#run ⇒ Object
13 14 15 16 17 |
# File 'lib/jekyll-books/book_writer.rb', line 13 def run mkdir create_index create_summary end |
#summary_file ⇒ Object
23 24 25 |
# File 'lib/jekyll-books/book_writer.rb', line 23 def summary_file summary.file_path end |