Class: CiteProc::Ruby::Formats::Html

Inherits:
CiteProc::Ruby::Format show all
Defined in:
lib/citeproc/ruby/formats/html.rb

Direct Known Subclasses

CiteProcJS

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from CiteProc::Ruby::Format

#locale

Instance Method Summary collapse

Methods inherited from CiteProc::Ruby::Format

#apply, #apply_prefix, #apply_quotes, #apply_suffix, #apply_text_case, #close_inner_quote, #close_quote, #join, #keys, load, #punctuation_in_quotes?, #split_closing_quotes, squeezable, #squeezable?, squeezable?, #squeeze_prefix, #squeeze_suffix, stopword?

Constructor Details

#initialize(config = nil) ⇒ Html

Returns a new instance of Html.



29
30
31
32
33
34
35
# File 'lib/citeproc/ruby/formats/html.rb', line 29

def initialize(config = nil)
  if config.nil?
    @config = Html.defaults.dup
  else
    @config = Html.defaults.merge(config)
  end
end

Class Attribute Details

.defaultsObject (readonly)

Returns the value of attribute defaults.



24
25
26
# File 'lib/citeproc/ruby/formats/html.rb', line 24

def defaults
  @defaults
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



27
28
29
# File 'lib/citeproc/ruby/formats/html.rb', line 27

def config
  @config
end

Instance Method Details

#apply_displayObject



107
108
109
110
111
# File 'lib/citeproc/ruby/formats/html.rb', line 107

def apply_display
  output.replace(
    (config[:display], output, 'class' => "csl-#{options[:display]}" )
  )
end

#apply_font_styleObject



79
80
81
82
83
84
85
# File 'lib/citeproc/ruby/formats/html.rb', line 79

def apply_font_style
  if options[:'font-style'] == 'italic' && !css_only?
    output.replace (config[:italic], output)
  else
    css['font-style'] = options[:'font-style']
  end
end

#apply_font_variantObject



87
88
89
# File 'lib/citeproc/ruby/formats/html.rb', line 87

def apply_font_variant
  css['font-variant'] = options[:'font-variant']
end

#apply_font_weightObject



91
92
93
94
95
96
97
# File 'lib/citeproc/ruby/formats/html.rb', line 91

def apply_font_weight
  if options[:'font-weight'] == 'bold' && !css_only?
    output.replace (config[:bold], output)
  else
    css['font-weight'] = options[:'font-weight']
  end
end

#apply_text_decorationObject



99
100
101
# File 'lib/citeproc/ruby/formats/html.rb', line 99

def apply_text_decoration
  css['text-decoration'] = options[:'text-decoration']
end

#apply_vertical_alignObject



103
104
105
# File 'lib/citeproc/ruby/formats/html.rb', line 103

def apply_vertical_align
  css['vertical-align'] = options[:'vertical-align']
end

#bibliography(bibliography) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/citeproc/ruby/formats/html.rb', line 37

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?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/citeproc/ruby/formats/html.rb', line 75

def css_only?
  config[:css_only]
end

#escape_quotes?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/citeproc/ruby/formats/html.rb', line 121

def escape_quotes?
  true
end

#prefixObject



113
114
115
# File 'lib/citeproc/ruby/formats/html.rb', line 113

def prefix
  CSL.encode_xml_text(options[:prefix])
end

#strip(string) ⇒ Object



125
126
127
# File 'lib/citeproc/ruby/formats/html.rb', line 125

def strip(string)
  string.split(/((?:^<[^>]+>)|(?:<[^>]+>))$/, 2)
end

#suffixObject



117
118
119
# File 'lib/citeproc/ruby/formats/html.rb', line 117

def suffix
  CSL.encode_xml_text(options[:suffix])
end