Class: String
- Inherits:
-
Object
show all
- Includes:
- ReactiveTags
- Defined in:
- lib/volt/extra_core/blank.rb,
lib/volt/extra_core/string.rb,
lib/volt/reactive/string_extensions.rb
Instance Method Summary
collapse
included, #reactive_method_tag
Instance Method Details
In volt, we want a value + reactive strings to return a reactive string. So we over-ride + to check for when we are adding a reactive string to a string.
12
13
14
15
16
17
18
19
|
# File 'lib/volt/reactive/string_extensions.rb', line 12
def +(val)
result = __old_plus(val.cur)
if val.reactive? && !result.reactive?
result = ReactiveValue.new(result)
end
return result
end
|
22
23
24
25
26
27
28
29
|
# File 'lib/volt/reactive/string_extensions.rb', line 22
def <<(val)
if val.reactive?
raise "Cannot append a reactive string to non-reactive string. Use + instead"
end
result = __old_concat(val)
return result
end
|
#__old_concat ⇒ Object
6
|
# File 'lib/volt/reactive/string_extensions.rb', line 6
alias :__old_concat :<<
|
#__old_plus ⇒ Object
4
|
# File 'lib/volt/reactive/string_extensions.rb', line 4
alias :__old_plus :+
|
A string is blank if it’s empty or contains whitespaces only:
''.blank? ' '.blank? ' '.blank? ' something here '.blank?
73
74
75
76
77
|
# File 'lib/volt/extra_core/blank.rb', line 73
def blank?
self.strip == ''
end
|
TODO: replace with better implementations NOTE: strings are currently immutable in Opal, so no ! methods
4
5
6
|
# File 'lib/volt/extra_core/string.rb', line 4
def camelize
self.split("_").map {|s| s.capitalize }.join("")
end
|
30
31
32
33
|
# File 'lib/volt/extra_core/string.rb', line 30
def plural?
self[-1] == 's'
end
|
#pluralize ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/volt/extra_core/string.rb', line 12
def pluralize
if self[-1] != 's'
return self + 's'
else
return self
end
end
|
35
36
37
38
|
# File 'lib/volt/extra_core/string.rb', line 35
def singular?
self[-1] != 's'
end
|
#singularize ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/volt/extra_core/string.rb', line 21
def singularize
if self[-1] == 's'
return self[0..-2]
else
return self
end
end
|
#underscore ⇒ Object
8
9
10
|
# File 'lib/volt/extra_core/string.rb', line 8
def underscore
self.scan(/[A-Z][a-z]*/).join("_").downcase
end
|