예제 #1
0
파일: shortcuts.cpp 프로젝트: hchtym/onion
onion_connection_status Onion::render_to_response(::Onion::template_f fn, const ::Onion::Dict& context, ::Onion::Response &res) {
    ONION_DEBUG("Context: %s", context.toJSON().c_str());

    onion_dict *d=onion_dict_dup( context.c_handler() );

    fn(d, res.c_handler());

    return OCS_PROCESSED;
}
예제 #2
0
const Onion::Dict getLanguagesDict(){
	const char *languages[2][2]={ 
		{"en", "English"},
		{"es", "Español"}
	};

	Onion::Dict ret;
	ret.add(languages[0][0], languages[0][1]);
	ret.add(languages[1][0], languages[1][1]);
	
	std::string json=ret.toJSON();
	std::cout<<json<<std::endl;;
	
	return ret;
}
예제 #3
0
void t03_subdict(){
	INIT_LOCAL();
	
	Onion::Dict a;
	a.add("Hello", "World");
	{
#if __cplusplus >= 201103L
		// C++11 Style add, if not using c++11, compile anyway.
		Onion::Dict b( {{"Hello","World"},{"Another","item"}} );
#else
		Onion::Dict b;
		b.add("Hello","World");
		b.add("Another","item");
#endif
		a.add("dict",b);
	}
	
	std::string json=a.toJSON();
	std::cout<<json<<std::endl;;
	
	FAIL_IF_NOT_EQUAL_STRING(json, "{\"Hello\":\"World\", \"dict\":{\"Another\":\"item\", \"Hello\":\"World\"}}");
	
	END_LOCAL();
};