diff --git a/README.md b/README.md index fef561e8b2fde2a51633a0cb1302d3a6b30ee016..81f6524a298f04266f70ac90e7067ff72cbbd66d 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,27 @@ following blog post: {% bibliography %} +For longer quotes, Jekyll-Scholar provides a `quote` tag: + + {% quote derrida:purveyor %} + Lorem ipsum dolor sit amet, consectetur adipisicing elit, + sed do eiusmod tempor. + + Lorem ipsum dolor sit amet, consectetur adipisicing. + {% endquote %} + +For example, this could be rendered as: + +
++ + ### Detail Pages If your layouts directory contains a layout file for bibliography details diff --git a/features/citation.feature b/features/citation.feature index 23e640c3697a742bc4e00cef3d688da88eb0c445..f0388ba5b969219a59cd8b43f8d3b92513f91cba 100644 --- a/features/citation.feature +++ b/features/citation.feature @@ -2,7 +2,7 @@ Feature: Citations As a scholar who likes to blog I want to reference cool papers and books from my bibliography - @tags + @tags @cite Scenario: A Simple Citation Given I have a scholar configuration with: | key | value | @@ -29,7 +29,7 @@ Feature: Citations And the "_site/scholar.html" file should exist And I should see "Flanagan" in "_site/scholar.html" - @tags + @tags @cite Scenario: Missing references Given I have a scholar configuration with: | key | value | @@ -55,3 +55,32 @@ Feature: Citations Then the _site directory should exist And the "_site/scholar.html" file should exist And I should see "missing reference" in "_site/scholar.html" + + @tags @quote + Scenario: A Simple Block-Quote + Given I have a scholar configuration with: + | key | value | + | source | ./_bibliography | + | bibliography | my_references | + And I have a "_bibliography" directory + And I have a file "_bibliography/my_references.bib": + """ + @book{ruby, + title = {The Ruby Programming Language}, + author = {Flanagan, David and Matsumoto, Yukihiro}, + year = {2008}, + publisher = {O'Reilly Media} + } + """ + And I have a page "scholar.html": + """ + --- + --- + {% quote ruby %} + We <3 Ruby + {% endquote %} + """ + When I run jekyll + Then the _site directory should exist + And the "_site/scholar.html" file should exist + And I should see "Lorem ipsum dolor sit amet, consectetur adipisicing elit,
+
+ sed do eiusmod tempor.Lorem ipsum dolor sit amet, consectetur adipisicing.
+ + (Derrida, 1975) + +
We <3 Ruby
config['style'], - :locale => config['locale'], :format => 'html', :mode => :citation - - link_to "##{entry.key}", citation - else - "(missing reference)" - end + cite key end end diff --git a/lib/jekyll/scholar/tags/quote.rb b/lib/jekyll/scholar/tags/quote.rb new file mode 100644 index 0000000000000000000000000000000000000000..42d5935049febaf2832b3991a48cfa73908ef0e7 --- /dev/null +++ b/lib/jekyll/scholar/tags/quote.rb @@ -0,0 +1,34 @@ +module Jekyll + class Scholar + + class QuoteTag < Liquid::Block + include Scholar::Utilities + + attr_reader :key, :pages + + def initialize(tag_name, arguments, tokens) + super + + @config = Scholar.defaults.dup + @key = arguments.strip.split(/\s+/)[0] + end + + def render(context) + set_context_to context + + quote = super.strip.gsub(/\n\n/, '').gsub(/\n/, '
') + quote = content_tag :p, quote + + citation = cite(key) + + quote << content_tag(:cite, citation) + + content_tag :blockquote, quote + end + + end + + end +end + +Liquid::Template.register_tag('quote', Jekyll::Scholar::QuoteTag) \ No newline at end of file diff --git a/lib/jekyll/scholar/utilities.rb b/lib/jekyll/scholar/utilities.rb index 655e45079e3fe1e55ace0752eaaee2e88cee9921..82e41e30a626494f40ba2772174810a0a924e9b0 100644 --- a/lib/jekyll/scholar/utilities.rb +++ b/lib/jekyll/scholar/utilities.rb @@ -53,14 +53,31 @@ module Jekyll [name, 'html'].join('.') end - def details_link_for(entry, base = site.config['baseurl'] || '/') - [base, details_path, details_file_for(entry)].compact.join('/') + def details_link_for(entry, base = base_url) + [base, details_path, details_file_for(entry)].join('/') + end + + def base_url + @base_url ||= site.config['baseurl'] || nil end def details_path config['details_dir'] end + def cite(key) + entry = bibliography[key] + + if bibliography.key?(key) + citation = CiteProc.process entry.to_citeproc, :style => config['style'], + :locale => config['locale'], :format => 'html', :mode => :citation + + link_to "##{entry.key}", citation.join + else + "(missing reference)" + end + end + def content_tag(name, content_or_attributes, attributes = {}) if content_or_attributes.is_a?(Hash) content, attributes = nil, content_or_attributes