Method: CSLAdaptor.safe_style

Defined in:
lib/texstylist/csl_adaptor.rb

.safe_style(style) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/texstylist/csl_adaptor.rb', line 26

def self.safe_style(style)
  if style.is_a? Symbol
    style = style.to_s
  end
  style_path = File.basename(style,".*") + '.csl'
  expected_path = File.join(CSL::Style.root,style_path)
  dependent_path = File.join(CSL::Style.root,'dependent',style_path)
  if File.exist?(expected_path)
    style
  elsif File.exist?(dependent_path)
    # While waiting for the main CSL library to implement dependent support, we'll pass the parent here
    begin
      dom = Nokogiri::XML(File.open(dependent_path))
      parent_link = dom.search('link[@rel="independent-parent"]').first.attr('href')
      parent_style = parent_link.sub('http://www.zotero.org/styles/','')
    rescue
      :'chicago-author-date'
    end
  else
    :'chicago-author-date'
  end
end