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.



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

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.



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

def filepath
  @filepath
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#rendered_markdownObject (readonly)

Returns the value of attribute rendered_markdown.



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

def rendered_markdown
  @rendered_markdown
end

Instance Method Details

#contentObject



21
22
23
24
25
# File 'lib/octodown/renderer/html.rb', line 21

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

#highlight_stylesheetObject



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

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

#hostObject



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

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

#presentObject



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

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



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

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

#titleObject



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

def title
  'Octodown Preview'
end