Class: Coradoc::Input::HTML::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/coradoc/input/html/plugin.rb,
lib/coradoc/input/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.



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

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

Instance Attribute Details

#asciidoc_stringObject

AsciiDoc string functionalities



127
128
129
# File 'lib/coradoc/input/html/plugin.rb', line 127

def asciidoc_string
  @asciidoc_string
end

#coradoc_treeObject

Coradoc tree functionalities



121
122
123
# File 'lib/coradoc/input/html/plugin.rb', line 121

def coradoc_tree
  @coradoc_tree
end

#html_treeObject

HTML Tree functionalities



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

def html_tree
  @html_tree
end

Class Method Details

.new(&block) ⇒ Object

Allow building plugins with a shorthand syntax: plugin = Coradoc::Input::HTML::Plugin.new do

def name = "Test"

end



10
11
12
13
14
15
16
# File 'lib/coradoc/input/html/plugin.rb', line 10

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

Instance Method Details

#html_tree_add_hook_post(element, &block) ⇒ Object

Creates a hook to be called after converting an element to a Coradoc node.

proc |html_node, coradoc_node, state|

coradoc_node

end



95
96
97
# File 'lib/coradoc/input/html/plugin.rb', line 95

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



99
100
101
102
103
# File 'lib/coradoc/input/html/plugin.rb', line 99

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

Creates a hook to be called instead of converting an element to a Coradoc node.

proc |html_node, state|

coradoc_node

end



79
80
81
# File 'lib/coradoc/input/html/plugin.rb', line 79

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



83
84
85
86
87
# File 'lib/coradoc/input/html/plugin.rb', line 83

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



38
39
40
41
42
43
44
# File 'lib/coradoc/input/html/plugin.rb', line 38

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



32
33
34
35
36
# File 'lib/coradoc/input/html/plugin.rb', line 32

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_previewObject



64
65
66
67
68
69
# File 'lib/coradoc/input/html/plugin.rb', line 64

def html_tree_preview
  Tempfile.open(%w"coradoc .html") do |i|
    i << html_tree.to_html
    system "chromium-browser", "--no-sandbox", i.path
  end
end

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



60
61
62
# File 'lib/coradoc/input/html/plugin.rb', line 60

def html_tree_process_to_adoc(tree, state = {})
  Coradoc::Input::HTML::Converters.process(tree, state)
end

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



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

def html_tree_process_to_coradoc(tree, state = {})
  Coradoc::Input::HTML::Converters.process_coradoc(tree, state)
end

#html_tree_remove_by_css(css) ⇒ Object



46
47
48
# File 'lib/coradoc/input/html/plugin.rb', line 46

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

#html_tree_replace_with_children_by_css(css) ⇒ Object



50
51
52
53
54
# File 'lib/coradoc/input/html/plugin.rb', line 50

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, &_block) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/coradoc/input/html/plugin.rb', line 105

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

  coradoc = hook_pre.(node, state) if hook_pre
  coradoc ||= yield node, state

  if hook_post
    coradoc = hook_post.(node, coradoc, state)
  end

  coradoc
end

#nameObject

define name to name a Plugin



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

def name
  self.class.name
end