Module: TrustyCms::Taggable::Util

Defined in:
lib/trusty_cms/taggable.rb

Class Method Summary collapse

Class Method Details

.strip_leading_whitespace(text) ⇒ Object



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

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
    end
  end.compact.min
  lines.inject([]) { |ary, line| ary << line.sub(/^[ ]{#{leading}}/, '') }.join("\n")
end

.tags_in_array(array) ⇒ Object



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

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