Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/wlang/ext/string.rb

Overview

Installs wlang utility methods on Ruby String.

Direct Known Subclasses

WLang::IntelligentBuffer

Instance Method Summary collapse

Instance Method Details

#__wlang_column_of(index) ⇒ Object

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

#__wlang_line_of(index) ⇒ Object

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

#__wlang_realign(offset, strip_first = false) ⇒ Object



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

#wlang_instantiate(context = nil, dialect = "wlang/active-string", block_symbols = :braces) ⇒ Object 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

#wlang_template(dialect = "wlang/active-string", block_symbols = :braces) ⇒ Object

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