class TumblrThemer::HtmlSnippet

Attributes

str[R]

Public Class Methods

new(str) click to toggle source
# File lib/tumblr-themer/html_snippet.rb, line 4
def initialize(str)
  @str = str.dup
end

Public Instance Methods

block(_type, tf=true) { |str| ... } click to toggle source
# File lib/tumblr-themer/html_snippet.rb, line 12
def block _type, tf=true
  regex = Regexp.new("{block:#{_type}}(.*?){/block:#{_type}}",Regexp::MULTILINE)

  if tf
    if block_given?
      str.gsub!(regex) {yield($1)}
    else
      str.gsub!(regex, '\1')
    end
  else
    str.gsub!(regex, '')
  end
end
tag(key, val) click to toggle source
# File lib/tumblr-themer/html_snippet.rb, line 8
def tag key, val
  str.gsub! "{#{key}}", val.to_s
end