Daniel@0: /* Part of DML (Digital Music Laboratory) Daniel@0: Copyright 2014-2015 Samer Abdallah, University of London Daniel@0: Daniel@0: This program is free software; you can redistribute it and/or Daniel@0: modify it under the terms of the GNU General Public License Daniel@0: as published by the Free Software Foundation; either version 2 Daniel@0: of the License, or (at your option) any later version. Daniel@0: Daniel@0: This program is distributed in the hope that it will be useful, Daniel@0: but WITHOUT ANY WARRANTY; without even the implied warranty of Daniel@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Daniel@0: GNU General Public License for more details. Daniel@0: Daniel@0: You should have received a copy of the GNU General Public Daniel@0: License along with this library; if not, write to the Free Software Daniel@0: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Daniel@0: */ Daniel@0: Daniel@0: :- module(pengutils, Daniel@0: [ write_html/1 Daniel@0: , term_rendering//3 Daniel@0: ]). Daniel@0: Daniel@0: :- meta_predicate write_html(:). Daniel@0: Daniel@0: :- use_module(library(http/html_write)). Daniel@0: :- use_module(library(pengines)). Daniel@0: :- use_module(library(sandbox)). Daniel@0: :- use_module(library(swish/render)). Daniel@0: Daniel@0: :- register_renderer(html,"Render HTML"). Daniel@0: Daniel@0: :- meta_predicate write_html(:). Daniel@0: sandbox:safe_meta(pengutils:write_html(_),[]). Daniel@0: Daniel@0: %% write_html(+HTML) is det. Daniel@0: % Takes HTML elements as accepted by html//1 and outputs Daniel@0: % them to the pengine. Daniel@0: write_html(M:H) :- Daniel@0: debug(pengutils,'write_html(~w)',[M:H]), Daniel@0: html(M:H,Tokens,[]), Daniel@0: with_output_to(string(S),print_html(Tokens)), Daniel@0: debug(pengutils,'write_html output: ~s',[S]), Daniel@0: pengine_output(S). Daniel@0: Daniel@0: term_rendering(html(Stuff),_,Opts) --> Daniel@0: {option(module(M),Opts)}, Daniel@0: {debug(pengutils,'Rendering as HTML: ~q',[Stuff])}, Daniel@0: html(M:Stuff). Daniel@0: