Module: Fabulator::Template::Taggable::Util

Defined in:
lib/fabulator/template/taggable.rb

Class Method Summary collapse

Class Method Details

.strip_leading_whitespace(text) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fabulator/template/taggable.rb', line 72

def self.strip_leading_whitespace(text)
  text = text.dup
  text.gsub!("\t", "  ")
  lines = text.split("\n")
  leading = lines.map do |line|
    unless line =~ /^\s*$/
       line.match(/^(\s*)/)[0].length
    else
      nil
    end
  end.compact.min
  lines.inject([]) {|ary, line| ary << line.sub(/^[ ]{#{leading}}/, "")}.join("\n")
end

.tags_in_array(array) ⇒ Object



68
69
70
# File 'lib/fabulator/template/taggable.rb', line 68

def self.tags_in_array(array)
  array.grep(/^tag:/).map { |name| name[4..-1] }.sort
end