class BookLab::SML::Rules::Base
Constants
- INDENT_PX
Public Class Methods
match?(node)
click to toggle source
# File lib/booklab/sml/rules/base.rb, line 18 def self.match?(node) false end
to_html(node, opts = {})
click to toggle source
# File lib/booklab/sml/rules/base.rb, line 22 def self.to_html(node, opts = {}) children = opts[:renderer].children_to_html(node) tag = tag_name(node) %(<#{tag}>#{children}</#{tag}>) end
to_text(node, opts = {})
click to toggle source
# File lib/booklab/sml/rules/base.rb, line 28 def self.to_text(node, opts = {}) opts[:renderer].children_to_text(node) end
Protected Class Methods
css_attrs(style)
click to toggle source
# File lib/booklab/sml/rules/base.rb, line 58 def self.css_attrs(style) style.map { |k, v| "#{k}: #{v};" }.join(" ") end
html_attrs(attrs)
click to toggle source
# File lib/booklab/sml/rules/base.rb, line 62 def self.html_attrs(attrs) attrs[:width] = nil if attrs[:width].to_i == 0 attrs[:height] = nil if attrs[:height].to_i == 0 props = attrs.map { |k, v| v.present? ? %(#{k}="#{v}") : nil }.compact.join(" ") %( #{props}) end
style_for_attrs(attrs, style = {})
click to toggle source
# File lib/booklab/sml/rules/base.rb, line 33 def self.style_for_attrs(attrs, style = {}) attrs ||= {} if attrs[:align] style["text-align"] = attrs[:align] end if attrs[:indent] if attrs[:indent].is_a?(Hash) # text-indent text_indent = attrs.dig(:indent, :firstline) style["text-indent"] = "#{4 * INDENT_PX}px" if text_indent && text_indent > 0 # padding-left indent_left = attrs.dig(:indent, :left) style["padding-left"] = "#{indent_left * INDENT_PX}px" if indent_left && indent_left > 0 end end props = css_attrs(style) return "" if props.strip.blank? %( style="#{props}") rescue => e "" end