class ResumeStylist::Theme

Public Class Methods

new(source) click to toggle source

def intialize(theme_path) @source = File.read(theme_path)

# File lib/resume-stylist/theme.rb, line 5
def initialize(source)
  @source = source
  @frontmatter = {
    "flags" => []
  }
  parse_frontmatter!

  @template = Liquid::Template.parse(@source)
end

Public Instance Methods

render(resume_data) click to toggle source
# File lib/resume-stylist/theme.rb, line 15
def render(resume_data)
  meta_data = {
    "frontmatter" => @frontmatter,

    "_generator" => {
      "name" =>  "resume-stylist",
      "version" => ResumeStylist::VERSION
    }

  }
  ctx = resume_data.merge(meta_data)
  @resume = @template.render(ctx)
  post_process!

  @resume
end

Private Instance Methods

parse_frontmatter!() click to toggle source
# File lib/resume-stylist/theme.rb, line 50
def parse_frontmatter!
  if @source =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
    @source = $POSTMATCH
    @frontmatter.merge!(YAML.load($1) || {})
  end

  nil
end
post_process!() click to toggle source
# File lib/resume-stylist/theme.rb, line 33
def post_process!
  return if @frontmatter["flags"].include? "disable_post_processing"

  @document = Oga.parse_html @resume

  @document.css(%q{style[type="text/scss"], style[type="text/sass"]}).each do |style|
    syntax = style.get("type")[5, 4].to_sym # Going to be :scss or :sass
    css = Sass::Engine.new(style.text, syntax: syntax, style: :compressed)

    style.inner_text = css.render
    style.set("type", "text/css")
  end

  @resume = @document.to_xml
end