Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/wlang/ext/string.rb
Overview
Installs wlang utility methods on Ruby String.
Direct Known Subclasses
Instance Method Summary (collapse)
-
- (Object) __wlang_column_of(index)
Computes the column number for a given offset in this string.
-
- (Object) __wlang_line_of(index)
Computes the line number for a given offset in this string.
- - (Object) __wlang_realign(offset, strip_first = false)
-
- (Object) wlang_instantiate(context = nil, dialect = "wlang/active-string", block_symbols = :braces)
(also: #wlang)
Instantiates the string as a wlang template using a context object and a dialect.
-
- (Object) wlang_template(dialect = "wlang/active-string", block_symbols = :braces)
Converts the string to a wlang template.
Instance Method Details
- (Object) __wlang_column_of(index)
Computes the column number for a given offset in this string
22 23 24 25 26 27 28 29 30 |
# File 'lib/wlang/ext/string.rb', line 22 def __wlang_column_of(index) return 1 if index == 0 newline_index = rindex("\n", index - 1) if newline_index index - newline_index else index + 1 end end |
- (Object) __wlang_line_of(index)
Computes the line number for a given offset in this string
34 35 36 |
# File 'lib/wlang/ext/string.rb', line 34 def __wlang_line_of(index) self[0...index].count("\n") + 1 end |
- (Object) __wlang_realign(offset, strip_first = false)
38 39 40 41 |
# File 'lib/wlang/ext/string.rb', line 38 def __wlang_realign(offset, strip_first = false) s = gsub(/^/, ' ' * offset) strip_first ? s.gsub(/\A\s*/, "") : s end |
- (Object) wlang_instantiate(context = nil, dialect = "wlang/active-string", block_symbols = :braces) Also known as: wlang
Instantiates the string as a wlang template using a context object and a dialect.
15 16 17 |
# File 'lib/wlang/ext/string.rb', line 15 def wlang_instantiate(context = nil, dialect = "wlang/active-string", block_symbols = :braces) WLang::instantiate(self, context, dialect, block_symbols) end |
- (Object) wlang_template(dialect = "wlang/active-string", block_symbols = :braces)
Converts the string to a wlang template
7 8 9 |
# File 'lib/wlang/ext/string.rb', line 7 def wlang_template(dialect = "wlang/active-string", block_symbols = :braces) WLang::template(self, dialect, block_symbols) end |