aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_text/html_conversion.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2018-04-13 16:23:04 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2018-04-13 16:23:04 -0700
commitf1d74871e7f00e8bbde3501a759487ac8cc4c3fc (patch)
tree2f1fa680bd1e6a356256fdc59cab5a6af8d74da7 /lib/action_text/html_conversion.rb
parent3bc244abc1800c7617cbfbbe1dd2597053a638c9 (diff)
downloadrails-f1d74871e7f00e8bbde3501a759487ac8cc4c3fc.tar.gz
rails-f1d74871e7f00e8bbde3501a759487ac8cc4c3fc.tar.bz2
rails-f1d74871e7f00e8bbde3501a759487ac8cc4c3fc.zip
Rename from Active Text to Action Text
This is more like Action View than Active Model.
Diffstat (limited to 'lib/action_text/html_conversion.rb')
-rw-r--r--lib/action_text/html_conversion.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/action_text/html_conversion.rb b/lib/action_text/html_conversion.rb
new file mode 100644
index 0000000000..1c70504fb7
--- /dev/null
+++ b/lib/action_text/html_conversion.rb
@@ -0,0 +1,22 @@
+module ActionText
+ module HtmlConversion
+ extend self
+
+ def node_to_html(node)
+ node.to_html(save_with: Nokogiri::XML::Node::SaveOptions::AS_HTML)
+ end
+
+ def fragment_for_html(html)
+ document.fragment(html)
+ end
+
+ def create_element(tag_name, attributes = {})
+ document.create_element(tag_name, attributes)
+ end
+
+ private
+ def document
+ Nokogiri::HTML::Document.new.tap { |doc| doc.encoding = "UTF-8" }
+ end
+ end
+end