Module: Radiant::Taggable::Util

Defined in:
lib/radiant/taggable.rb

Class Method Summary collapse

Class Method Details

.strip_leading_whitespace(text) ⇒ Object



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

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



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

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