Ejemplo n.º 1
0
        void TemplateTagSplatAttrs::render(std::string &buffer, expr::Scope &scope)const
        {
            std::unordered_map<std::string, std::vector<Ptr<Object>>> attrs;
            //Determine all attributes
            for (auto &i : static_attrs)
                attrs[i.first].push_back(make_value(i.second));

            for (auto &i : dynamic_attrs)
            {
                auto &attr = attrs[i.first];
                auto val = i.second->eval(scope);
                add_attr_value(attr, val);
            }

            for (auto &splat : splat_attrs)
            {
                auto hash = coerce<Hash>(splat->eval(scope));
                for (auto &i : *hash)
                {
                    auto &attr = attrs[i.first->to_string()];
                    auto val = i.second;
                    add_attr_value(attr, val);
                }
            }
            //Output attributes
            for (auto &i : attrs)
            {
                auto &name = html_escape(i.first);
                auto &values = i.second;

                if (values.empty()) continue; //empty / no value
                else if (values.size() == 1)
                {
                    auto val = values[0];
                    if (val == TRUE_VALUE) //true boolean attr
                    {
                        buffer += ' ';
                        buffer += name;
                    }
                    else if (val == FALSE_VALUE || val == NIL_VALUE) //false boolean attr
                    {
                        continue;
                    }
                    else buffer += attr_str(name, {val->to_string()});
                }
                else
                {
                    //array of values, e.g. "class"
                    std::vector<std::string> strings;
                    for (auto &j : values) strings.push_back(j->to_string());
                    buffer += attr_str(name, strings);
                }
            }
        }
Ejemplo n.º 2
0
        void TemplateTagAttr::render(std::string &buffer, expr::Scope &scope)const
        {
            std::vector<ObjectPtr> values;
            for (auto &expr : dynamic_values)
            {
                auto val = expr->eval(scope);
                add_attr_value(values, val);
            }

            if (static_values.empty() && values.empty()) return;

            if (static_values.empty() && values.size() == 1)
            {
                if (values[0] == TRUE_VALUE)
                {
                    buffer += ' ' + attr;
                    return;
                }
                else if (values[0] == FALSE_VALUE || values[0] == NIL_VALUE) return;
            }

            std::vector<std::string> strings = static_values;
            for (auto &v : values) strings.push_back(html_escape(v));

            buffer += attr_str(attr, strings);
        }
Ejemplo n.º 3
0
END_TEST


START_TEST(process_job_attribute_information_test)
  {
  std::string attr_str("(cput=100,vmem=100101,mem=100020)");
  std::string jobid("2.napali");

  str_to_attr_count = 0;
  process_job_attribute_information(jobid, attr_str);
  fail_unless(str_to_attr_count == 3);
  fail_unless(decode_resc_count == 3);
  }