Module: Taggart::Array

Included in:
Array
Defined in:
lib/taggart.rb

Constant Summary collapse

DEBUG =
false

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.array_attribute_tag(tag, tag_name = nil) ⇒ Object

Defines a standard tag that can create attributes



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/taggart.rb', line 218

def self.array_attribute_tag(tag, tag_name = nil)
  tag_name ||= tag
  puts "Defining array tag '#{(tag + "',").ljust(12)} with method name: '#{tag_name}'" if DEBUG
  define_method(tag_name) do |*args|
    args = args.first if args # Only using the first of the array
    result = []
    self.each do |object|
      if object.is_a? String
        result << object.send(tag_name.to_sym, args)
      elsif object.is_a? Symbol
        result << object.to_s.send(tag_name.to_sym, args)
      elsif object.is_a? Array # I don't know why you'd want to do this, but here it is.
        result << (object.send(tag_name.to_sym, args)).send(tag_name.to_sym, args)
      end
    end
    result.join
  end
end

Instance Method Details

#ol(*args) ⇒ Object



244
245
246
# File 'lib/taggart.rb', line 244

def ol(*args)
  self.li.ol(*args)
end

#table(*args) ⇒ Object



259
260
261
262
263
264
265
266
267
# File 'lib/taggart.rb', line 259

def table(*args)
  if self.first.is_a? Array
    self.map do |table_row|
      table_row.tr if table_row.is_a? Array
    end.join.table(*args)
  else
    self.tr.table(*args)
  end
end

#tr(*args) ⇒ Object



254
255
256
# File 'lib/taggart.rb', line 254

def tr(*args)
  self.td.tr(*args)
end

#ul(*args) ⇒ Object



249
250
251
# File 'lib/taggart.rb', line 249

def ul(*args)
  self.li.ul(*args)
end