Sha256: e1151aa96a7cfdfb571aef9493bcb605e09d399cd09981730f242b2b2fb672de

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

module HashBrowns
  module LinksHelpers
    def linkify(key, value, parent = false, id = false, text = false)
      return "" if value.nil? or key.nil?
      key, value, parent, id, text = key.to_s, value.to_s, parent.to_s, id.to_s, text.to_s
      text = value if text
      puts "k #{key}, v #{value}, p #{parent} i #{id} t #{text}"
      return link_to(text, HashBrowns.conf.link_parents[parent][key]+value).html_safe if parent && HashBrowns.conf.link_parents.has_key?(parent) && HashBrowns.conf.link_parents[parent].has_key?(key)
      return link_to(text, HashBrowns.conf.link_hash[key]+value).html_safe if HashBrowns.conf.link_hash.has_key?(key)
      return link_to(text, value).html_safe if HashBrowns.conf.links.include?(key)
      return link_to(text, HashBrowns.conf.link_parents[parent]["id"]+id).html_safe if id && parent && HashBrowns.conf.link_for_id.has_key?(key) && HashBrowns.conf.link_for_id[key].include?(parent)
      return value
    end

    def get_value_and_id(object, path)
      #puts "o #{object.inspect} p #{p.inspect}"
      value = object[path.shift.to_s]
      value = "false" if value.nil?
      #puts "value is '#{value}'"
      return value.to_s, object["id"] if path.empty? or value.nil?
      return get_value_and_id(value, path)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hashbrowns-0.1.5 lib/hashbrowns/helpers/links_helpers.rb
hashbrowns-0.1.4 lib/hashbrowns/helpers/links_helpers.rb
hashbrowns-0.1.3 lib/hashbrowns/helpers/links_helpers.rb