class CiteProc::Ruby::Formats::Html
Attributes
Public Class Methods
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
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
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
Source
# File lib/citeproc/ruby/formats/html.rb, line 93 def apply_font_variant css['font-variant'] = options[:'font-variant'] end
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
Source
# File lib/citeproc/ruby/formats/html.rb, line 105 def apply_text_decoration css['text-decoration'] = options[:'text-decoration'] end
Source
# File lib/citeproc/ruby/formats/html.rb, line 109 def apply_vertical_align css['vertical-align'] = Html.vertical_align[ options[:'vertical-align'] ] end
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
Source
# File lib/citeproc/ruby/formats/html.rb, line 81 def css_only? config[:css_only] end
Source
# File lib/citeproc/ruby/formats/html.rb, line 129 def escape_quotes? true end
Source
# File lib/citeproc/ruby/formats/html.rb, line 121 def prefix CSL.encode_xml_text(options[:prefix]) end
Source
# File lib/citeproc/ruby/formats/html.rb, line 133 def strip(string) string.split(/((?:^<\p{Alpha}[^>]*>)|(?:<\/\p{Alpha}[^>]*>))$/, 2) end
Source
# File lib/citeproc/ruby/formats/html.rb, line 125 def suffix CSL.encode_xml_text(options[:suffix]) end
Protected Instance Methods
Source
# File lib/citeproc/ruby/formats/html.rb, line 157 def cleanup! @css = nil super end
Calls superclass method
CiteProc::Ruby::Format#cleanup!
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/, '& ' => '& ', '< ' => '< ') output.gsub!(/\s>/, ' >') end
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
Calls superclass method
CiteProc::Ruby::Format#finalize_content!
Private Instance Methods
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
Source
# File lib/citeproc/ruby/formats/html.rb, line 191 def closing_tag(name) "</#{name}>" end
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
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
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