From 34213c1b452d87fcf1649bf42179a218361b5818 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 28 Sep 2012 01:31:37 +0300 Subject: [PATCH] Add a shortcut for wrapping data for a collection file Collections are part of the library itself, so there's no reason to require users to write all the boilerplate to do the wrapping. --- tool/compiler.cpp | 23 +++++++++++++++++++++++ tool/compiler.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/tool/compiler.cpp b/tool/compiler.cpp index 8725bea..49dd190 100644 --- a/tool/compiler.cpp +++ b/tool/compiler.cpp @@ -45,6 +45,14 @@ bool Compiler::process_statement(const FS::Path &fn, DataFile::Statement &st) if(st.keyword=="_content") return true; + if(st.keyword=="_extension") + { + string ext = FS::extpart(FS::basename(fn)); + if(ext.empty() || ext.size()==1) + throw invalid_argument("Compiler::process_statement"); + st.keyword = ext.substr(1); + } + for(vector::iterator i = st.args.begin(); i!=st.args.end(); ++i) if(i->get_signature()==DataFile::StringType::signature) { @@ -151,6 +159,8 @@ ForEach::ForEach(Compiler &c, const FS::Path &b, const list &p): { add("exclude", &ForEach::exclude); add("pattern", &ForEach::pattern); + add("wrap", &ForEach::wrap); + add("wrap", &ForEach::wrap_keyword); add("write", &ForEach::write); } @@ -179,6 +189,19 @@ void ForEach::pattern(const string &p) patterns.push_back(p); } +void ForEach::wrap() +{ + wrap_keyword("_extension"); +} + +void ForEach::wrap_keyword(const string &kwd) +{ + DataFile::Statement st(kwd); + st.append("$filename"); + st.sub.push_back(DataFile::Statement("_content")); + write_st.push_back(st); +} + void ForEach::write(const DataFile::Statement &st) { write_st.insert(write_st.end(), st.sub.begin(), st.sub.end()); diff --git a/tool/compiler.h b/tool/compiler.h index 1e7907a..0462099 100644 --- a/tool/compiler.h +++ b/tool/compiler.h @@ -60,6 +60,8 @@ private: void exclude(const std::string &); void pattern(const std::string &); + void wrap(); + void wrap_keyword(const std::string &); void write(const Msp::DataFile::Statement &); }; -- 2.43.0