Module: UltraSettings::ViewHelper

Defined in:
lib/ultra_settings/view_helper.rb

Overview

Base class for rendering views.

Class Method Summary collapse

Class Method Details

.app_dirString

Get the app directory path.

Returns:

  • (String)

    The absolute path to the app directory.



30
31
32
# File 'lib/ultra_settings/view_helper.rb', line 30

def app_dir
  File.expand_path(File.join("..", "..", "app"), __dir__)
end

.erb_template(path) ⇒ ERB

Get an ERB template for rendering.

Parameters:

  • path (String)

    The path to the template file.

Returns:

  • (ERB)

    The compiled ERB template.



13
14
15
16
# File 'lib/ultra_settings/view_helper.rb', line 13

def erb_template(path)
  @cache.clear if development_mode?
  @cache["erb:#{path}"] ||= ERB.new(read_app_file(path))
end

.read_app_file(path) ⇒ String

Read a file from the app directory.

Parameters:

  • path (String)

    The path to the file relative to the app directory.

Returns:

  • (String)

    The contents of the file.



22
23
24
25
# File 'lib/ultra_settings/view_helper.rb', line 22

def read_app_file(path)
  @cache.clear if development_mode?
  @cache["file:#{path}"] ||= File.read(File.join(app_dir, path))
end