Module: Lolita::Controllers::InternalHelpers

Included in:
RailsHelpers
Defined in:
lib/lolita/controllers/internal_helpers.rb

Instance Method Summary collapse

Instance Method Details

#current_form(temp_form = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/lolita/controllers/internal_helpers.rb', line 36

def current_form(temp_form = nil)
  if block_given?
    old_form = @current_form
    @current_form = temp_form
    content = yield
    @current_form = old_form
  end
  @current_form
end

#current_form=(form) ⇒ Object



32
33
34
# File 'lib/lolita/controllers/internal_helpers.rb', line 32

def current_form=(form)
  @current_form = form
end

#include_application_assetsObject



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/lolita/controllers/internal_helpers.rb', line 4

def include_application_assets
  result = ''
  Lolita.application.assets.each do |asset_name|
    if asset_name.match(/\.js(\.|$)/)
      result << javascript_include_tag(asset_name)
    elsif asset_name.match(/\.css(\.|$)/)
      result << stylesheet_link_tag(asset_name)
    end
  end
  raw(result)
end

#is_lolita_resource?Boolean

Returns:

  • (Boolean)


59
60
61
62
# File 'lib/lolita/controllers/internal_helpers.rb', line 59

def is_lolita_resource?
  fail ActionController::UnknownAction unless lolita_mapping
  true
end

#lolita_mapping(new_mapping = nil) ⇒ Object



28
29
30
# File 'lib/lolita/controllers/internal_helpers.rb', line 28

def lolita_mapping(new_mapping = nil)
  @lolita_mapping ||= request.env['lolita.mapping']
end

#resourceObject



16
17
18
# File 'lib/lolita/controllers/internal_helpers.rb', line 16

def resource
  instance_variable_get(:"@#{resource_name}")
end

#resource_classObject



24
25
26
# File 'lib/lolita/controllers/internal_helpers.rb', line 24

def resource_class
  lolita_mapping.to
end

#resource_nameObject



20
21
22
# File 'lib/lolita/controllers/internal_helpers.rb', line 20

def resource_name
  lolita_mapping.class_name.gsub(/::/, '_').underscore.to_sym
end

#use_mapping(new_mapping) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/lolita/controllers/internal_helpers.rb', line 46

def use_mapping(new_mapping)
  if block_given?
    begin
      @old_mapping = lolita_mapping
      @lolita_mapping = new_mapping
      yield
    ensure
      @lolita_mapping = @old_mapping
      @old_mapping = nil
    end
  end
end