Module: TrustyCms::Taggable::Util

Defined in:
lib/trusty_cms/taggable.rb

Class Method Summary collapse

Class Method Details

.strip_leading_whitespace(text) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/trusty_cms/taggable.rb', line 122

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



118
119
120
# File 'lib/trusty_cms/taggable.rb', line 118

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