Class: ActiveSupport::SafeBuffer
Relationships & Source Files | |
Namespace Children | |
Exceptions:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
ActionView::OutputBuffer
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::String
|
|
Instance Chain:
self,
::String
|
|
Inherits: | String |
Defined in: | activesupport/lib/active_support/core_ext/string/output_safety.rb |
Constant Summary
-
UNSAFE_STRING_METHODS =
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 163%w( capitalize chomp chop delete delete_prefix delete_suffix downcase lstrip next reverse rstrip scrub slice squeeze strip succ swapcase tr tr_s unicode_normalize upcase )
-
UNSAFE_STRING_METHODS_WITH_BACKREF =
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 169%w(gsub sub)
::String
- Inherited
Class Method Summary
- .new(str = "") ⇒ SafeBuffer constructor
Instance Attribute Summary
- #html_safe? ⇒ Boolean readonly
::String
- Inherited
#acts_like_string? | Enables more predictable duck-typing on String-like classes. |
#blank? | A string is blank if it’s empty or contains whitespaces only: |
#is_utf8? | Returns |
Instance Method Summary
- #%(args)
- #*
- #+(other)
-
#<<(value)
Alias for #concat.
- #[](*args)
- #[]=(*args)
- #bytesplice(*args, value)
- #clone_empty
- #concat(value) (also: #<<)
- #encode_with(coder)
- #initialize_copy(other)
- #insert(index, value)
- #prepend(value)
- #replace(value)
- #safe_concat(value)
- #to_param
- #to_s
::String
- Inherited
#at | If you pass a single integer, returns a substring of one character at that position. |
#camelcase | Alias for String#camelize. |
#camelize | By default, |
#classify | Creates a class name from a plural table name like |
#constantize |
|
#dasherize | Replaces underscores with dashes in the string. |
#deconstantize | Removes the rightmost segment from the constant expression in the string. |
#demodulize | Removes the module part from the constant expression in the string. |
#ends_with?, | |
#exclude? | The inverse of |
#first | Returns the first character. |
#foreign_key | Creates a foreign key name from a class name. |
#from | Returns a substring from the given position to the end of the string. |
#html_safe | Marks a string as trusted safe. |
#humanize | Capitalizes the first word, turns underscores into spaces, and (by default)strips a trailing ‘_id’ if present. |
#in_time_zone | Converts String to a |
#indent | Indents the lines in the receiver: |
#indent! | Same as |
#inquiry | Wraps the current string in the |
#last | Returns the last character of the string. |
#mb_chars |
|
#parameterize | Replaces special characters in a string so that it may be used as part of a ‘pretty’ URL. |
#pluralize | Returns the plural form of the word in the string. |
#remove | Returns a new string with all occurrences of the patterns removed. |
#remove! | Alters the string by removing all occurrences of the patterns. |
#safe_constantize |
|
#singularize | The reverse of |
#squish | Returns the string, first removing all whitespace on both ends of the string, and then changing remaining consecutive whitespace groups into one space each. |
#squish! | Performs a destructive squish. |
#starts_with?, | |
#strip_heredoc | Strips indentation in heredocs. |
#tableize | Creates the name of a table like |
#titlecase | Alias for String#titleize. |
#titleize | Capitalizes all the words and replaces some characters in the string to create a nicer looking title. |
#to | Returns a substring from the beginning of the string to the given position. |
#to_date | Converts a string to a |
#to_datetime | Converts a string to a |
#to_time | Converts a string to a |
#truncate | Truncates a given |
#truncate_bytes | Truncates |
#truncate_words | Truncates a given |
#underscore | The reverse of |
#upcase_first | Converts just the first character to uppercase. |
Constructor Details
.new(str = "") ⇒ SafeBuffer
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 200
def initialize(str = "") @html_safe = true super end
Instance Attribute Details
#html_safe? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 265
def html_safe? defined?(@html_safe) && @html_safe end
Instance Method Details
#%(args)
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 254
def %(args) case args when Hash escaped_args = args.transform_values { |arg| html_escape_interpolated_argument(arg) } else escaped_args = Array(args).map { |arg| html_escape_interpolated_argument(arg) } end self.class.new(super(escaped_args)) end
#*
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 247
def *(*) new_string = super new_safe_buffer = new_string.is_a?(SafeBuffer) ? new_string : SafeBuffer.new(new_string) new_safe_buffer.instance_variable_set(:@html_safe, @html_safe) new_safe_buffer end
#+(other)
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 243
def +(other) dup.concat(other) end
#<<(value)
Alias for #concat.
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 217
alias << concat
#[](*args)
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 181
def [](*args) if html_safe? new_string = super return unless new_string new_safe_buffer = new_string.is_a?(SafeBuffer) ? new_string : SafeBuffer.new(new_string) new_safe_buffer.instance_variable_set :@html_safe, true new_safe_buffer else to_str[*args] end end
#[]=(*args)
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 235
def []=(*args) if args.length == 3 super(args[0], args[1], html_escape_interpolated_argument(args[2])) else super(args[0], html_escape_interpolated_argument(args[1])) end end
#bytesplice(*args, value)
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 219
def bytesplice(*args, value) super(*args, implicit_html_escape_interpolated_argument(value)) end
#clone_empty
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 210
def clone_empty self[0, 0] end
#concat(value) Also known as: #<<
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 214
def concat(value) super(html_escape_interpolated_argument(value)) end
#encode_with(coder)
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 277
def encode_with(coder) coder.represent_object nil, to_str end
#initialize_copy(other)
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 205
def initialize_copy(other) super @html_safe = other.html_safe? end
#insert(index, value)
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 223
def insert(index, value) super(index, html_escape_interpolated_argument(value)) end
#prepend(value)
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 227
def prepend(value) super(html_escape_interpolated_argument(value)) end
#replace(value)
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 231
def replace(value) super(html_escape_interpolated_argument(value)) end
#safe_concat(value)
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 195
def safe_concat(value) raise SafeConcatError unless html_safe? original_concat(value) end
#to_param
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 273
def to_param to_str end
#to_s
[ GitHub ]# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 269
def to_s self end