Class: Coradoc::Input::Html::Plugin
- Inherits:
-
Object
- Object
- Coradoc::Input::Html::Plugin
- Defined in:
- lib/coradoc/html/input/plugin.rb,
lib/coradoc/html/input/plugins/plateau.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Plateau
Instance Attribute Summary collapse
-
#coremodel_tree ⇒ Object
HTML Tree functionalities.
-
#html_tree ⇒ Object
HTML Tree functionalities.
-
#output_string ⇒ Object
HTML Tree functionalities.
Class Method Summary collapse
-
.new(&block) ⇒ Object
Allow building plugins with a shorthand syntax: plugin = Coradoc::Html::Input::Plugin.new do def name = “Test” end.
Instance Method Summary collapse
-
#asciidoc_string ⇒ Object
deprecated
Deprecated.
Use output_string instead. Will be removed in v2.0.
- #asciidoc_string=(value) ⇒ Object
-
#coradoc_tree ⇒ Object
deprecated
Deprecated.
Use coremodel_tree instead. Will be removed in v2.0.
- #coradoc_tree=(value) ⇒ Object
-
#html_tree_add_hook_post(element, &block) ⇒ Object
Creates a hook to be called after converting an element to a CoreModel 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 CoreModel 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_coradoc(tree, state = {}) ⇒ Object
deprecated
Deprecated.
Use html_tree_process_to_coremodel instead. Will be removed in v2.0.
- #html_tree_process_to_coremodel(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.
-
#postprocess_asciidoc_string ⇒ Object
deprecated
Deprecated.
Use postprocess_output_string instead. Will be removed in v2.0.
-
#postprocess_coradoc_tree ⇒ Object
deprecated
Deprecated.
Use postprocess_coremodel_tree instead. Will be removed in v2.0.
Constructor Details
#initialize ⇒ Plugin
Returns a new instance of Plugin.
22 23 24 25 |
# File 'lib/coradoc/html/input/plugin.rb', line 22 def initialize @html_tree_hooks_pre = {} @html_tree_hooks_post = {} end |
Instance Attribute Details
#coremodel_tree ⇒ Object
HTML Tree functionalities
34 35 36 |
# File 'lib/coradoc/html/input/plugin.rb', line 34 def coremodel_tree @coremodel_tree end |
#html_tree ⇒ Object
HTML Tree functionalities
34 35 36 |
# File 'lib/coradoc/html/input/plugin.rb', line 34 def html_tree @html_tree end |
#output_string ⇒ Object
HTML Tree functionalities
34 35 36 |
# File 'lib/coradoc/html/input/plugin.rb', line 34 def output_string @output_string end |
Class Method Details
Instance Method Details
#asciidoc_string ⇒ Object
Use output_string instead. Will be removed in v2.0.
49 50 51 52 |
# File 'lib/coradoc/html/input/plugin.rb', line 49 def asciidoc_string warn '[DEPRECATION] `asciidoc_string` is deprecated. Use `output_string` instead.' output_string end |
#asciidoc_string=(value) ⇒ Object
54 55 56 57 |
# File 'lib/coradoc/html/input/plugin.rb', line 54 def asciidoc_string=(value) warn '[DEPRECATION] `asciidoc_string=` is deprecated. Use `output_string=` instead.' self.output_string = value end |
#coradoc_tree ⇒ Object
Use coremodel_tree instead. Will be removed in v2.0.
Legacy accessors for backward compatibility
38 39 40 41 |
# File 'lib/coradoc/html/input/plugin.rb', line 38 def coradoc_tree warn '[DEPRECATION] `coradoc_tree` is deprecated. Use `coremodel_tree` instead.' coremodel_tree end |
#coradoc_tree=(value) ⇒ Object
43 44 45 46 |
# File 'lib/coradoc/html/input/plugin.rb', line 43 def coradoc_tree=(value) warn '[DEPRECATION] `coradoc_tree=` is deprecated. Use `coremodel_tree=` instead.' self.coremodel_tree = value end |
#html_tree_add_hook_post(element, &block) ⇒ Object
Creates a hook to be called after converting an element to a CoreModel node.
proc |html_node, coremodel_node, state|
coremodel_node
end
124 125 126 |
# File 'lib/coradoc/html/input/plugin.rb', line 124 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
128 129 130 131 132 |
# File 'lib/coradoc/html/input/plugin.rb', line 128 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 CoreModel node.
proc |html_node, state|
coremodel_node
end
108 109 110 |
# File 'lib/coradoc/html/input/plugin.rb', line 108 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
112 113 114 115 116 |
# File 'lib/coradoc/html/input/plugin.rb', line 112 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
65 66 67 68 69 70 71 |
# File 'lib/coradoc/html/input/plugin.rb', line 65 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
59 60 61 62 63 |
# File 'lib/coradoc/html/input/plugin.rb', line 59 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
93 94 95 96 97 98 |
# File 'lib/coradoc/html/input/plugin.rb', line 93 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_coradoc(tree, state = {}) ⇒ Object
Use html_tree_process_to_coremodel instead. Will be removed in v2.0.
88 89 90 91 |
# File 'lib/coradoc/html/input/plugin.rb', line 88 def html_tree_process_to_coradoc(tree, state = {}) warn '[DEPRECATION] `html_tree_process_to_coradoc` is deprecated. Use `html_tree_process_to_coremodel` instead.' html_tree_process_to_coremodel(tree, state) end |
#html_tree_process_to_coremodel(tree, state = {}) ⇒ Object
83 84 85 |
# File 'lib/coradoc/html/input/plugin.rb', line 83 def html_tree_process_to_coremodel(tree, state = {}) Coradoc::Html::Input::Converters.process_coradoc(tree, state) end |
#html_tree_remove_by_css(css) ⇒ Object
73 74 75 |
# File 'lib/coradoc/html/input/plugin.rb', line 73 def html_tree_remove_by_css(css) html_tree.css(css).each(&:remove) end |
#html_tree_replace_with_children_by_css(css) ⇒ Object
77 78 79 80 81 |
# File 'lib/coradoc/html/input/plugin.rb', line 77 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
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/coradoc/html/input/plugin.rb', line 134 def html_tree_run_hooks(node, state, &_block) 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 |
#name ⇒ Object
define name to name a Plugin
28 29 30 |
# File 'lib/coradoc/html/input/plugin.rb', line 28 def name self.class.name end |
#postprocess_asciidoc_string ⇒ Object
Use postprocess_output_string instead. Will be removed in v2.0.
162 163 164 165 |
# File 'lib/coradoc/html/input/plugin.rb', line 162 def postprocess_asciidoc_string warn '[DEPRECATION] `postprocess_asciidoc_string` is deprecated. Use `postprocess_output_string` instead.' postprocess_output_string if public_methods.include?(:postprocess_output_string) end |
#postprocess_coradoc_tree ⇒ Object
Use postprocess_coremodel_tree instead. Will be removed in v2.0.
151 152 153 154 |
# File 'lib/coradoc/html/input/plugin.rb', line 151 def postprocess_coradoc_tree warn '[DEPRECATION] `postprocess_coradoc_tree` is deprecated. Use `postprocess_coremodel_tree` instead.' postprocess_coremodel_tree if public_methods.include?(:postprocess_coremodel_tree) end |