class Interview::Link
Attributes
action[RW]
active[RW]
assoc_object[RW]
caption[RW]
hint[RW]
http_method[RW]
image[RW]
nested_resource[RW]
new_site[RW]
object[RW]
options[RW]
style[RW]
url[RW]
url_params[R]
Public Class Methods
new(params={})
click to toggle source
Calls superclass method
Interview::Control::new
# File lib/interview/controls/link.rb, line 11 def initialize(params={}) @options = {} super end
Public Instance Methods
build(b) { || ... }
click to toggle source
# File lib/interview/controls/link.rb, line 16 def build(b) html_options = @html_options.dup html_class = @html_class.dup url = get_url if @action == 'destroy' html_options[:method] = :delete html_options[:data] = {} unless html_options[:data] html_options[:data][:confim] = 'Are you sure?' # todo end if @http_method html_options[:method] = @http_method.to_sym end if @hint html_options[:title] = @hint end if @style == 'button' html_class += %w(btn btn-default) elsif @style == 'primary_button' html_class += %w(btn btn-primary) end if @new_site html_options[:target] = 'blank' end add_list_item(b) do b << h.link_to(url, options_to_html(html_options, html_class)) do create_nested_builder(b) b.glyphicon image: @image if @image b.space if @image and @caption b.text text: @caption if @caption yield if block_given? render_nested_builder(b) end end end
Protected Instance Methods
add_list_item(b) { || ... }
click to toggle source
# File lib/interview/controls/link.rb, line 78 def add_list_item(b) # todo: wird das gebraucht? if @style == 'list' li_class = @active ? 'active' : '' b.section style: 'li', html_class: li_class do yield end else yield end end
get_url()
click to toggle source
# File lib/interview/controls/link.rb, line 60 def get_url options = @options.dup if @url url = @url url = "/#{url}" if url[0..3] != 'http' and url[0] != '/' and url[0] != '#' else options[:action] = @action if @action and not %w(index show create update destroy).include? @action object = @object || find_attribute!(:object) if @nested_resource or @assoc_object assoc_object = @assoc_object || find_attribute!(:assoc_object) url = h.polymorphic_path [assoc_object, object], options else url = h.polymorphic_path object, options end end return url end