class Hastighedstest < Sinatra::Base # Returns the tags that the user can configure # # @param template_id [Integer] The database template ID # @return an Array of tags def get_configurable_tags(template_id) #speedtest = Speedtest.new($config) #tags = speedtest.get_template_tags(template_id) tags = get_template_tags(template_id) # We do not want to configure default tags default_tags = %w(testcpe testbb pairlocal pairremote netlocal netremote) default_tags.each { |t| tags.delete(t) } tags end # Extracts all tags from a Mustache template # # @param id [Integer] the template ID from the database # @return The tags from both the configure and deconfigure templates def get_template_tags(id) config_text = Templates.where(:id => id).first.contents if config_text config = Mustache::Template.new(Templates.where(:id => id).first.contents).tags else config = [] end deconfig_text = Templates.where(:id => id).first.contents_deconfigure if deconfig_text deconfig = Mustache::Template.new(Templates.where(:id => id).first.contents_deconfigure).tags else deconfig = [] end config | deconfig end # Updates the tags in the database # # @param id [Integer] the template db ID # @param fields [Hash] the new value of the fields column def store_template_tags(id, fields) ds = Templates.where(:id => id) if ds.count == 1 ds.update(:fields => fields.to_json) end end # Converts the database tags in to HTML elements # # @param fields [JSON] The fields in JSON format # @return an HTML table def tag_to_elements(fields) tags = JSON.parse(fields) #output = "