Module: TXPRails::Util

Extended by:
Util
Included in:
Util, Version
Defined in:
lib/txprails/util.rb

Overview

A module containing various useful functions.

Constant Summary collapse

RUBY_VERSION =

An array of ints representing the Ruby version number.

::RUBY_VERSION.split(".").map {|s| s.to_i}

Instance Method Summary collapse

Instance Method Details

#av_template_class(name) ⇒ Object

Returns an ActionView::Template* class. In pre-3.0 versions of Rails, most of these classes were of the form ‘ActionView::TemplateFoo`, while afterwards they were of the form `ActionView::Template::Foo`.

Parameters:

  • name (#to_s)

    The name of the class to get. For example, ‘:Error` will return `ActionView::TemplateError` or `ActionView::Template::Error`.



38
39
40
41
# File 'lib/txprails/util.rb', line 38

def av_template_class(name)
  return ActionView.const_get("Template#{name}") if ActionView.const_defined?("Template#{name}")
  return ActionView::Template.const_get(name.to_s)
end

#rails_rootString?

Returns the root of the Rails application, if this is running in a Rails context. Returns ‘nil` if no such root is defined.

Returns:

  • (String, nil)


24
25
26
27
28
# File 'lib/txprails/util.rb', line 24

def rails_root
  return Rails.root.to_s if defined?(Rails.root)
  return RAILS_ROOT.to_s if defined?(RAILS_ROOT)
  return nil
end

#scope(file) ⇒ String

Returns the path of a file relative to the Haml root directory.

Parameters:

  • file (String)

    The filename relative to the Haml root

Returns:

  • (String)

    The filename relative to the the working directory



13
14
15
# File 'lib/txprails/util.rb', line 13

def scope(file)
  File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), file)
end