Module: TXPRails::Util
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
-
#av_template_class(name) ⇒ Object
Returns an ActionView::Template* class.
-
#rails_root ⇒ String?
Returns the root of the Rails application, if this is running in a Rails context.
-
#scope(file) ⇒ String
Returns the path of a file relative to the Haml root directory.
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`.
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_root ⇒ String?
Returns the root of the Rails application, if this is running in a Rails context. Returns ‘nil` if no such root is defined.
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.
13 14 15 |
# File 'lib/txprails/util.rb', line 13 def scope(file) File.join(File.dirname(File.dirname(File.dirname(File.(__FILE__)))), file) end |