class StandaloneTypograf::Typograf

Options

Attributes

mode[R]
text[RW]

Public Class Methods

new(text, options={}) click to toggle source
# 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

Public Instance Methods

exclude(list) click to toggle source
# 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
prepare() click to toggle source

@return [String]

# File lib/standalone_typograf.rb, line 73
def prepare
  processor(*processors.keys)
end
processor(*names) click to toggle source

Call a separate processor or several processors @return [String]

# 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
processors() click to toggle source

@return [Hash]

# File lib/standalone_typograf.rb, line 68
def processors
  @processors ||= StandaloneTypograf.processors.deep_dup
end

Private Instance Methods

validate_option(param, options={}) click to toggle source

Validate initialization options that have been passed thought the params.

Available validations:

* in [Array] 
  provided param should be in array, for example:
 `validate_option(:hello, in: [:hello, :world])`
# File lib/standalone_typograf.rb, line 94
def validate_option(param, options={})
  return unless param.present?
  if options[:in].present?
    raise ArgumentError.new("Wrong argument `#{param}`, should be in `#{options[:in].join(', ')}`") unless options[:in].include?(param)
  end
  return param
end