Properly handle metadata tags on auto-postings

This commit is contained in:
John Wiegley 2012-11-12 02:29:10 -06:00
parent 484e54c2b3
commit 63712728e1
2 changed files with 22 additions and 7 deletions

View file

@ -575,7 +575,7 @@ void instance_t::automated_xact_directive(char * line)
item = ae.get();
// This is a trailing note, and possibly a metadata info tag
item->append_note(p + 1, *context.scope, true);
ae->append_note(p + 1, *context.scope, true);
item->add_flags(ITEM_NOTE_ON_NEXT_LINE);
item->pos->end_pos = context.curr_pos;
item->pos->end_line++;

View file

@ -645,6 +645,18 @@ namespace {
}
}
static string apply_format(const string& str, scope_t& scope)
{
if (contains(str, "%(")) {
format_t str_format(str);
std::ostringstream buf;
buf << str_format(scope);
return buf.str();
} else {
return str;
}
}
void auto_xact_t::extend_xact(xact_base_t& xact, parse_context_t& context)
{
posts_list initial_posts(xact.posts.begin(), xact.posts.end());
@ -696,8 +708,9 @@ void auto_xact_t::extend_xact(xact_base_t& xact, parse_context_t& context)
if (deferred_notes) {
foreach (deferred_tag_data_t& data, *deferred_notes) {
if (data.apply_to_post == NULL)
initial_post->parse_tags(data.tag_data.c_str(), bound_scope,
data.overwrite_existing);
initial_post->append_note(
apply_format(data.tag_data, bound_scope).c_str(),
bound_scope, data.overwrite_existing);
}
}
@ -776,7 +789,7 @@ void auto_xact_t::extend_xact(xact_base_t& xact, parse_context_t& context)
account = account->parent;
account = account->find_account(fullname);
}
else if (contains(fullname, "%")) {
else if (contains(fullname, "%(")) {
format_t account_name(fullname);
std::ostringstream buf;
buf << account_name(bound_scope);
@ -804,9 +817,11 @@ void auto_xact_t::extend_xact(xact_base_t& xact, parse_context_t& context)
if (deferred_notes) {
foreach (deferred_tag_data_t& data, *deferred_notes) {
if (! data.apply_to_post || data.apply_to_post == post)
new_post->parse_tags(data.tag_data.c_str(), bound_scope,
data.overwrite_existing);
if (! data.apply_to_post || data.apply_to_post == post) {
new_post->append_note(
apply_format(data.tag_data, bound_scope).c_str(),
bound_scope, data.overwrite_existing);
}
}
}