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
# File 'lib/octodown/renderer/html.rb', line 12

def initialize(rendered_markdown, options = {})
  @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

#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



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

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

#highlight_stylesheetObject



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

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

#hostObject



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

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

#presentObject



41
42
43
# File 'lib/octodown/renderer/html.rb', line 41

def present
  Launchy.open PersistentTempfile.create(content, :html).path
end

#stylesheetObject



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

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

#titleObject



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

def title
  'Octodown Preview'
end