Sha256: 649411ea8c00898fa7d6a128df9e005c0333dff1659a5f0b61283c321cea867c
Contents?: true
Size: 920 Bytes
Versions: 13
Compression:
Stored size: 920 Bytes
Contents
require 'csv' # A filter for displaying full names of acronyms Nanoc::Filter.define(:scholar_acronym) do |content, params| acronyms = CSV.parse(params[:acronyms].raw_content, :headers => true) # Annotate all occurrences with their full name transformed = content.dup acronyms.each do |row| transformed.gsub! %r{(?<=[\s\.,!?])#{row['abbreviation']}(?=[\s\.,!?])} do |match| %{<abbr title='#{row['full']}'>#{row['abbreviation']}</abbr>} end end # Inject acronyms list transformed = transformed.gsub! %r{<div id="scholarmarkdown-acronyms-list"></div>} do |match| serialize_acronyms acronyms end transformed end # Serialize the list of acronyms to a table def serialize_acronyms acronyms table = "<table class=\"acronyms\">" acronyms.each do |row| table += "<tr><th>#{row['abbreviation']}</th><td>#{row['full']}</td></tr>" end table += "</table>" table end
Version data entries
13 entries across 13 versions & 1 rubygems