Class: Slamdown::Conversion::Policy::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/slamdown/conversion/policy.rb

Overview

Looks up policy for source-aware parsed nodes. Parser-synthetic nodes deliberately receive no invented element key.

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Resolver

Returns a new instance of Resolver.



59
60
61
# File 'lib/slamdown/conversion/policy.rb', line 59

def initialize(configuration)
	@configuration = configuration
end

Instance Method Details

#action_for(node) ⇒ Object



63
64
65
66
67
# File 'lib/slamdown/conversion/policy.rb', line 63

def action_for(node)
	return unless node.source_name

	first_element_decision(node.source_name, :action) || Decision.new(generic_action(node), :default_any, :element_scope => :any)
end

#action_for_source_name(source_name) ⇒ Object

Resolves policy for a semantic element generated during normalisation, such as a strong wrapper recovered from span styling.

Raises:

  • (ArgumentError)


70
71
72
73
74
75
# File 'lib/slamdown/conversion/policy.rb', line 70

def action_for_source_name(source_name)
	decision = first_element_decision(source_name, :action)
	return decision if decision

	raise ArgumentError, "no element action is registered for #{source_name.inspect}"
end

#attribute_for(node, attribute_name) ⇒ Object



77
78
79
80
81
# File 'lib/slamdown/conversion/policy.rb', line 77

def attribute_for(node, attribute_name)
	return unless node.source_name

	first_attribute_decision(node.source_name, attribute_name.to_s.downcase)
end

#class_for(node, token) ⇒ Object



83
84
85
# File 'lib/slamdown/conversion/policy.rb', line 83

def class_for(node, token)
	match_decision(@configuration.classes, node, token)
end

#id_for(node, value) ⇒ Object



87
88
89
# File 'lib/slamdown/conversion/policy.rb', line 87

def id_for(node, value)
	match_decision(@configuration.ids, node, value)
end