Class: Octodown::Renderer::GithubMarkdown

Inherits:
Object
  • Object
show all
Includes:
HTML, Renderable
Defined in:
lib/octodown/renderer/github_markdown.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Renderable

included

Constructor Details

#initialize(file, options = {}) ⇒ GithubMarkdown

Returns a new instance of GithubMarkdown.



16
17
18
19
20
# File 'lib/octodown/renderer/github_markdown.rb', line 16

def initialize(file, options = {})
  @file = file
  @options = options
  @logger = options[:logger]
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



14
15
16
# File 'lib/octodown/renderer/github_markdown.rb', line 14

def file
  @file
end

#loggerObject (readonly)

Returns the value of attribute logger.



14
15
16
# File 'lib/octodown/renderer/github_markdown.rb', line 14

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/octodown/renderer/github_markdown.rb', line 14

def options
  @options
end

Instance Method Details

#contentObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/octodown/renderer/github_markdown.rb', line 22

def content
  if file == STDIN
    buffer = file.read
  else
    begin
      File.open(file.path, 'r') { |f| buffer = f.read }
    rescue Errno::ENOENT
      logger.warn 'Something went wrong when trying to open the file'
    end
  end
  pipeline.call(buffer ||= 'could not read changes')[:output].to_s
end