Module: Utils

Defined in:
lib/trellis/utils.rb

Overview

class Radius::TagBinding #:nodoc:

end

Class Method Summary collapse

Class Method Details

.evaluate_tag_attribute(attribute_name, tag) ⇒ Object

TODO open the tag ==> TagContext?? class



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/trellis/utils.rb', line 216

def self.evaluate_tag_attribute(attribute_name, tag)
  result = nil
  source = tag.attr[attribute_name]
  if source
    source = expand_properties_in_tag(source, tag)  
    begin
      local = tag.locals.instance_eval(source)
    rescue
      # log that they try to get a value that doesn't exist/can't be reached
    end
    begin
      global = tag.globals.instance_eval(source)
    rescue
      # same as above
    end

    if local
      result = local
    elsif global
      result = global
    end
  end
  result
end

.expand_properties_in_tag(text, tag) ⇒ Object

TODO open the tag ==> TagContext?? class



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/trellis/utils.rb', line 199

def self.expand_properties_in_tag(text, tag)
  # resolve the ${} variables
  result = text #TODO not tested!
  result = text.gsub(/\$\{.*?\}/) do |match|
    name = match.split(/\$\{|\}/)[1] 
    unless name.include?('.')
      tag.locals.send(name.to_sym) || tag.globals.send(name.to_sym)   
    else
      target_name, method = name.split('.')
      target = tag.locals.send(target_name.to_sym) || tag.globals.send(target_name.to_sym)
      target.send(method.to_sym) if target
    end        
  end if text
  result
end