Class: Riven::MarkupFile

Inherits:
Object
  • Object
show all
Defined in:
lib/riven/markup_file.rb

Overview

Represents a MD File

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ MarkupFile

Constructor Also checks if the file exists. If not, an exception will be thrown.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/riven/markup_file.rb', line 15

public def initialize(path)
  @path = File.expand_path(path)

  unless File.exists?(@path)
    raise "File '#{path}' doesn't exist"
  end

  if File.directory?(@path)
    raise "Mixing files and directories is not allowed, sorry"
  end
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/riven/markup_file.rb', line 7

def path
  @path
end

Instance Method Details

#read_all(markup_files, except = []) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/riven/markup_file.rb', line 29

public def read_all(markup_files, except = [])
  markup = ''

  markup_files = [markup_files] unless markup_files.respond_to?(:each)
  except = [except] unless except.respond_to?(:each)

  markup_files.each do |file|
    markup << "\n\n" + File.read(file.path) unless exclude?(except, file)
  end

  return markup
end

#read_cover(cover_file) ⇒ Object



42
43
44
45
46
# File 'lib/riven/markup_file.rb', line 42

public def read_cover(cover_file)
  cover_markup =  "\n////[COVERSTART]////\n"
  cover_markup << Riven::MarkupFile.read_all(cover_file)
  cover_markup << "\n////[COVEREND]////\n"
end