Sha256: 8947d0b4ff6ff16d267a57cf74ebf74197277a269e2eb09ddf84f72d65222a20

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

require 'rouge'
require 'date'

module VimwikiMarkdown
  class Template

    def initialize(options)
      @options = options
      get_template_contents

      validate_template
    end

    def to_s
      fixtags(template)
    end


    private

    attr_reader :options, :template

    def get_template_contents
      file = File.open(options.template_filename, "r")
      @template = file.read
    end

    def fixtags(template)
      @template = template.gsub('%title%',title)
                          .gsub('%pygments%',pygments_wrapped_in_tags)
                          .gsub('%root_path%', root_path)
                          .gsub('%date%', Date.today.strftime("%e %b %Y"))
    end

    def pygments_wrapped_in_tags
      "<style type=\"text/css\">
        #{::Rouge::Themes::Github.render(scope: '.highlight')}
      </style>"
    end

    def root_path
      options.root_path
    end

    def title
      options.title
    end

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
vimwiki_markdown-0.8.2 lib/vimwiki_markdown/template.rb
vimwiki_markdown-0.8.1 lib/vimwiki_markdown/template.rb
vimwiki_markdown-0.7.0 lib/vimwiki_markdown/template.rb
vimwiki_markdown-0.6.0 lib/vimwiki_markdown/template.rb
vimwiki_markdown-0.5.1 lib/vimwiki_markdown/template.rb
vimwiki_markdown-0.5.0 lib/vimwiki_markdown/template.rb
vimwiki_markdown-0.4.4 lib/vimwiki_markdown/template.rb
vimwiki_markdown-0.4.3 lib/vimwiki_markdown/template.rb
vimwiki_markdown-0.4.2 lib/vimwiki_markdown/template.rb
vimwiki_markdown-0.4.1 lib/vimwiki_markdown/template.rb
vimwiki_markdown-0.4.0 lib/vimwiki_markdown/template.rb
vimwiki_markdown-0.3.3 lib/vimwiki_markdown/template.rb