class CiteProc::Ruby::Formats::Html

Attributes

defaults[R]
vertical_align[R]
config[R]

Public Class Methods

new(config = nil) click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 33
def initialize(config = nil)
  if config.nil?
    @config = Html.defaults.dup
  else
    @config = Html.defaults.merge(config)
  end

  @css = nil
end

Public Instance Methods

apply_display() click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 115
def apply_display
  output.replace(
    content_tag(config[:display], output, 'class' => "csl-#{options[:display]}" )
  )
end
apply_font_style() click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 85
def apply_font_style
  if options[:'font-style'] == 'italic' && !css_only?
    output.replace content_tag(config[:italic], output)
  else
    css['font-style'] = options[:'font-style']
  end
end
apply_font_variant() click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 93
def apply_font_variant
  css['font-variant'] = options[:'font-variant']
end
apply_font_weight() click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 97
def apply_font_weight
  if options[:'font-weight'] == 'bold' && !css_only?
    output.replace content_tag(config[:bold], output)
  else
    css['font-weight'] = options[:'font-weight']
  end
end
apply_text_decoration() click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 105
def apply_text_decoration
  css['text-decoration'] = options[:'text-decoration']
end
apply_vertical_align() click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 109
def apply_vertical_align
  css['vertical-align'] = Html.vertical_align[
    options[:'vertical-align']
  ]
end
bibliography(bibliography) click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 43
def bibliography(bibliography)
  ol, li, indent, unit =
    config.values_at(:bib_container, :bib_entry, :bib_indent, :bib_unit)

  container_options = {}
  container_options['class'] = config[:bib_container_class]

  entry_options = {}
  entry_options['class'] = config[:bib_entry_class]

  entry_options['style'] = {}
  container_options['style'] = {}

  if bibliography.line_spacing != 1.0
    container_options['style']['line-height'] = bibliography.line_spacing
  end

  if bibliography.hanging_indent?
    hanging_indent = "#{config[:bib_hanging_indent]}#{bib_unit}"

    container_options['style']['padding-left'] = hanging_indent
    entry_options['style']['text-indent'] = "-#{hanging_indent}"
  end

  if bibliography.entry_spacing != 1.0
    entry_options['style']['margin-bottom'] = "#{bibliography.entry_spacing}#{unit}"
  end

  bibliography.header = opening_tag(ol, container_options)
  bibliography.footer = closing_tag(ol)

  bibliography.prefix = [indent, opening_tag(li, entry_options)].join('')
  bibliography.suffix = closing_tag(li)

  bibliography.connector = indent ? "\n" : ''
  bibliography
end
css_only?() click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 81
def css_only?
  config[:css_only]
end
escape_quotes?() click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 129
def escape_quotes?
  true
end
prefix() click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 121
def prefix
  CSL.encode_xml_text(options[:prefix])
end
strip(string) click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 133
def strip(string)
  string.split(/((?:^<[^>]+>)|(?:<[^>]+>))$/, 2)
end
suffix() click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 125
def suffix
  CSL.encode_xml_text(options[:suffix])
end

Protected Instance Methods

cleanup!() click to toggle source
Calls superclass method CiteProc::Ruby::Format#cleanup!
# File lib/citeproc/ruby/formats/html.rb, line 157
def cleanup!
  @css = nil
  super
end
css() click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 139
def css
  @css ||= {}
end
finalize!() click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 148
def finalize!
  # TODO find a better solution for this (strip tags?)
  # For now make sure not to double encode entities
  # by matching spaces before or after.

  output.gsub!(/[&<]\s/, '& ' => '&amp; ', '< ' => '&lt; ')
  output.gsub!(/\s>/, ' &gt;')
end
finalize_content!() click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 143
def finalize_content!
  super
  output.replace content_tag(config[:container], output, 'style' => css) if @css
end

Private Instance Methods

attribute_assignments(options) click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 173
def attribute_assignments(options)
  return unless options

  options = options.select { |_, v| !v.nil? }

  return unless !options.empty?

  ' ' << options.map { |k, v| [k, v.inspect].join('=') }.join(' ')
end
closing_tag(name) click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 191
def closing_tag(name)
  "</#{name}>"
end
content_tag(name, content, options = nil) click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 164
def content_tag(name, content, options = nil)
  opening_tag(name, options) << content << closing_tag(name)
end
opening_tag(name, options = nil) click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 183
def opening_tag(name, options = nil)
  if options && options.key?('style')
    options['style'] = style_for(options['style'])
  end

  "<#{name}#{attribute_assignments(options)}>"
end
style_for(options) click to toggle source
# File lib/citeproc/ruby/formats/html.rb, line 168
def style_for(options)
  return unless options && !options.empty?
  options.map { |*kv| kv.join(': ') }.join('; ')
end