module ArticleJSON::Export::Common::HTML::Elements::Text
Public Instance Methods
export()
click to toggle source
Generate a Nokogiri node or simple text node, depending on the text options @return [Nokogiri::XML::NodeSet]
# File lib/article_json/export/common/html/elements/text.rb, line 10 def export return bold_and_italic_node if @element.bold && @element.italic return bold_node if @element.bold return italic_node if @element.italic content_node end
Private Instance Methods
bold_and_italic_node()
click to toggle source
@return [Nokogiri::XML::NodeSet]
# File lib/article_json/export/common/html/elements/text.rb, line 32 def bold_and_italic_node create_element(:strong) do |strong| strong.add_child(italic_node) end end
bold_node()
click to toggle source
@return [Nokogiri::XML::NodeSet]
# File lib/article_json/export/common/html/elements/text.rb, line 25 def bold_node create_element(:strong) do |strong| strong.add_child(content_node) end end
content_node()
click to toggle source
@return [Nokogiri::XML::NodeSet]
# File lib/article_json/export/common/html/elements/text.rb, line 39 def content_node return create_text_nodes(@element.content) if @element.href.nil? create_element(:a, href: @element.href) do |a| a.add_child(create_text_nodes(@element.content)) end end
create_text_nodes(text)
click to toggle source
@param [Nokogiri::XML::NodeSet] text
# File lib/article_json/export/common/html/elements/text.rb, line 47 def create_text_nodes(text) Nokogiri::HTML .fragment(text.gsub(/\n/, '<br>')) .children end
italic_node()
click to toggle source
@return [Nokogiri::XML::NodeSet]
# File lib/article_json/export/common/html/elements/text.rb, line 20 def italic_node create_element(:em) { |em| em.add_child(content_node) } end