Skip to content

Commit

Permalink
Finalize and add test for #268 #269
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed Jul 21, 2019
1 parent ed86347 commit f4490d7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 21 deletions.
41 changes: 41 additions & 0 deletions features/bibtex.feature
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,44 @@ Feature: BibTeX
When I run jekyll
Then the _site directory should exist
And I should see "The Ruby Programming Language" in "_site/scholar.html"

@tags @bibliography @locale
Scenario: Non-english reference
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
| bibliography | my_references |
| allow_locale_overrides | true |
| style | chicago-fullnote-bibliography |
And I have a "_bibliography" directory
And I have a file "_bibliography/my_references.bib":
"""
@article{one,
title = {Ideología y narrativa en el Ramayana de Valmiki},
number = {22},
language = {es},
journal = {Estudios de Asia y Africa},
author = {Pollock, Sheldon I.},
year = {1987},
pages = {336--54}
}
@article{two,
title = {{Ideología y narrativa en el Ramayana de Valmiki}},
number = {22},
journal = {Estudios de Asia y Africa},
author = {Pollock, Sheldon I.},
year = {1987},
pages = {336--54}
}
"""
And I have a page "scholar.html":
"""
---
---
{% bibliography %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "Estudios de Asia y Africa</i>, n.º 22" in "_site/scholar.html"
And I should see "Estudios De Asia y Africa</i>, no. 22" in "_site/scholar.html"
42 changes: 21 additions & 21 deletions lib/jekyll/scholar/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Scholar
# treated as being read-only.
STYLES = {}

LOCALES = {}

# Utility methods used by several Scholar plugins. The methods in this
# module may depend on the presence of #config, #bibtex_files, and
# #site readers
Expand Down Expand Up @@ -113,6 +115,11 @@ def bibliography_list_tag
end
end

def allow_locale_overrides?
!!config['allow_locale_overrides']
end


def locators
@locators ||= []
end
Expand Down Expand Up @@ -622,31 +629,20 @@ def render_citation(items)
end

def render_bibliography(entry, index = nil)

entry.language = entry['language']

if config['allow_locale_overrides'] == true && entry.language != "" && entry.language != config['locale']
begin
new_locale = CSL::Locale.load(entry.language)
unless new_locale.nil?
original_locale, renderer.locale = renderer.locale, new_locale
end
rescue ParseError
# locale not found
end
end
begin
original_locale, renderer.locale =
renderer.locale, locales(entry.language)
rescue
# Locale failed to load; just use original one!
end if allow_locale_overrides? &&
entry['language'] != renderer.locale.language

renderer.render citation_item_for(entry, index),
styles(style).bibliography

ensure
unless original_locale.nil?
renderer.locale = original_locale
end
styles(style).bibliography
ensure
renderer.locale = original_locale unless original_locale.nil?
end



def citation_item_for(entry, citation_number = nil)
CiteProc::CitationItem.new id: entry.id do |c|
c.data = CiteProc::Item.new entry.to_citeproc
Expand Down Expand Up @@ -758,6 +754,10 @@ def styles(style)
STYLES[style] ||= load_style(style)
end

def locales(lang)
LOCALES[lang] ||= CSL::Locale.load(lang)
end

def update_dependency_tree
# Add bibtex files to dependency tree
if context.registers[:page] and context.registers[:page].key? "path"
Expand Down

0 comments on commit f4490d7

Please sign in to comment.