Sha256: c70c6f2f7679d32a7ddf3fe71f2d260dbe9bc5b8736c06b5a38eeb290f78a462
Contents?: true
Size: 1023 Bytes
Versions: 2
Compression:
Stored size: 1023 Bytes
Contents
require 'active_support/core_ext/string/inflections' class String def parameterize self.downcase.strip.gsub(/\W+/, '-') end def dasherize `#{self}.replace(/[-_\s]+/g, '-') .replace(/([A-Z\d]+)([A-Z][a-z])/g, '$1-$2') .replace(/([a-z\d])([A-Z])/g, '$1-$2') .toLowerCase()` end def demodulize %x{ var idx = #{self}.lastIndexOf('::'); if (idx > -1) { return #{self}.substr(idx + 2); } return #{self}; } end def underscore `#{self}.replace(/[-\s]+/g, '_') .replace(/([A-Z\d]+)([A-Z][a-z])/g, '$1_$2') .replace(/([a-z\d])([A-Z])/g, '$1_$2') .replace(/-/g, '_') .toLowerCase()` end def camelize(first_letter = :upper) `#{underscore}.replace(/(^|_)([^_]+)/g, function(match, pre, word, index) { var capitalize = #{first_letter} === #{:upper} || index > 0; return capitalize ? word.substr(0,1).toUpperCase()+word.substr(1) : word; })` end alias_method :camelcase, :camelize end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
opal-activesupport-0.3.0 | opal/active_support/core_ext/string.rb |
opal-activesupport-0.2.0 | opal/active_support/core_ext/string.rb |