Class: Coradoc::Input::Html::Plugin
- Inherits:
-
Object
- Object
- Coradoc::Input::Html::Plugin
- Defined in:
- lib/coradoc/input/html/plugin.rb,
lib/coradoc/input/html/plugins/plateau.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Plateau
Instance Attribute Summary collapse
-
#asciidoc_string ⇒ Object
HTML Tree functionalities.
-
#coradoc_tree ⇒ Object
HTML Tree functionalities.
-
#html_tree ⇒ Object
HTML Tree functionalities.
Class Method Summary collapse
-
.new ⇒ Object
Allow building plugins with a shorthand syntax: plugin = Coradoc::Input::Html::Plugin.new do def name = “Test” end.
Instance Method Summary collapse
-
#html_tree_add_hook_post(element, &block) ⇒ Object
Creates a hook to be called after converting an element to a Coradoc node.
- #html_tree_add_hook_post_by_css(css, &block) ⇒ Object
-
#html_tree_add_hook_pre(element, &block) ⇒ Object
Creates a hook to be called instead of converting an element to a Coradoc node.
- #html_tree_add_hook_pre_by_css(css, &block) ⇒ Object
- #html_tree_change_properties_by_css(css, properties) ⇒ Object
- #html_tree_change_tag_name_by_css(css, new_name) ⇒ Object
- #html_tree_preview ⇒ Object
- #html_tree_process_to_adoc(tree, state = {}) ⇒ Object
- #html_tree_process_to_coradoc(tree, state = {}) ⇒ Object
- #html_tree_remove_by_css(css) ⇒ Object
- #html_tree_replace_with_children_by_css(css) ⇒ Object
- #html_tree_run_hooks(node, state, &_block) ⇒ Object
-
#initialize ⇒ Plugin
constructor
A new instance of Plugin.
-
#name ⇒ Object
define name to name a Plugin.
Constructor Details
#initialize ⇒ Plugin
Returns a new instance of Plugin.
20 21 22 23 |
# File 'lib/coradoc/input/html/plugin.rb', line 20 def initialize @html_tree_hooks_pre = {} @html_tree_hooks_post = {} end |
Instance Attribute Details
#asciidoc_string ⇒ Object
HTML Tree functionalities
32 33 34 |
# File 'lib/coradoc/input/html/plugin.rb', line 32 def asciidoc_string @asciidoc_string end |
#coradoc_tree ⇒ Object
HTML Tree functionalities
32 33 34 |
# File 'lib/coradoc/input/html/plugin.rb', line 32 def coradoc_tree @coradoc_tree end |
#html_tree ⇒ Object
HTML Tree functionalities
32 33 34 |
# File 'lib/coradoc/input/html/plugin.rb', line 32 def html_tree @html_tree end |
Class Method Details
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
97 98 99 |
# File 'lib/coradoc/input/html/plugin.rb', line 97 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
101 102 103 104 105 |
# File 'lib/coradoc/input/html/plugin.rb', line 101 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
81 82 83 |
# File 'lib/coradoc/input/html/plugin.rb', line 81 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
85 86 87 88 89 |
# File 'lib/coradoc/input/html/plugin.rb', line 85 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
40 41 42 43 44 45 46 |
# File 'lib/coradoc/input/html/plugin.rb', line 40 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
34 35 36 37 38 |
# File 'lib/coradoc/input/html/plugin.rb', line 34 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_preview ⇒ Object
66 67 68 69 70 71 |
# File 'lib/coradoc/input/html/plugin.rb', line 66 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
62 63 64 |
# File 'lib/coradoc/input/html/plugin.rb', line 62 def html_tree_process_to_adoc(tree, state = {}) Coradoc::Input::Html::Converters.process(tree, state) end |
#html_tree_process_to_coradoc(tree, state = {}) ⇒ Object
58 59 60 |
# File 'lib/coradoc/input/html/plugin.rb', line 58 def html_tree_process_to_coradoc(tree, state = {}) Coradoc::Input::Html::Converters.process_coradoc(tree, state) end |
#html_tree_remove_by_css(css) ⇒ Object
48 49 50 |
# File 'lib/coradoc/input/html/plugin.rb', line 48 def html_tree_remove_by_css(css) html_tree.css(css).each(&:remove) end |
#html_tree_replace_with_children_by_css(css) ⇒ Object
52 53 54 55 56 |
# File 'lib/coradoc/input/html/plugin.rb', line 52 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
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/coradoc/input/html/plugin.rb', line 107 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 |
#name ⇒ Object
define name to name a Plugin
26 27 28 |
# File 'lib/coradoc/input/html/plugin.rb', line 26 def name self.class.name end |