Module: Radiant::Taggable::Util

Defined in:
lib/radiant/taggable.rb

Class Method Summary collapse

Class Method Details

.strip_leading_whitespace(text) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/radiant/taggable.rb', line 74

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



70
71
72
# File 'lib/radiant/taggable.rb', line 70

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