Class: InplaceEditingHelper::Tag

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::CaptureHelper
Defined in:
app/helpers/inplace_editing_helper.rb

Defined Under Namespace

Classes: CSS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attributes = {}) ⇒ Tag

Returns a new instance of Tag.



124
125
126
127
128
# File 'app/helpers/inplace_editing_helper.rb', line 124

def initialize(name, attributes = {})
  @name = name
  @attributes = attributes.with_indifferent_access
  @attributes[:class] = Tag::CSS.new(attributes[:class])
end

Instance Attribute Details

#cssObject (readonly)

Returns the value of attribute css.



122
123
124
# File 'app/helpers/inplace_editing_helper.rb', line 122

def css
  @css
end

#idObject

Returns the value of attribute id.



121
122
123
# File 'app/helpers/inplace_editing_helper.rb', line 121

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



122
123
124
# File 'app/helpers/inplace_editing_helper.rb', line 122

def name
  @name
end

Instance Method Details

#[](k) ⇒ Object



134
135
136
# File 'app/helpers/inplace_editing_helper.rb', line 134

def [](k)
  @attributes[k]
end

#[]=(k, v) ⇒ Object



130
131
132
# File 'app/helpers/inplace_editing_helper.rb', line 130

def []=(k,v)
  @attributes[k] = v
end

#render(content) ⇒ Object



138
139
140
# File 'app/helpers/inplace_editing_helper.rb', line 138

def render(content)
  "<#{name}#{render_attributes}>#{content ? content.strip : nil}</#{name}>".html_safe
end

#render_attributesObject



142
143
144
145
146
147
148
149
150
151
152
153
# File 'app/helpers/inplace_editing_helper.rb', line 142

def render_attributes
  attrs = @attributes.dup
  if self[:class].empty?
    attrs.delete :class
  else
    attrs[:class] = self[:class].to_s
  end

  attrs.keys.map do |k|
    "#{k}='#{ERB::Util.html_escape(attrs[k])}'".html_safe
  end.join(' ').prepend(' ')
end