Class: WelltreatStoreFramework::HamlRenderer::Context

Inherits:
Object
  • Object
show all
Includes:
Rack::Recaptcha::Helpers, LoremHelper, Partial, Paths, TagsHelper
Defined in:
lib/welltreat_store_framework/haml_renderer/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Paths

#asset_path, #image_path, #javascript_path, #sprockets_enabled?, #stylesheet_path

Methods included from Partial

#partial

Methods included from TagsHelper

#content_tag, #image_tag, #javascript_include_tag, #link_to, #strip_tags, #stylesheet_link_tag, #truncate

Methods included from LoremHelper

#lorem

Constructor Details

#initialize(app, request, response, options) ⇒ Context

Returns a new instance of Context.



16
17
18
19
20
21
22
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 16

def initialize(app, request, response, options)
  @app      = app
  @request  = request
  @response = response
  @options  = options || { }
  @locals   = { }
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



14
15
16
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 14

def options
  @options
end

#requestObject

Returns the value of attribute request.



14
15
16
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 14

def request
  @request
end

#responseObject

Returns the value of attribute response.



14
15
16
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 14

def response
  @response
end

Instance Method Details

#alertObject



52
53
54
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 52

def alert
  get_flash :alert
end

#appObject



24
25
26
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 24

def app;
  @app
end

#flashObject



76
77
78
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 76

def flash
  options[:session][:flash] ||= { }
end

#flash_exist?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 60

def flash_exist?
  notice || alert || success
end

#get_flash(k) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 64

def get_flash(k)
  @flash_values    ||= { }
  @flash_values[k] ||= flash[k]
  flash[k] = nil if @flash_values[k].present?

  @flash_values[k]
end

#get_local(k) ⇒ Object



32
33
34
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 32

def get_local(k)
  @locals[k]
end

#local_exists?(k) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 36

def local_exists?(k)
  @locals.include?(k)
end

#local_present?(k) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 40

def local_present?(k)
  local_exists?(k) && get_local(k).present?
end

#noticeObject



48
49
50
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 48

def notice
  get_flash :notice
end

#sessionObject



44
45
46
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 44

def session
  options[:session]
end

#set_flash(k, v) ⇒ Object



72
73
74
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 72

def set_flash(k, v)
  flash[k] = v
end

#set_local(k, v) ⇒ Object



28
29
30
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 28

def set_local(k, v)
  @locals[k] = v
end

#successObject



56
57
58
# File 'lib/welltreat_store_framework/haml_renderer/context.rb', line 56

def success
  get_flash :success
end