Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add BookUnit class instead of Compilable module #1543

Merged
merged 1 commit into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@

module ReVIEW
module Book
module Compilable
class BookUnit
include TextUtils
attr_reader :book
attr_reader :path
attr_accessor :content

def initialize(book, number, name = nil)
@book = book
@number = number
@name = name
end

def dirname
return nil unless @path
File.dirname(@path)
Expand Down
10 changes: 3 additions & 7 deletions lib/review/book/chapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
# the GNU LGPL, Lesser General Public License version 2.1.
# For details of the GNU LGPL, see the file "COPYING".
#
require 'review/book/compilable'
require 'review/book/book_unit'
require 'review/lineinput'
require 'review/preprocessor'

module ReVIEW
module Book
class Chapter
include Compilable

class Chapter < BookUnit
attr_reader :number, :book

def self.mkchap(book, name, number = nil)
Expand All @@ -34,9 +32,7 @@ def self.mkchap_ifexist(book, name, number = nil)
end

def initialize(book, number, name, path, io = nil)
@book = book
@number = number
@name = name
super(book, number, name)
@path = path
@io = io
@title = nil
Expand Down
10 changes: 3 additions & 7 deletions lib/review/book/part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
# the GNU LGPL, Lesser General Public License version 2.1.
# For details of the GNU LGPL, see the file "COPYING".
#
require 'review/book/compilable'
require 'review/book/book_unit'

module ReVIEW
module Book
class Part
include Compilable

class Part < BookUnit
def self.mkpart_from_namelistfile(book, path)
chaps = []
File.read(path, mode: 'rt:BOM|utf-8').split.each_with_index do |name, number|
Expand All @@ -36,10 +34,8 @@ def self.mkpart(chaps)
# if Part is dummy, `number` is nil.
#
def initialize(book, number, chapters, name = '', io = nil)
@book = book
@number = number
super(book, number, name)
@chapters = chapters
@name = name
@path = name
@content = ''
if io
Expand Down