Class: FlashGordon::ElementDecorator

Inherits:
Object
  • Object
show all
Defined in:
lib/flash_gordon/flash.rb

Class Method Summary collapse

Class Method Details

.decorate_message(message, glue, index) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/flash_gordon/flash.rb', line 62

def self.decorate_message(message, glue, index)
  # Splits the elements into sticky elements and sticky classes
  raw = glue.split(".")
  # Unsticky the element if it has an id tag stuck to it
  element = raw.map{|x| x["#"] ? x[0..x.index("#")-1] : x}[0]
  # Next you isolate the sticky id and classes into its own array
  ids = raw.map{|x| x[x.index("#")+1..-1].gsub("%",index.to_s) if x["#"]}.compact
  classes = raw[1..-1].map{|x| x["#"] ? x[0..x.index("#")-1] : x}
  # Lastly decorate the message with the intended tags with classes and ids
  "<#{element}#{" class='"+classes.join(" ")+"'" unless classes.empty? }#{" id='"+ids.join(" ")+"'" unless ids.empty? }>#{message}</#{element}>"
end