Class: Octodown::Renderer::HTML

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Renderable

included

Constructor Details

#initialize(rendered_markdown, options = {}) ⇒ HTML

Returns a new instance of HTML.



12
13
14
15
16
17
# File 'lib/octodown/renderer/html.rb', line 12

def initialize(rendered_markdown, options = {})
  @logger = options[:logger]
  @rendered_markdown = rendered_markdown
  @options = options
  @filepath = File.join parent_dir, 'template', 'octodown.html.erb'
end

Instance Attribute Details

#filepathObject (readonly)

Returns the value of attribute filepath.



10
11
12
# File 'lib/octodown/renderer/html.rb', line 10

def filepath
  @filepath
end

#loggerObject (readonly)

Returns the value of attribute logger.



10
11
12
# File 'lib/octodown/renderer/html.rb', line 10

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/octodown/renderer/html.rb', line 10

def options
  @options
end

#rendered_markdownObject (readonly)

Returns the value of attribute rendered_markdown.



10
11
12
# File 'lib/octodown/renderer/html.rb', line 10

def rendered_markdown
  @rendered_markdown
end

Instance Method Details

#contentObject



19
20
21
22
23
# File 'lib/octodown/renderer/html.rb', line 19

def content
  template_text = File.read filepath
  erb_template = ERB.new template_text
  erb_template.result binding
end

#highlight_stylesheetObject



34
35
36
# File 'lib/octodown/renderer/html.rb', line 34

def highlight_stylesheet
  inject_html_node_with_file_content assets_dir('highlight.css'), :style
end

#hostObject



38
39
40
# File 'lib/octodown/renderer/html.rb', line 38

def host
  "ws://localhost:#{options[:port]}".dump
end

#presentObject



42
43
44
45
46
47
48
# File 'lib/octodown/renderer/html.rb', line 42

def present
  if options[:no_open]
    logger.warn('--no-open argument was used so no browser will be opened')
  else
    Launchy.open PersistentTempfile.create(content, :html).path
  end
end

#stylesheetObject



29
30
31
32
# File 'lib/octodown/renderer/html.rb', line 29

def stylesheet
  stylesheet = "#{options[:style]}.css"
  inject_html_node_with_file_content assets_dir(stylesheet), :style
end

#titleObject



25
26
27
# File 'lib/octodown/renderer/html.rb', line 25

def title
  'Octodown Preview'
end