Class: Coradoc::Html::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/coradoc/html/plugin.rb,
lib/coradoc/html/plugins/plateau.rb

Direct Known Subclasses

Plateau

Defined Under Namespace

Classes: Plateau

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlugin

Returns a new instance of Plugin.



14
15
16
17
# File 'lib/coradoc/html/plugin.rb', line 14

def initialize
  @html_tree_hooks_pre = {}
  @html_tree_hooks_post = {}
end

Instance Attribute Details

#coremodel_treeObject

Returns the value of attribute coremodel_tree.



27
28
29
# File 'lib/coradoc/html/plugin.rb', line 27

def coremodel_tree
  @coremodel_tree
end

#html_treeObject

Returns the value of attribute html_tree.



27
28
29
# File 'lib/coradoc/html/plugin.rb', line 27

def html_tree
  @html_tree
end

#output_stringObject

Returns the value of attribute output_string.



27
28
29
# File 'lib/coradoc/html/plugin.rb', line 27

def output_string
  @output_string
end

Class Method Details

.newObject



6
7
8
9
10
11
12
# File 'lib/coradoc/html/plugin.rb', line 6

def self.new(&)
  if self == Plugin
    Class.new(Plugin, &)
  else
    super
  end
end

Instance Method Details

#html_tree_add_hook_post(element, &block) ⇒ Object



67
68
69
# File 'lib/coradoc/html/plugin.rb', line 67

def html_tree_add_hook_post(element, &block)
  @html_tree_hooks_post[element] = block
end

#html_tree_add_hook_post_by_css(css, &block) ⇒ Object



71
72
73
74
75
# File 'lib/coradoc/html/plugin.rb', line 71

def html_tree_add_hook_post_by_css(css, &block)
  html_tree.css(css).each do |e|
    html_tree_add_hook_post(e, &block)
  end
end

#html_tree_add_hook_pre(element, &block) ⇒ Object



57
58
59
# File 'lib/coradoc/html/plugin.rb', line 57

def html_tree_add_hook_pre(element, &block)
  @html_tree_hooks_pre[element] = block
end

#html_tree_add_hook_pre_by_css(css, &block) ⇒ Object



61
62
63
64
65
# File 'lib/coradoc/html/plugin.rb', line 61

def html_tree_add_hook_pre_by_css(css, &block)
  html_tree.css(css).each do |e|
    html_tree_add_hook_pre(e, &block)
  end
end

#html_tree_change_properties_by_css(css, properties) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/coradoc/html/plugin.rb', line 35

def html_tree_change_properties_by_css(css, properties)
  html_tree.css(css).each do |e|
    properties.each do |k, v|
      e[k.to_s] = v
    end
  end
end

#html_tree_change_tag_name_by_css(css, new_name) ⇒ Object



29
30
31
32
33
# File 'lib/coradoc/html/plugin.rb', line 29

def html_tree_change_tag_name_by_css(css, new_name)
  html_tree.css(css).each do |e|
    e.name = new_name
  end
end

#html_tree_process_to_coremodel(tree, state = {}) ⇒ Object



53
54
55
# File 'lib/coradoc/html/plugin.rb', line 53

def html_tree_process_to_coremodel(tree, state = {})
  Coradoc::Html::Converters.process_coradoc(tree, state)
end

#html_tree_remove_by_css(css) ⇒ Object



43
44
45
# File 'lib/coradoc/html/plugin.rb', line 43

def html_tree_remove_by_css(css)
  html_tree.css(css).each(&:remove)
end

#html_tree_replace_with_children_by_css(css) ⇒ Object



47
48
49
50
51
# File 'lib/coradoc/html/plugin.rb', line 47

def html_tree_replace_with_children_by_css(css)
  html_tree.css(css).each do |e|
    e.replace(e.children)
  end
end

#html_tree_run_hooks(node, state) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/coradoc/html/plugin.rb', line 77

def html_tree_run_hooks(node, state, &)
  hook_pre = @html_tree_hooks_pre[node]
  hook_post = @html_tree_hooks_post[node]

  coremodel = hook_pre.call(node, state) if hook_pre
  coremodel ||= yield node, state

  coremodel = hook_post.call(node, coremodel, state) if hook_post

  coremodel
end

#nameObject



19
20
21
# File 'lib/coradoc/html/plugin.rb', line 19

def name
  self.class.name
end

#postprocess_coremodel_treeObject



24
# File 'lib/coradoc/html/plugin.rb', line 24

def postprocess_coremodel_tree; end

#postprocess_output_stringObject



25
# File 'lib/coradoc/html/plugin.rb', line 25

def postprocess_output_string; end

#preprocess_html_treeObject



23
# File 'lib/coradoc/html/plugin.rb', line 23

def preprocess_html_tree; end