Sha256: c432f09f6c87d222181c35503fd0369184cea7100e2530fdee5a411a9da36e4e

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

#
# Installs _wlang_ utility methods on Ruby String. 
#
class String

  # Converts the string to a wlang template
  def wlang_template(dialect = "wlang/active-string", block_symbols = :braces)
    WLang::template(self, dialect, block_symbols)
  end
  
  #
  # Instantiates the string as a wlang template using
  # a context object and a dialect.
  #
  def wlang_instantiate(context = nil, dialect = "wlang/active-string", block_symbols = :braces)
    WLang::instantiate(self, context, dialect, block_symbols)
  end
  alias :wlang :wlang_instantiate
  
  # Computes the column number for a given offset in 
  # this string
  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
  
  # Computes the line number for a given offset in 
  # this string
  def __wlang_line_of(index)
    self[0...index].count("\n") + 1
  end
  
  def __wlang_realign(offset, strip_first = false)
    s = gsub(/^/, ' ' * offset)
    strip_first ? s.gsub(/\A\s*/, "") : s
  end
  
end
       

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wlang-0.10.2 lib/wlang/ext/string.rb
wlang-0.10.1 ./lib/wlang/ext/string.rb
wlang-0.10.0 lib/wlang/ext/string.rb