Module: Cms::Extensions::String

Defined in:
lib/cms/extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#indent(n = 0) ⇒ Object


4
5
6
# File 'lib/cms/extensions/string.rb', line 4

def indent(n=0)
  (" "*n.to_i) + self 
end

#markdownObject


7
8
9
# File 'lib/cms/extensions/string.rb', line 7

def markdown
  Cms.markdown? ? Markdown.new(self).to_html : "<strong>ERROR</strong>: Markdown Support Not Installed"   
end

#pluralize_unless_one(count = nil) ⇒ String

Allows for conditional pluralization of names where object counts are not singular.

Parameters:

  • count (Integer) (defaults to: nil)

    The number of objects of this string there are.

Returns:

  • (String)

    Plural of string, unless count == 1


18
19
20
# File 'lib/cms/extensions/string.rb', line 18

def pluralize_unless_one(count=nil)
  count == 1 ? self : ActiveSupport::Inflector.pluralize(self)
end

#to_slugObject


10
11
12
# File 'lib/cms/extensions/string.rb', line 10

def to_slug
  gsub(/\W+/, ' ').strip.downcase.gsub(/\ +/, '-')
end