class Jekyll::Lilypond::Template
Public Class Methods
new(site, tag, type)
click to toggle source
# File lib/jekyll-lilypond/templates.rb, line 4 def initialize(site, tag, type) @site = site @type = type @tag_template_names = tag.template_names @tag_template_code = tag.template_code end
Public Instance Methods
render(tag)
click to toggle source
# File lib/jekyll-lilypond/templates.rb, line 11 def render(tag) Liquid::Template.parse(template_code).render(tag.attrs) end
template_code()
click to toggle source
# File lib/jekyll-lilypond/templates.rb, line 19 def template_code @tag_template_code[@type] or fetch_site_template(template_name) or fetch_plugin_template(template_name) or raise LoadError.new("No template named #{template_name}.#{extension}") end
template_name()
click to toggle source
# File lib/jekyll-lilypond/templates.rb, line 15 def template_name @tag_template_names[@type] || sitewide_template_names[@type] || plugin_template_names[@type] end
Private Instance Methods
extension()
click to toggle source
# File lib/jekyll-lilypond/templates.rb, line 54 def extension if @type == :source then "ly" else "html" end end
fetch_plugin_template(name)
click to toggle source
# File lib/jekyll-lilypond/templates.rb, line 46 def fetch_plugin_template(name) dir = File.join(File.dirname(__dir__), "/jekyll-lilypond/templates/") filename = File.join(dir, "#{name}.#{extension}") if File.exists?(filename) File.read(filename).strip end end
fetch_site_template(name)
click to toggle source
# File lib/jekyll-lilypond/templates.rb, line 40 def fetch_site_template(name) if @site.layouts[name] @site.layouts[name].content.strip end end
plugin_template_names()
click to toggle source
# File lib/jekyll-lilypond/templates.rb, line 36 def plugin_template_names { source: "basic", include: "img" } end
sitewide_template_names()
click to toggle source
# File lib/jekyll-lilypond/templates.rb, line 28 def sitewide_template_names if @site.respond_to? :lilypond and @site.lilypond.respond_to? :template_names @site.lilypond.template_names else { source: nil, include: nil } end end