class VimwikiMarkdown::Template

Attributes

options[R]
template[R]

Public Class Methods

new(options) click to toggle source
# File lib/vimwiki_markdown/template.rb, line 7
def initialize(options)
  @options = options
  get_template_contents

  validate_template
end

Public Instance Methods

to_s() click to toggle source
# File lib/vimwiki_markdown/template.rb, line 14
def to_s
  fixtags(template)
end

Private Instance Methods

dark_template?() click to toggle source
# File lib/vimwiki_markdown/template.rb, line 61
def dark_template?
  @template =~ /%dark_pygments%/
end
fixtags(template) click to toggle source
# File lib/vimwiki_markdown/template.rb, line 28
def fixtags(template)
  @template = template.gsub('%title%',title)
                      .gsub(pygments_marker,pygments_wrapped_in_tags)
                      .gsub('%root_path%', root_path)
                      .gsub('%date%', Date.today.strftime("%e %b %Y"))
end
get_template_contents() click to toggle source
# File lib/vimwiki_markdown/template.rb, line 23
def get_template_contents
  file = File.open(options.template_filename, "r")
  @template = file.read
end
pygments_marker() click to toggle source
# File lib/vimwiki_markdown/template.rb, line 57
def pygments_marker
  dark_template? ? "%dark_pygments%" : "%pygments%"
end
pygments_wrapped_in_tags() click to toggle source
# File lib/vimwiki_markdown/template.rb, line 35
def pygments_wrapped_in_tags
  Rouge::Themes::Github.dark! if dark_template?

  "<style type=\"text/css\">
    #{::Rouge::Themes::Github.render(scope: '.highlight')}
  </style>"
end
regular_template?() click to toggle source
# File lib/vimwiki_markdown/template.rb, line 65
def regular_template?
  @template =~ /%pygments%/
end
root_path() click to toggle source
# File lib/vimwiki_markdown/template.rb, line 43
def root_path
  options.root_path
end
title() click to toggle source
# File lib/vimwiki_markdown/template.rb, line 47
def title
  options.title
end
validate_template() click to toggle source
# File lib/vimwiki_markdown/template.rb, line 51
def validate_template
  return if dark_template? || regular_template?

  raise MissingRequiredParamError.new("ERROR: vimwiki template must contain %pygments% placeholder token.  Please visit https://github.com/patrickdavey/vimwiki_markdown for more information")
end