Class: StandaloneTypograf::Typograf

Inherits:
Object
  • Object
show all
Defined in:
lib/standalone_typograf.rb

Overview

Options

  • mode [Symbol] typograf supports html and </b>utf</b> mods. The default one is UTF. It means all special symbols will be represents as UTF sequence.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, options = {}) ⇒ Typograf

Returns a new instance of Typograf.



50
51
52
53
54
55
# File 'lib/standalone_typograf.rb', line 50

def initialize(text, options={})
  options.assert_valid_keys(:mode, :exclude)
  @text = text
  @mode = validate_option(options[:mode].try(:to_sym), in: [:html, :utf]) || :utf
  exclude(options[:exclude]) if options[:exclude].present?
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



48
49
50
# File 'lib/standalone_typograf.rb', line 48

def mode
  @mode
end

#textObject

Returns the value of attribute text.



47
48
49
# File 'lib/standalone_typograf.rb', line 47

def text
  @text
end

Instance Method Details

#exclude(list) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/standalone_typograf.rb', line 77

def exclude(list)
  list = Array(list) unless list.is_a?(Array)
  list.each do |name|
    validate_option(name, in: processors.keys)
    processors.delete(name)
  end
end

#prepareString

Returns:

  • (String)


73
74
75
# File 'lib/standalone_typograf.rb', line 73

def prepare
  processor(*processors.keys)
end

#processor(*names) ⇒ String

Call a separate processor or several processors

Returns:

  • (String)


59
60
61
62
63
64
65
# File 'lib/standalone_typograf.rb', line 59

def processor(*names)
  names.each do |name|
    validate_option(name, in: processors.keys)
    processors[name].send(:compile, text, mode)
  end
  return text
end

#processorsHash

Returns:

  • (Hash)


68
69
70
# File 'lib/standalone_typograf.rb', line 68

def processors
  @processors ||= StandaloneTypograf.processors.deep_dup
end