Class: Slamdown::Conversion::Normaliser::NodeFactory

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

Overview

Centralises construction of immutable normalised nodes so transformations only describe the fields they intend to change.

Constant Summary collapse

DEFAULTS =
{
	:kind => :element,
	:source_name => nil,
	:semantic_kind => nil,
	:category => nil,
	:value => nil,
	:attributes => [],
	:classes => [],
	:id => nil,
	:children => [],
	:properties => {},
	:semantic_values => {},
	:representation => nil,
	:synthetic => false,
	:source_path => nil
}.freeze

Instance Method Summary collapse

Instance Method Details

#build(values) ⇒ Object



26
27
28
# File 'lib/slamdown/conversion/normaliser/node_factory.rb', line 26

def build(values)
	NormalisedNode.new(DEFAULTS.merge(values))
end

#copy_leaf(node, path) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/slamdown/conversion/normaliser/node_factory.rb', line 78

def copy_leaf(node, path)
	build(
		:kind => node.kind,
		:category => node.category,
		:value => node.value,
		:properties => node.properties,
		:source_path => path
	)
end

#paragraph(children, path) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/slamdown/conversion/normaliser/node_factory.rb', line 88

def paragraph(children, path)
	build(
		:kind => :element,
		:semantic_kind => :paragraph,
		:category => :block,
		:children => children,
		:representation => :semantic,
		:source_path => path
	)
end

#paragraph_boundary(path) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'lib/slamdown/conversion/normaliser/node_factory.rb', line 99

def paragraph_boundary(path)
	build(
		:kind => :element,
		:semantic_kind => :paragraph_boundary,
		:category => :block,
		:representation => :boundary,
		:source_path => path
	)
end

#preserved(node, semantic_kind, children, path) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/slamdown/conversion/normaliser/node_factory.rb', line 59

def preserved(node, semantic_kind, children, path)
	build(
		:kind => :element,
		:source_name => node.source_name,
		:semantic_kind => semantic_kind,
		:category => node.category,
		:value => node.value,
		:attributes => node.attributes,
		:classes => node.classes,
		:id => node.id,
		:children => children,
		:properties => node.properties,
		:semantic_values => node.semantic_values,
		:representation => :html,
		:synthetic => node.synthetic,
		:source_path => path
	)
end

#semantic(node, semantic_kind, children, path, changes = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/slamdown/conversion/normaliser/node_factory.rb', line 39

def semantic(node, semantic_kind, children, path, changes = {})
	category = Content::BLOCK_SEMANTICS.include?(semantic_kind) ? :block : :span
	build({
		:kind => :element,
		:source_name => node.source_name,
		:semantic_kind => semantic_kind,
		:category => category,
		:value => node.value,
		:attributes => node.attributes,
		:classes => node.classes,
		:id => node.id,
		:children => children,
		:properties => node.properties,
		:semantic_values => node.semantic_values,
		:representation => :semantic,
		:synthetic => node.synthetic,
		:source_path => path
	}.merge(changes))
end

#text(value, path) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/slamdown/conversion/normaliser/node_factory.rb', line 30

def text(value, path)
	build(
		:kind => :text,
		:category => :span,
		:value => value,
		:source_path => path
	)
end