Class: Interview::Link

Inherits:
Control show all
Includes:
HasControls
Defined in:
lib/interview/link.rb

Direct Known Subclasses

NavigationItem

Instance Attribute Summary collapse

Attributes included from HasControls

#controls

Attributes inherited from Control

#parent

Instance Method Summary collapse

Methods included from HasControls

#add_control, #add_controls, included, #siblings

Methods inherited from Control

#ancestors, build, definition, #find_attribute, #find_attribute!, inherited, #set_attributes, #set_defaults

Constructor Details

#initialize(params = {}) ⇒ Link

Returns a new instance of Link.



10
11
12
13
14
15
# File 'lib/interview/link.rb', line 10

def initialize(params={})
  @html_class = []
  @html_data = {}
  @url_params = {}
  super
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



5
6
7
# File 'lib/interview/link.rb', line 5

def action
  @action
end

#activeObject

Returns the value of attribute active.



5
6
7
# File 'lib/interview/link.rb', line 5

def active
  @active
end

#captionObject

Returns the value of attribute caption.



5
6
7
# File 'lib/interview/link.rb', line 5

def caption
  @caption
end

#controllerObject

Returns the value of attribute controller.



5
6
7
# File 'lib/interview/link.rb', line 5

def controller
  @controller
end

#hintObject

Returns the value of attribute hint.



5
6
7
# File 'lib/interview/link.rb', line 5

def hint
  @hint
end

#html_classObject (readonly)

Returns the value of attribute html_class.



8
9
10
# File 'lib/interview/link.rb', line 8

def html_class
  @html_class
end

#html_dataObject (readonly)

Returns the value of attribute html_data.



8
9
10
# File 'lib/interview/link.rb', line 8

def html_data
  @html_data
end

#http_methodObject

Returns the value of attribute http_method.



5
6
7
# File 'lib/interview/link.rb', line 5

def http_method
  @http_method
end

#imageObject

Returns the value of attribute image.



5
6
7
# File 'lib/interview/link.rb', line 5

def image
  @image
end

#nested_resourceObject

Returns the value of attribute nested_resource.



5
6
7
# File 'lib/interview/link.rb', line 5

def nested_resource
  @nested_resource
end

#objectObject

todo: Überdenken



84
85
86
# File 'lib/interview/link.rb', line 84

def object
  @object
end

#redirect_toObject

Returns the value of attribute redirect_to.



5
6
7
# File 'lib/interview/link.rb', line 5

def redirect_to
  @redirect_to
end

#styleObject

Returns the value of attribute style.



5
6
7
# File 'lib/interview/link.rb', line 5

def style
  @style
end

#trailObject

Returns the value of attribute trail.



5
6
7
# File 'lib/interview/link.rb', line 5

def trail
  @trail
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/interview/link.rb', line 5

def url
  @url
end

#url_paramsObject (readonly)

Returns the value of attribute url_params.



8
9
10
# File 'lib/interview/link.rb', line 8

def url_params
  @url_params
end

Instance Method Details

#assoc_objectObject

todo: Überdenken



88
89
90
# File 'lib/interview/link.rb', line 88

def assoc_object # todo: Überdenken
  find_attribute(:assoc_object)
end

#filter=(filter) ⇒ Object



21
22
23
# File 'lib/interview/link.rb', line 21

def filter=(filter)
  @url_params[:filter] = filter
end

#renderObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/interview/link.rb', line 25

def render
  if @redirect_to
    if @redirect_to == :current
      @url_params[:redirect_to] = h.request.original_url
    elsif @redirect_to == :parent and Object.const_defined? 'Gretel'
      @url_params[:redirect_to] = h.parent_breadcrumb.url
    else
      @url_params[:redirect_to] = @redirect_to
    end
  end
  
  if @trail and Object.const_defined? 'Gretel'
    @url_params[:trail] = h.breadcrumb_trail
  end
  
  if @url
    url = @url
    url = "#{h.root_url}#{url}" if url[0..3] != 'http'
  elsif @controller
    url_options = @url_option.dup
    opts = {controller: @controller, action: @action}.merge @url_params
    url = h.url_for opts
  else
    url_params = @url_params.dup
    url_params[:action] = @action if @action and not %w(index show create update destroy).include? @action
    object = @object || find_attribute!(:object)
    url_params.each do |key, value|
      url_params[key] = value.call(self) if value.is_a? Proc
    end
    if @nested_resource and assoc_object
      url = h.polymorphic_path [assoc_object, object], url_params
    else
      url = h.polymorphic_path object, url_params
    end
  end
  
  html_options = {}
  html_class = @html_class.dup
  if @action == 'destroy'
    html_options[:method] = :delete
    html_options[:data] = { confirm: 'Are you sure?' }
  end
  if @http_method
    html_options[:method] = @http_method.to_sym
  end
  
  if @hint
    html_class << 'action_hint'
    html_options[:'data-toggle'] = 'tooltip'
    html_options[:title] = @hint
  end
  
  if @style and respond_to? "render_#{@style}_style", true
    return send "render_#{@style}_style", url, html_class, html_options
  else
    return render_link url, html_class, html_options
  end
end

#scope=(scope) ⇒ Object



17
18
19
# File 'lib/interview/link.rb', line 17

def scope=(scope)
  @url_params[:scope] = scope
end