class PseudoHiki::HtmlPlugin
Constants
- NUMBER_RE
- PLUGIN_PAT
Public Class Methods
add_chemical_formula(chemical_formula="CO2", en_word="carbon dioxide")
click to toggle source
# File lib/pseudohiki/htmlplugin.rb, line 75 def HtmlPlugin.add_chemical_formula(chemical_formula="CO2", en_word="carbon dioxide") eval(<<-End) def #{chemical_formula.downcase} #(display=":cf",second_display=nil) display, second_display = @data.split(",\s") display = ":cf" unless display return [#{chemical_formula.downcase}(display), "(", #{chemical_formula.downcase}(second_display), ")"].join("") if second_display case display when ":cf" "#{chemical_formula}".gsub(NUMBER_RE, "<sub>\\\\1</sub>") when ":en" "#{en_word}" end end End end
new(tag_type, parsed_data)
click to toggle source
# File lib/pseudohiki/htmlplugin.rb, line 45 def initialize(tag_type, parsed_data) @tag_type = tag_type @plugin_name = nil @with_paren = nil @data = parse(parsed_data.to_s) end
Public Instance Methods
anchor()
click to toggle source
def inline
lines = HtmlElement.decode(@data).split(/\r*\n/o) lines.shift if lines.first == "" HikiBlockParser.new.parse_lines(lines).join
end
# File lib/pseudohiki/htmlplugin.rb, line 67 def anchor name, anchor_mark = @data.split(/,\s*/o, 2) anchor_mark = "_" if (anchor_mark.nil? or anchor_mark.empty?) HtmlElement.create("a", anchor_mark, "name" => name, "href" => "#" + name) end
apply()
click to toggle source
# File lib/pseudohiki/htmlplugin.rb, line 52 def apply self.send @plugin_name end
c_degree()
click to toggle source
# File lib/pseudohiki/htmlplugin.rb, line 120 def c_degree "°C" end
Also aliased as: oc
cb()
click to toggle source
# File lib/pseudohiki/htmlplugin.rb, line 111 def cb # I'm wondering if we'd be better to use ³ , but... "#{@data}<sup>3</sup>" end
chemical_formula()
click to toggle source
# File lib/pseudohiki/htmlplugin.rb, line 124 def chemical_formula @data.gsub(NUMBER_RE, "<sub>\\1</sub>") end
html()
click to toggle source
# File lib/pseudohiki/htmlplugin.rb, line 56 def html # "<div class='raw-html'>"+HtmlElement.decode(@data)+"</div>" HtmlElement.decode(@data).to_s end
iso()
click to toggle source
# File lib/pseudohiki/htmlplugin.rb, line 128 def iso @data.scan(/\A(\d+)([^\d].*)/o) do |data| weight, molecule = data if self.respond_to? molecule return "<sup>#{weight}</sup>" + HtmlPlugin.new("", molecule).apply else return "<sup>#{weight}</sup>" + molecule end end end
method_missing()
click to toggle source
# File lib/pseudohiki/htmlplugin.rb, line 142 def method_missing HtmlElement.create(@tag_type, @data, "class" => "plugin") end
parse(data)
click to toggle source
# File lib/pseudohiki/htmlplugin.rb, line 32 def parse(data) result = "".freeze if PLUGIN_PAT =~ data @plugin_name = $1 @with_paren = true if $2.chomp == "(" result = data.chomp.sub(PLUGIN_PAT, "") result[-1, 1] = "" if @with_paren else @plugin_name = data.chomp end result end
per()
click to toggle source
# File lib/pseudohiki/htmlplugin.rb, line 116 def per "#{@data}<sup>-1</sup>" end
sq()
click to toggle source
# File lib/pseudohiki/htmlplugin.rb, line 106 def sq # I'm wondering if we'd be better to use ² , but when we search by "km2" for example, we may have problem... "#{@data}<sup>2</sup>" end