muflax65ngodyewp.onion/lib/meta.rb

60 lines
1.1 KiB
Ruby
Raw Normal View History

# meta tags for text sections
def meta &block
annotate block do |c|
div_wrap :meta, c
end
end
2012-09-09 18:30:19 +02:00
# wrap in div tags
def div_wrap tag, text
"<div class='#{tag}' markdown='1'>#{text}</div>"
end
2013-01-17 01:11:21 +01:00
# wrap in span tags
def span_wrap tag, text
"<span class='#{tag}' markdown='1'>#{text}</span>"
end
2012-09-09 18:30:19 +02:00
# don't parse this when counting words
def skip &block
annotate block do |c|
2012-05-30 06:26:53 +02:00
c unless @item_rep.name == :wordcount
end
end
2012-09-09 18:30:19 +02:00
# replace end-of-line with " " used by markdown
def poem &block
annotate block do |c|
c.split("\n").join(" \n")
end
end
2013-01-16 23:54:59 +01:00
# interpolations; highlight them
def interpolation &block
annotate block do |c|
2013-01-17 01:11:21 +01:00
span_wrap :interpolation, c
2013-01-16 23:54:59 +01:00
end
end
def annotate content, &filter
# get erbout so far
erbout = eval('_erbout', content.binding)
erbout_length = erbout.length
# execute content block
content.call
# remove raw content
raw = erbout[erbout_length..-1]
erbout[erbout_length..-1] = ''
# filter content, if possible
filtered = block_given? ? filter.call(raw) : raw
# print filtered content
erbout << filtered unless filtered.nil?
end